Skip to content

Instantly share code, notes, and snippets.

@danharper
Created February 11, 2015 12:46
Show Gist options
  • Save danharper/6150e408356d0b678938 to your computer and use it in GitHub Desktop.
Save danharper/6150e408356d0b678938 to your computer and use it in GitHub Desktop.
How we deploy InventoryBase from CircleCI
machine:
php:
version: 5.6.5
dependencies:
cache_directories:
- vendor
- node_modules
pre:
- sudo pip install awscli
test:
pre:
- ./bin/compile-js
override:
- ./vendor/phpspec/phpspec/bin/phpspec run
deployment:
stage:
branch: develop
commands:
- ./.circle/deploy-stage.sh
production:
branch: master
commands:
- ./.circle/deploy-production.sh
#!/bin/bash -eu
GIT_SHA=$CIRCLE_SHA1 # use the current git commit SHA, which CircleCI provides us
NOW=`date '+%F-T-%H-%M-%S'` # date formatted like: 2014-10-09-T-15-59-31
TARBALL="IB-$NOW.tar.gz" # archive will be named as the current date & time
S3_BUCKET="INSERT_SOMETHING_HERE" # the name of the S3 bucket to store the archive in
BUILD_SERVER_IP=INSERT_SOMETHING_HERE # the IP address of the build & deploy server
######################################################################
# Remove existing an existing archive if it exists
######################################################################
rm -f $TARBALL
######################################################################
# Write a public file containing the deployment's date & sha
######################################################################
echo "{\"sha\":\"$GIT_SHA\",\"date\":\"$NOW\"}" > public/release.txt
######################################################################
# Archive all system assets to a tarball ready for upload
######################################################################
echo "Archiving as $TARBALL..."
tar czf $TARBALL bin migrations fuel lib public src vendor oil phinx.yml
echo "Achiving complete."
######################################################################
# Upload to S3 bucket named as date, then copy as Latest.tar.gz
######################################################################
echo "Uploading to S3 bucket..."
aws s3 cp $TARBALL s3://$S3_BUCKET
aws s3 cp s3://$S3_BUCKET/$TARBALL s3://$S3_BUCKET/Latest-IB-Production.tar.gz
echo "S3 upload complete."
######################################################################
# Notify all EC2 instances to update from S3 bucket
######################################################################
echo "Notifying build server..."
ssh ubuntu@$BUILD_SERVER_IP "source ~/.profile; ./ansible/Deploy-IB-Production.sh"
echo "Ding."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment