WebP support with AWS ElasticBeanstalk

2019-04-13 06:15发布

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

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:

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

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

1条回答
▲ chillily
2楼-- · 2019-04-13 06:52

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

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>


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 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.

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.

I added the code I deployed to Github, for easy reference too. https://github.com/hephalump/testphp

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.

查看更多
登录 后发表回答