Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there Environment variable for Amazon ElasticBeanstalk containers for the deployed version?

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?

like image 643
Peter Fox Avatar asked Oct 04 '22 07:10

Peter Fox


2 Answers

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.

like image 117
kukido Avatar answered Oct 11 '22 14:10

kukido


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.

like image 22
Joseph Sheedy Avatar answered Oct 11 '22 14:10

Joseph Sheedy