更新时间:2023-11-29 15:29:46
您需要执行安装后部署. AWS尚未真正记录如何执行 post 部署命令,因此我将在此处进行.
You need to execute the install post deployment. AWS hasn't really documented how to execute commands post deployment, so I'll do so here.
commands:
create_post_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_install_libwebp.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
. /opt/elasticbeanstalk/support/envvars
cd $EB_CONFIG_APP_CURRENT
wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-0.5.0.tar.gz
tar xvzf libwebp-0.5.0.tar.gz
cd libwebp-0.5.0
sudo ./configure
sudo make
sudo make install
正如我提到的那样,AWS并未真正记录您可以在ElasticBeanstalk部署后实际执行脚本.如果您查看eb-commandprocessor.log文件,您会发现eb寻找AppDeployPreHook(6之4)和AppDeployPostHook(2之1).看起来像这样:
As I mentioned, AWS has not really documented that you can actually execute scripts on ElasticBeanstalk post deployment. If you talk a look in the eb-commandprocessor.log file you will see that eb looks for AppDeployPreHook (4 of 6) and AppDeployPostHook (1 of 2). It will look something like this:
[2016-04-13T14:15:22.955Z] DEBUG [8851] : Loaded 6 actions for stage 0.<br>
[2016-04-13T14:15:22.955Z] INFO [8851] : Running 1 of 6 actions: InfraWriteConfig...<br>
[2016-04-13T14:15:22.962Z] INFO [8851] : Running 2 of 6 actions: DownloadSourceBundle...<br>
[2016-04-13T14:15:23.606Z] INFO [8851] : Running 3 of 6 actions: EbExtensionPreBuild...<br>
[2016-04-13T14:15:24.229Z] INFO [8851] : Running 4 of 6 actions: AppDeployPreHook...<br>
[2016-04-13T14:15:28.469Z] INFO [8851] : Running 5 of 6 actions: EbExtensionPostBuild...<br>
[2016-04-13T14:15:28.970Z] INFO [8851] : Running 6 of 6 actions: InfraCleanEbextension...<br>
[2016-04-13T14:15:28.974Z] INFO [8851] : Running stage 1 of command CMD-AppDeploy...<br>
[2016-04-13T14:15:28.974Z] DEBUG [8851] : Loaded 2 actions for stage 1.<br>
[2016-04-13T14:15:28.974Z] INFO [8851] : Running 1 of 2 actions: AppDeployEnactHook...<br>
[2016-04-13T14:15:29.600Z] INFO [8851] : Running 2 of 2 actions: AppDeployPostHook...<br>
[2016-04-13T14:16:42.048Z] INFO [8851] : Running AddonsAfter for command CMD-AppDeploy... <br>
那个小小的"AppDeployPostHook"告诉我们它正在搜索脚本以运行后期部署.您可以在服务器的/opt/elasticbeanstalk
目录中找到eb部署脚本,如果在该目录中使用ssh和ls
,则会找到hooks
,这正是我们要查找的,如果您cd hooks
,您将找到appdeploy目录,依次为cd appdeploy
和ls
,然后将获得两个目录pre和enact.这似乎很平凡,但确实很棒,因为现在我们知道eb在哪里寻找正在运行的脚本.由于AppDeployPreHook脚本是从"pre"目录执行的,我们知道我们需要一个"post"目录来执行eb正在运行的AppDeployPostHook的命令后部署.现在我们知道该怎么做,我们可以开始编写命令了.
That little "AppDeployPostHook" tells us that it is searching for scripts to run post deployment. You can find the eb deployment scripts in the /opt/elasticbeanstalk
directory on the server, and if you ssh in and ls
on that directory you'll find hooks
, which is what we're looking for, and if you cd hooks
you'll find the appdeploy directory, cd appdeploy
and then ls
and you'll get two directories pre and enact. This seems mundane but is really great, because now we know where eb is looking for scripts it's running. Since the AppDeployPreHook scripts are executing from the "pre" directory we know that we'll need a "post" directory to execute a command post deployment with that AppDeployPostHook that eb is running. Now that we know what to do, we can start writing our commands.
mkdir "/opt/elasticbeanstalk/hooks/appdeploy/post"
将为我们执行此操作,因此我们将其创建为命令.mkdir "/opt/elasticbeanstalk/hooks/appdeploy/post"
will do that for us, so we'll create that as the command.就是这样.您可以使用隐身的AppDeployPostHook来运行几乎所需的任何部署后命令.如果您需要安装软件包,重新启动服务或在部署后执行其他任何操作,则超级有用.
That's it. You can use the stealthy AppDeployPostHook to run pretty much any post deployment command that you need. Super useful if you need to install packages, restart services, or do anything else post deployment.
我添加了我部署到Github的代码,以方便参考. https://github.com/hephalump/testphp
I added the code I deployed to Github, for easy reference too. https://github.com/hephalump/testphp
注意:我这样做是在一个稍有不同的环境中成功完成的.我使用ElasticBeanstalk在64位Amazon Linux 2016.03 v2.1.0上使用最新环境版本PHP 5.6部署了新的PHP应用程序;我无法选择使用的环境类型...实际上,这是我唯一可以使用的PHP 5.6版本,所以我同意了.
Note: I did this successfully running a slightly different environment. I used ElasticBeanstalk to deploy a new PHP application using the latest environment version which is PHP 5.6 on 64bit Amazon Linux 2016.03 v2.1.0; the environment type that you are using was not available as an option to me... Actually, this was the only version with PHP 5.6 that was available to me so I went with that.