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

capistrano-pending functionality doesn't work unless db role is defined #58

Closed
erikhansen opened this issue Feb 12, 2017 · 4 comments
Closed

Comments

@erikhansen
Copy link
Contributor

When a db role is not defined, the capistrano-pending functionality doesn't work. For example, if you're using a role configuration like this:

role :app, %w{
  www-data@example.com
}

You'll get output like this:

18-18-04 new message-ysg1u

However if you setup both the app and db roles like this:

server 'example.com', user: 'www-data', roles: %w{app db}

You'll get output like expected:

18-21-01 new message-um2om

Forcing users to define a db role doesn't seem like the right approach, so I'll let you take it from here to come up with the proper approach to this bug as I don't have any more time to look into this.

This seems to be a bug caused by the Capistrano :revision variable (see here) not being populated unless a db role is defined. If you agree that this seems to be a core Capistrano bug, not anything related to this Gem, then you're free to close this issue. We may just want to update the relevant section of this Gem's readme to alert users of this bug and open an issue on the Capistrano issues list.

@davidalger
Copy link
Owner

davidalger commented Feb 24, 2017

Very good findings, thanks for sharing! Your notes about it being related to the :db role not being defined definitely got me on the right track.

The capistrano-pending gem looks to :capistrano_pending_role for the role to lookup the current revision on. If that var is unset, it defaults to :db. So technically not a bug in this gem, certainly not playing nice in all cases, as it would require configuring that gem as well.

I've made changes in the above commit to remedy the issue. In short, I'm setting that role to match the :magento_deploy_setup_role by default, but still allowing it to be overridden.

Now all of this said… I've been refactoring this code some more, as I was unraveling more issues with how the underlying functionality works (this is why back when you initially PR'd it I didn't want it enabled by default…I feared it would work inconsistently). For example:

  • If REVISION on the server is ahead of the commit being deployed, nothing is reported as being deployed, and the current implementation actually tells the user that the from and to are the same when they are in-fact, definitively NOT the same.

  • Oddities in how the revisions are reported, as the current revision is using the lengthy hash, but the deployed ref is using the symbolic name

  • Potential to incorrectly report pending changes on a multiple node deployment

In my refactoring, I'm discovering there really is very little in the 3rd-party gem which is not being done natively, so very well may remove it as a dependency by the time I'm finished ;)

davidalger added a commit that referenced this issue Feb 24, 2017
- removed capistrano-pending gem as a dependency
- multi-node pending change reporting is now supported
- users only warned about deploying (by default) when no pending changes are found on any node
- refs are printed in a user-friendly symbolic format now
- when target is ahead of deployed revision, user is warned about possibly going backwards in time and the log shown is a reverse log showing commits between current and commit being deployed (as is when deploying forward)

Issue #58
@erikhansen
Copy link
Contributor Author

Thanks for spending the time to make fix those issues.

davidalger added a commit that referenced this issue Feb 24, 2017
…ing messages

- also eliminated the warning being presented on a fresh deploy where no REVISION files existed

Issue #58
@davidalger
Copy link
Owner

davidalger commented Feb 24, 2017

Deploying to multiple hosts which no current deployment:
cap -bash bash 182x80 2017-02-24 14-56-49

Deploying even changes to multiple hosts:
cap -bash bash 182x80 2017-02-24 14-55-48

Deploying a revision behind what's currently deployed:
cap -bash bash 182x80 2017-02-24 14-57-16

Deploying a revision behind what's currently deployed (on single host to create disparity for future test run):
cap -bash bash 182x80 2017-02-24 14-57-47

Deploying to multiple hosts which with divergent revisions:
cap -bash bash 182x80 2017-02-24 14-58-29

No change deployment with the warning; stopped via 'n' input:
cap -bash bash 182x80 2017-02-24 14-59-56

Test with one host having nothing to deploy (warning should not show, with deployment continuing automatically):
cap -bash bash 182x80 2017-02-24 15-01-26

No change deployment with warning; proceeding via 'y' input:
cap -bash bash 182x80 2017-02-24 15-02-19

Just a simple deploy:pending to check on system works (with no warning since it's not a deploy):
cap -bash bash 182x80 2017-02-24 15-03-15

Adding the following to project configuration will disable warning that will show on deployments with no pending changes:

set :magento_deploy_pending_warn, false

There are a couple other default values such as the log format and default role to use set in the defaults.rb as well.

One fringe case which I have not accounted for (and I'm not sure this is a way to account for it very readily): If one is deploying to a different branch than currently deployed, the change log won't show what changes on the current branch are being removed from the server, which could affect deployments where users dynamically change the feature branch being deployed to the same target. An example is the following where the latest commit on the 2.1 branch is currently deployed and cap is asked to deploy from a tag on the 2.0 branch. In that case, the commits from the 2.0 branch will be printed, but the fact that whats currently on the server from the 2.1 branch is ignored:
cap -bash bash 182x80 2017-02-24 15-09-51

This should all be rolled out in the next release.

@erikhansen
Copy link
Contributor Author

Wow, this looks fantastic! Good work on accounting for all of those scenarios.

In regards to the fringe case you mentioned: if the 2nd point in this issue were to be implemented, it seems like it would solve for that use case, as it would warn the user that the deployed branch was being changed and they could do their due diligence to determine the impact of switching branches. I agree with your latest comment on that issue that creating the functionality as a separate Gem might make more sense. My team is managing an M1 project right now and they're frequently deploying different branches and it would be great to be able to pull that functionality into that project.

davidalger added a commit that referenced this issue Feb 24, 2017
tunght13488 added a commit to tunght13488/capistrano-magento2 that referenced this issue Apr 12, 2017
* upstream/master: (35 commits)
  Prep for release
  Added setting `:magento_deploy_jobs` to support configuring number of parallel static content deployment tasks
  Improved error reporting on static content deployment failure
  Updated uses of bin/magento where output is parsed to include `--no-ansi` to eliminate potential failures
  Fixed issue where ./update dir may exist without a composer.json file, causing deployment failure
  Version bump
  Fixed Magento version check failing on some servers due to ansi output in non-interactive shells
  Cleaned up add auth credential settings and added information to README
  Updated pending change log hook
  README corrections
  Fixed spelling error in README (lame spell checker, lame)
  Updated CL and version number
  Updates to README for issue davidalger#58
  Updated messaging to include host name on all pending change log heading messages
  Added full-featured pending changes logging
  Set :capistrano_pending_role default to match :magento_deploy_setup_role to avoid potential incompatibilities
  Fixed inability to set PATH in capistrano configuration vs `.bashrc` file
  Remove terminal-notifier dependency
  Prepare for version 0.5.9 release
  Add composer magento auth config
  ...
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

No branches or pull requests

2 participants