Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stage dependency requirement should check all specified tasks for a stage rather than just the first one #1735

Open
olbrich opened this Issue Jul 24, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@olbrich
Copy link

olbrich commented Jul 24, 2016

Rationale

On rare occasions it is necessary call tasks before the stage definition file is loaded. For example, I have a task that sets the AWS_REGION and needs to be executed before the stage file is loaded.

Actual behavior

Capistrano checks the first task called to see if it's a stage or a default task. If it is not, the stage dependency message is emitted.

Requested behaviour

Capistrano should only complain about the stage not being set if there is not one (and only one) stage task called anywhere in the top level tasks.

Notes

If this restriction is lifted, there is a chance that users could misuse capistrano by issuing commands like cap deploy production. This would probably result in an error instead of a helpful error message. Alternately it might be possible to add a dependency on a task that removes the stage dependency.

@leehambley

This comment has been minimized.

Copy link
Member

leehambley commented Jul 25, 2016

First thoughts:

  • set your aws region in a task after the stage definition ($ cap stage set-aws-region deploy)
  • make the aws region part of your stage

You addressed the first idea when you mentioned

I have a task that sets the AWS_REGION and needs to be executed before the stage file is loaded.

Could you elaborate on what set of circumstances lead to this?

@olbrich

This comment has been minimized.

Copy link
Author

olbrich commented Jul 26, 2016

The stage file dynamically detects the servers present within a region that are part of the stage based on instance tags, but the region needs to be set so it can properly determine which one to use. I'm trying to setup our system so that I can replicate the same setup in two different regions (for disaster recovery purposes).

@leehambley

This comment has been minimized.

Copy link
Member

leehambley commented Jul 26, 2016

Alternative @olbrich if you know that you're always going to need this

task :production => :set_region
task :staging => :set_region

(If I remember Rake correctly, this "reopens" production and staging and adds :set_region as a prerequisite, so it :set_region will run before the stage task. This might work?

We have a method that will list all stages, so rather than enumerate one line per stage, you could call this and set the prerequisite in a loop.

You might also be able to hook here with something like:

task :ensure_region do
    # ensure region is set, prompt for it, or exit?
end
task :ensure_stage => :ensure_region
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.