Elastic BeanStalk app deploy post 挂钩不执行我的命令

Elastic BeanStalk app deploy post hook not executing my command

我最近能够在 Elastic Beanstalk 上使用 codepipeline 部署我的 Laravel 应用程序,但 运行 遇到了问题。我注意到我的路由由于 php.conf Nginx 配置而失败。我必须在 EB 的 nginx php.conf 文件中添加几行代码才能使其正常工作。

我现在的问题是每次部署后,我修改 php.conf 文件的应用程序实例都被销毁并重新创建。我想要一种在每次成功部署后动态更新文件的方法。我有一个文件版本,我希望在我的应用程序中对其进行版本控制,因此想在部署后创建指向该文件的符号链接。

经过大量研究,我在 Elastic Beanstalk 上偶然发现了 appDeploy Hooks,部署后 运行s post 脚本也是如此

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/91_post_deploy_script.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      sudo mkdir /var/testing1
      sudo ln -sfn /var/www/html/php.conf.example /etc/nginx/conf.d/elasticbeanstalk/php.conf
      sudo mkdir /var/testing
      sudo nginx -s reload

由于某种原因,这不起作用。符号链接未创建,所以我的路线仍然无法正常工作..

我什至添加了一些 mkdir,因此可以确定该脚本中的命令 运行s,这些命令的 none 运行 因为创建这些目录的 none。

请注意,如果我通过 ssh 进入 ec2 实例并 运行 那里的命令有效。 bash 脚本也存在于 post 目录中,如果我在服务器上手动 运行 它也可以工作。

任何有关如何解决此问题的指示都会有所帮助。也许我也做错了。

现在我已经通过关注 this 获得了我的脚本 运行。但是,脚本不是运行ning。我收到一个错误

2020/06/28 08:22:13.653339 [INFO] Following platform hooks will be executed in order: [01_myconf.config]
2020/06/28 08:22:13.653344 [INFO] Running platform hook: .platform/hooks/postdeploy/01_myconf.config
2020/06/28 08:22:13.653516 [ERROR] An error occurred during execution of command [app-deploy] - [RunPostDeployHooks]. Stop running the command. Error: Command .platform/hooks/postdeploy/01_myconf.config failed with error fork/exec .platform/hooks/postdeploy/01_myconf.config: permission denied 

我试图关注这个论坛 post here 通过向我的容器命令添加一个新命令来使我的文件可执行,如下所示:

01_chmod1:
        command: "chmod +x .platform/hooks/postdeploy/91_post_deploy_script.sh"

我还在运行遇到同样的问题。权限被拒绝

在项目根文件夹中创建一个名为 .platform 的文件夹,并在 .platform[ 中创建一个名为 00_myconf.config 的文件=22=]文件夹。

.platform/
          00_myconf.config

打开00_myconf.config并添加脚本

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/91_post_deploy_script.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      sudo mkdir /var/testing1
      sudo ln -sfn /var/www/html/php.conf.example /etc/nginx/conf.d/elasticbeanstalk/php.conf
      sudo mkdir /var/testing
      sudo nginx -s reload

提交您的更改或重新上传项目。在创建每个新实例时都会考虑此 .platform 文件夹,并且您的应用程序将在 Amazon Elastic beanstalk 创建的所有新实例中正确部署。

遗憾的是,您描述的挂钩(即 /opt/elasticbeanstalk/hooks/appdeploy)适用于 Amazon Linux 1.

由于您使用的是 Amazon Linux 2,如评论中所述,您尝试使用的挂钩不适用。因此它们没有被执行

在 Amazon Linux 2 中,有描述的新挂钩 here 它们是:

prebuild – Files here run after the Elastic Beanstalk platform engine downloads and extracts the application source bundle, and before it sets up and configures the application and web server.

predeploy – Files here run after the Elastic Beanstalk platform engine sets up and configures the application and web server, and before it deploys them to their final runtime location.

postdeploy – Files here run after the Elastic Beanstalk platform engine deploys the application and proxy server.

这些新挂钩的使用与在 Amazon Linux 1 中不同。因此您必须返回 Amazon Linux 1 或迁移您向亚马逊申请 Linux 2.

一般迁移步骤 从亚马逊Linux 1 到亚马逊Linux 2 在EB 中描述here

如果您访问文档 here 并滚动到标题为“带扩展的应用程序示例”的部分,您可以看到 .platform 文件夹的文件夹结构示例,因此它将您的自定义配置添加到NGINX conf 每次部署。

您可以用您的文件替换整个 nginx.conf 文件,或者将其他配置文件添加到 conf.d 目录

在应用程序部署时用您的文件替换 conf 文件: .platform/nginx/nginx.conf

将配置文件添加到nginx.conf: .platform/nginx/conf.d/custom.conf