I'm trying to make a deployment hook so when I deploy my PHP application to EB it will send the application code version or the git commit point, possibly even the git tag if one exists to my analytics service.
I was wandering if there's any environment variables that are set on the instances to say what version they're running is or if it even copies any of the git data to an instance that's been deployed as part of an EB setup?
AFAIK, when Elastic Beanstalk deploys your application to the cloud, it creates an archive with git archive
command. The resulting archive file does not have any repository metadata. Although Elastic Beanstalk is using your commit sha1 as part of the version name, if you are using your own versioning schema, sha1 might not be available.
As an alternative, you can create a shell script to send the commit information to your analytics service. With git alias you can execute your script and aws.push
as one command.
# .git/config
[alias "custom"]
push = !git aws.push $1 && ./custom.sh
# custom.sh
commit=$(git rev-parse HEAD)
echo 'send info to analytics service for commit: ' $commit
Then execute it as $ git custom.push
In the example above, custom.sh will be executed even when aws.push
resulted in error, so if you need more reliable solution, you might want to integrate it tighter with .git/AWSDevTools/aws.elasticbeanstalk.push
script itself.
Hope it helps.
For my Python app deployed from Git, the commit SHA-1 which is used for the beanstalk version is stored in the comment field of the source ZIP file of the currently deployed app. On application startup, I extract that value and expose it to the app.
The Python code is
with zipfile.ZipFile('/opt/elasticbeanstalk/deploy/appsource/source_bundle') as z:
return z.comment
You can check the value from the shell with
$ unzip -z /opt/elasticbeanstalk/deploy/appsource/source_bundle
Archive: /opt/elasticbeanstalk/deploy/appsource/source_bundle
1049cbed865334a805ae2ae3179339dd...
You could use ZipArchive::getArchiveComment in PHP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With