Hello,
I want know wheather its possible to automatically push code to production server? I have my code repo in bitbucket (git) and cloned it into my localhost and my production server. Whenever I do changes, I push it from the localhost and then pull it from the production server. Production server runs on EC2 ubuntu.
We use Pipelines with our Drupal 7 sites. Every time we approve a pull request to master branch, it automatically deploys to staging (we use WHM cPanel) by running the Pipeline which
We also have a production branch for deploying automatically to live (so we don't accidentally deploy something live that is on master - it's a specific step to ensure we're only deploying good code to the live server). Same thing. Pull request from master to production and the Pipeline runs again, deploying to live.
You, of course, need to set up your SSH keys so the Pipeline has permissions to deploy files to the server/s.
This is what the bitbucket-pipelines.yml in the root of our Drupal 7 project looks like.
image: phpunit/phpunit:5.0.3
pipelines:
branches:
master:
- step:
script:
- make ci-setup
- make ci-pre-deploy DRUSH=DRUSH_REMOTE_STAGING
- make ci-deploy-staging
- make ci-post-deploy DRUSH=DRUSH_REMOTE_STAGING
production:
- step:
script:
- make ci-setup
- make ci-pre-deploy DRUSH=DRUSH_REMOTE_PRODUCTION
- make ci-deploy-production
- make ci-post-deploy DRUSH=DRUSH_REMOTE_PRODUCTION
This is what the Makefile in the root of our Drupal 7 project looks like.
USER=__cpanel_username_here__
STAGING_HOST=123.456.789.123
PRODUCTION_HOST=987.654.321.987
DRUSH_REMOTE_STAGING=ssh $(USER)@$(STAGING_HOST) drush -r public_html
DRUSH_REMOTE_PRODUCTION=ssh $(USER)@$(PRODUCTION_HOST) drush8 -r public_html
ci-setup:
mkdir -p ~/.ssh
cat deploy/known_hosts >> ~/.ssh/known_hosts
(umask 077 ; echo $$SSH_KEY | base64 --decode > ~/.ssh/id_rsa)
ci-deploy-staging:
rsync -e 'ssh' -irKzl --delete --verbose --exclude-from="deploy/.deploy-ignore" "./" $(USER)@$(STAGING_HOST):public_html
ci-deploy-production:
rsync -e 'ssh' -irKzl --delete --verbose --exclude-from="deploy/.deploy-ignore" "./" $(USER)@$(PRODUCTION_HOST):public_html
ci-pre-deploy:
if [[ -f sites/default/settings.php ]] ; then $($(DRUSH)) vset maintenance_mode 1; else echo "Nothing to do"; fi
ci-post-deploy:
if [[ -f sites/default/settings.php ]] ; then $($(DRUSH)) updb -y; else echo "Nothing to do"; fi
if [[ -f sites/default/settings.php ]] ; then $($(DRUSH)) vset maintenance_mode 0; else echo "Nothing to do"; fi
We also have a /deploy folder with a .deploy-ignore file...
README.txt
INSTALL.txt
MAINTAINERS.txt
UPGRADE.txt
CHANGELOG.txt
COPYRIGHT.txt
sites/default/settings.php
sites/default/files
tmp
Makefile
.sass-cache
*.css.map
.gitdeploy
.idea
bitbucket-pipelines.yml
error_log
cgi-bin
Also in the /deploy folder, there is a known_hosts file with ssh keys in there.
One of our senior dev team set this up, and I don't know every in-and-out of our config (eg. the Docker image that does the deploying) so the above won't just be a copy-and-paste affair. But hopefully, it will point you in the right direction. At least you now know it can work with Drupal 7 (I'm still trying to figure out how to get it rocking with Drupal 8 and composer).
Here is a link to the Pipeline docks. Hopefully, this post and the docs will get you going.
Auto-deployment with Pipelines has been SUCH a time saver for our team.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.