2
votes

I'm deploying an application with elastic beanstalk, which has its own deploy tool. This tool takes the latest commit, creates a zip from it, and deploys that to the cloud. To verify the deploy on each server, I'd like it to be able to report its own SHA once it has been deployed. There are actually a few valid approaches:

  • Add SHA to current commit, with a git hook.
  • Alter the EB deploy scripts to include a specific uncommitted file, which can be easily created in a deploy script or git hook.
  • Make elastic beanstalk current application version label available to the instance.
3
What exactly is the question you are asking?Mark B

3 Answers

10
votes

I solved this with .gitattribtues export-subst. (http://git-scm.com/docs/gitattributes) This automatically adds the SHA to the repo when it is archived, which is what elastic-beanstalk does upon deploy.

My .gitattributes:

*.py diff=python
version.txt export-subst

My version.txt:

$Format:%H$

See https://stackoverflow.com/a/16365314/478354

0
votes

Add SHA to current commit, with a git hook.

This doesn't seem practival, as it would change the commit (and its SHA1)!

So generating the right file based on the commit, at deploy time is usually the best practice.

0
votes

You can create a post deploy hook, and access the SHA version in a bash script.

Here is an example that worked for me:

Create a file like .ebextensions/post_deploy_hook.config with this content:

commands:
  create_pre_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/pre"
    ignoreErrors: true
  create_post_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/rollback_deploy_tracking.sh":
    content: |
      #!/bin/bash

      REVISION=`unzip -z /opt/elasticbeanstalk/deploy/appsource/source_bundle | tail -n 1`

      # put your own logic here...

      exit 0;

Now when deploying with eb deploy that script will run.