我正在使用弹性beanstalk部署应用程序,该应用程序具有自己的部署工具。此工具采用最新提交,从中创建zip,并将其部署到云。要验证每台服务器上的部署,我希望能够在部署后报告自己的SHA。实际上有一些有效的方法:
答案 0 :(得分:10)
我用.gitattribtues export-subst解决了这个问题。 (http://git-scm.com/docs/gitattributes)这会在归档时自动将SHA添加到repo中,这就是弹性beanstalk在部署时的作用。
我的.gitattributes:
*.py diff=python
version.txt export-subst
我的版本.txt:
$Format:%H$
答案 1 :(得分:0)
使用git hook将SHA添加到当前提交。
这似乎不是实际的,因为它会改变提交(及其SHA1)!
因此,在部署时基于提交生成正确的文件通常是最佳做法。
答案 2 :(得分:0)
您可以创建一个部署后挂钩,并在bash脚本中访问SHA版本。
以下是对我有用的示例:
创建具有以下内容的文件,例如.ebextensions/post_deploy_hook.config
:
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;
现在,当使用eb deploy
进行部署时,该脚本将运行。