Skip to content

Adds resource target commands - #460

Merged
mbleigh merged 9 commits into
mb-targetfrom
mb-target-cmds
Sep 28, 2017
Merged

mbleigh merged 9 commits into
mb-targetfrom
mb-target-cmds

Conversation

@mbleigh

@mbleigh mbleigh commented Sep 18, 2017 •

Copy link
Copy Markdown
Contributor

Adds a set of commands for managing "resource targets", which will be used to coordinate e.g. rules deploys across multiple storage buckets.

This is the first part of the necessary changes (thus why it's being merged into a feature branch instead of master) -- up next will be changes to config file parsing and deployment to actually support the necessary rules deploys.

Internal design link: firebase-cli-multiresource

@coveralls

coveralls commented Sep 18, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.5%) to 55.806% when pulling 31a887f on mb-target-cmds into ef6cb05 on mb-target.

@mbleigh

mbleigh commented Sep 19, 2017

Copy link
Copy Markdown
Contributor Author

@laurenzlong this is ready for review, PTAL when you have a chance. Also includes tests for once 😄

@coveralls

coveralls commented Sep 19, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+1.2%) to 58.461% when pulling 90e213a on mb-target-cmds into ef6cb05 on mb-target.

@coveralls

coveralls commented Sep 27, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+1.2%) to 58.461% when pulling 26b8f57 on mb-target-cmds into a6e5865 on mb-target.

@laurenzlong laurenzlong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the word "target" is getting a bit overloaded. In partial deployments, "functions" or "hosting" or a particular function name is also called a "target" in command descriptions, error messages, and docs. They're related concepts to "target" in this PR but they're slightly different. Maybe those should be renamed to "components" instead?

Comment thread lib/rc.js
var utils = require('./utils');

var TARGET_TYPES = {
storage: {resource: 'bucket', exclusive: true}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write a comment to explain what "exclusive" means?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread lib/rc.js Outdated
if (!TARGET_TYPES[type]) {
throw new FirebaseError(
'Unrecognized target type ' + chalk.bold(type) +
'. Must be ' + _.keys(TARGET_TYPES).join(', '),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe revise message to "Must be one of ....", or "Valid targets are... ". It's a bit confusing currently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread lib/rc.js Outdated
return this.get(['targets', project, type, name], []);
},

applyTarget: function(project, type, name, resources) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider renaming "name" to "targetName" or "target", otherwise it's unclear what name it's referring to.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread lib/rc.js Outdated
* not persist the result.
*/
unsetTargetResource: function(project, type, name, resource) {
var tp = ['targets', project, type, name];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you name it something more descriptive than "tp"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread test/lib/rc.spec.js
expect(subject.hasProjects).to.be.true;
});
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i'm understanding these tests correctly, they actually do disk writes into the fixtures folder. It would be better to mock out RC.save() and RC.load() to use memory instead, or at the minimum an afterEach function that cleans things up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it doesn't -- the logic of save() is that it only persists to disk if a path is set in the constructor, which these tests don't do. save() just returns false otherwise.

@laurenzlong laurenzlong assigned mbleigh and unassigned laurenzlong Sep 28, 2017

@mbleigh mbleigh left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "target" name isn't perfect, but was carefully considered. "Component" isn't correct because a single target can apply to multiple resources.

I agree that this is a bit confusing and will do my best to make sure the docs are clear. We can adapt to user feedback once this goes live, as well.

Comment thread lib/rc.js
var utils = require('./utils');

var TARGET_TYPES = {
storage: {resource: 'bucket', exclusive: true}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread lib/rc.js Outdated
return this.get(['targets', project, type, name], []);
},

applyTarget: function(project, type, name, resources) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread lib/rc.js Outdated
if (!TARGET_TYPES[type]) {
throw new FirebaseError(
'Unrecognized target type ' + chalk.bold(type) +
'. Must be ' + _.keys(TARGET_TYPES).join(', '),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread lib/rc.js Outdated
* not persist the result.
*/
unsetTargetResource: function(project, type, name, resource) {
var tp = ['targets', project, type, name];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread test/lib/rc.spec.js
expect(subject.hasProjects).to.be.true;
});
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it doesn't -- the logic of save() is that it only persists to disk if a path is set in the constructor, which these tests don't do. save() just returns false otherwise.

@coveralls

coveralls commented Sep 28, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+1.2%) to 58.461% when pulling 0afef01 on mb-target-cmds into a6e5865 on mb-target.

@coveralls

coveralls commented Sep 28, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+1.2%) to 58.461% when pulling 99db9f1 on mb-target-cmds into a6e5865 on mb-target.

@mbleigh

mbleigh commented Sep 28, 2017

Copy link
Copy Markdown
Contributor Author

Filed a follow-up internal bug to track docs/wording updates of existing usage of "target".

@mbleigh mbleigh assigned laurenzlong and unassigned mbleigh Sep 28, 2017
@laurenzlong laurenzlong assigned mbleigh and unassigned laurenzlong Sep 28, 2017
@mbleigh
mbleigh merged commit 64a618c into mb-target Sep 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants