This post shows how we can use Continuous Integration using Travis-CI and deploy a DocPad based static website/blog to Amazon S3.
Continuous Integration (CI) tools such as Travis, Jenkins etc. help compile and deploy source code multiple times a day. Install Travis command line tools using the commands below.
sudo apt-get install ruby sudo apt-get install rubygems gem uninstall travis-cli #uninstall the old client sudo gem install travis # install travis sudo gem install json sudo gem install travis-lint #to check if .travis.yml file is validHere is the raw version of the script above.
Setup a file named .travis.yml in your git directory as below. This will hook git to travis-ci
/#http://docs.travis-ci.com/user/deployment/s3/ deploy: provider: s3 access_key_id: "" #YOUR ENCRYPTED AWS ACCESS KEY secret_access_key: "" #YOUR ENCRYPTED AWS SECRET KEY bucket: "make.stanleygeorge.com" skip_cleanup: true local-dir: out on: tags: trueHere is the raw version of the script above.
Security
You can encrypt your AWS credentials using:
travis encrypt access_key_id:YOUR-AWS-ACCESS-KEY-ID
These commands replace the entries in your .travis.yml file with something like this:
travis encrypt secret_access_key:YOUR-AWS-SECRET-ACCESS-KEY
deploy: access_key_id: secure: "ABC5OwLpwB7L6Ca...." secret_access_key: secure: "ABC5OwLpwB7L6Ca...."This set of encryption keys will work ONLY on your repository. If someone forks your repository, then these keys will not work for them. The encrypted keys on the new repository will be different. This is good since you do not have to worry about someone forking your repository and overwriting the files in your S3 bucket.More detais on travis encryption keys can be found here. These files are fairly safe to be committed. A better practice is to use AWS IAM.
Now when you commit to git, a Travis-CI build will be triggered. This is how a sample build looks like. You will also need to add a policy on your Amazon S3 bucket so that all files uploaded to it are public read
If you prefer not to use either GitHub or Travis-CI and prefer to upload the files manually to Amazon S3, see this post on using Amazon CLI tool.
References