AWS ElasticBeanstalk的WebP支持 [英] WebP support with AWS ElasticBeanstalk

查看:101
本文介绍了AWS ElasticBeanstalk的WebP支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试支持将webp格式与EB结合使用,但是它不能按预期方式工作...

I try to support the use of the webp format with EB, however it's not working as expected...

我在.ebextensions中使用以下命令创建了一个.config文件:

I created a .config file in .ebextensions with this:

commands:
01-command:
    command: wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-0.5.0.tar.gz

02-command:
    command: tar xvzf libwebp-0.5.0.tar.gz

03-command:
    command: cd libwebp-0.5.0

04-command:
    command: ./configure

05-command:
    command: make

06-command:
    command: sudo make install

但是在部署时出现此错误:

But when deploying I got this error:

错误:实例上的命令失败.返回码:127输出:/bin/sh:./configure:没有这样的文件或目录.

ERROR: Command failed on instance. Return code: 127 Output: /bin/sh: ./configure: No such file or directory.

我做错什么了吗? (环境:运行PHP 5.6的64位Amazon Linux 2015.09 v2.0.6)

Am I doing something wrong? (environment: 64bit Amazon Linux 2015.09 v2.0.6 running PHP 5.6)

推荐答案

您需要执行安装后部署. 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 appdeployls,然后将获得两个目录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.

  1. create_post_dir 第一步是使用mkdir命令在服务器上实际创建"post"目录. mkdir "/opt/elasticbeanstalk/hooks/appdeploy/post"将为我们执行此操作,因此我们将其创建为命令.
  2. 文件通过文件配置,我们可以通过ElasticBeanstalk在目录中创建文件.对于我们的目的而言非常方便!文件操作的第一行为我们提供了要创建的文件的名称.我们将创建一个Shell脚本来执行命令,您可以随意调用它,但我将从99开始并继续.我们将这个正在创建的shell脚本称为"99_install_libwebp.sh".
  3. 文件设置接下来的三行用于设置文件设置.确保root拥有它们,并且在那里存在000755.
  4. 文件内容,这是我们正在创建的文件的内容.直截了当.将您的shell脚本放在那里,一切都很好.
  5. 加载环境vars 我们选择加载eb环境变量,以便我们的脚本可以知道该应用程序当前版本的位置.它通常位于/var/app/current中,但取决于多种因素,它可能位于其他位置.我们将使用环境变量使我们的生活更轻松.
  6. 更改为当前应用程序目录.我们将转到当前应用程序目录cd,以便我们可以执行我们在这里要做的事情.
  7. 获取所需的包,使用wget获取所需的libwebp
  8. 打开包装自我解释
  9. 更改为程序包目录现在,我们已经解压缩了程序包,可以更改为程序包目录.
  10. 做我们需要做的事情.我们现在可以运行./configure、make和make install.
  1. create_post_dir First step is to actually going to create the "post" directory on the server using the mkdir command. mkdir "/opt/elasticbeanstalk/hooks/appdeploy/post" will do that for us, so we'll create that as the command.
  2. files The files config allows us to create a file in a directory via ElasticBeanstalk. Pretty convenient for our purposes! The first line of the files action gives us the name of the file to create. We'll create a shell script to execute out commands, and you can call it whatever you want, but I'd start with 99 and go onwards. We'll call this shell script that we're creating "99_install_libwebp.sh".
  3. File settings The next three lines set the file settings. Make sure root owns them and that there 000755'd.
  4. File Contents This is the content of the file we're creating. Straight forward. Put your shell script in there and you're good to go.
  5. Load environment vars We opted to load the eb environment variables so our script can know where the current version of the app is. It's usually in /var/app/current but it could be elsewhere depending on a variety of factors. We'll use the environment variables to make life a bit easier for us.
  6. Change to our current app directory We're going to cd to our current app directory so we can do what we we're here to do.
  7. Get the package we want use wget to get the libwebp we want
  8. Unpack the package self explanatory
  9. Change to the package directory Now that we've unpacked the package we can change to the package directory.
  10. Do what we need to do We can now run our ./configure, make, and make install.

就是这样.您可以使用隐身的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.

这篇关于AWS ElasticBeanstalk的WebP支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆