【发布时间】:2021-06-07 23:05:20
【问题描述】:
在我运行 eb create command 之前,如何告诉 Elastic Beanstalk 使用不同的 docker-compose 文件?
比如我的项目目录:
HelloWorldDocker
├──.elasticbeanstalk
│ └──config.yml
├──app/
├──proxy/
└──docker-compose.prod.yml
└──docker-compose.yml
- 我的
docker-compose.yml用于本地开发 - 我的
docker-compose.prod.yml是我想用于生产的东西
有没有办法在从 EB CLI 运行 eb create 命令之前定义此配置?
显而易见:我意识到我可以将docker-compose.yml 用于我的生产文件,将docker-compose.dev.yml 用于我的本地开发,但随后在本地运行docker-compose up 命令变得更加乏味(即: docker-compose -f docker-compose.dev.yml up --build...)。此外,我主要感兴趣的是这是否可能,因为我正在学习 Elastic Beanstalk,以及如果我愿意,我如何可以做到这一点。
编辑/更新:2021 年 6 月 11 日
我尝试将 .ebextensions/docker-settings.config 中的 docker-compose.prod.yml 重命名为 docker-compose.yml,如下所示:
container_commands:
rename_docker_compose:
command: mv docker-compose.prod.yml docker-compose.yml
>eb 部署:
2021-06-11 16:44:45 ERROR Instance deployment failed.
For details, see 'eb-engine.log'.
2021-06-11 16:44:45 ERROR Instance deployment: Both
'Dockerfile' and 'Dockerrun.aws.json' are missing in your
source bundle. Include at least one of them. The deployment
failed.
在 eb-engine.log 中,我看到:
2021/06/11 16:44:45.818876 [ERROR] An error occurred during
execution of command [app-deploy] - [Docker Specific Build
Application]. Stop running the command. Error: Dockerfile and
Dockerrun.aws.json are both missing, abort deployment
根据我的测试,这是因为 AWS 需要在进入 container_commands 的后续步骤之前调用 /bin/sh -c docker-compose config。
编辑/更新 #2
如果我使用commands 而不是container_commands:
commands:
rename_docker_compose:
command: mv docker-compose.prod.yml docker-compose.yml
cwd: /var/app/staging
它确实似乎成功完成了替换:
2021-06-11 21:40:44,809 P1957 [INFO] Command find_docker_compose_file
2021-06-11 21:40:45,086 P1957 [INFO] -----------------------Command Output-----------------------
2021-06-11 21:40:45,086 P1957 [INFO] ./var/app/staging/docker-compose.prod.yml
2021-06-11 21:40:45,086 P1957 [INFO] ------------------------------------------------------------
2021-06-11 21:40:45,086 P1957 [INFO] Completed successfully.
但我仍然被击中:
2021/06/11 21:40:45.192780 [ERROR] An error occurred during
execution of command [app-deploy] - [Docker Specific Build
Application]. Stop running the command. Error: Dockerfile and
Dockerrun.aws.json are both missing, abort deployment
编辑/更新:2021 年 6 月 12 日
我使用的是 Windows 10 机器。在本地运行eb deploy 命令之前,我打开了使用 MINGW64 终端的 Git Bash。我cdd 到prebuild 存在build.sh 的目录。我跑了:
chmod +x build.sh
如果我执行ls -l,它会返回:
-rwxr-xr-x 1 Jarad 197121 58 Jun 12 12:31 build.sh*
我认为这意味着该文件是可执行的。
然后我致力于 git。
然后我跑了eb deploy。
我在 eb-engine.log 中看到 build.sh: permission denied 错误。以下是相关部分的摘录。
...
2021/06/12 19:41:38.108528 [INFO] application/zip
2021/06/12 19:41:38.108541 [INFO] app source bundle is zip file ...
2021/06/12 19:41:38.108547 [INFO] extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/
2021/06/12 19:41:38.108556 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /var/app/staging/
2021/06/12 19:41:38.149125 [INFO] finished extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/ successfully
2021/06/12 19:41:38.149142 [INFO] Executing instruction: RunAppDeployPreBuildHooks
2021/06/12 19:41:38.149190 [INFO] Executing platform hooks in .platform/hooks/prebuild/
2021/06/12 19:41:38.149249 [INFO] Following platform hooks will be executed in order: [build.sh]
2021/06/12 19:41:38.149255 [INFO] Running platform hook: .platform/hooks/prebuild/build.sh
2021/06/12 19:41:38.149457 [ERROR] An error occurred during execution of command [app-deploy] - [RunAppDeployPreBuildHooks]. Stop running the command. Error: Command .platform/hooks/prebuild/build.sh failed with error fork/exec .platform/hooks/prebuild/build.sh: permission denied
2021/06/12 19:41:38.149464 [INFO] Executing cleanup logic
2021/06/12 19:41:38.149572 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1623526898,"severity":"ERROR"}]}]}
2021/06/12 19:41:38.149706 [INFO] Platform Engine finished execution on command: app-deploy
...
知道为什么我会收到权限被拒绝错误吗?
我从这种疯狂中得出的结论
Elastic Beanstalk 的 EB CLI eb deploy 命令无法在 Windows 计算机上正确压缩文件(它创建的 app_source_bundle)。
证明
我可以通过在本地压缩它并通过 Elastic Beanstalk 在线界面手动上传 recreate Marcin's example。当我这样做并检查源包时,它显示build.sh 确实具有可执行权限(-rwxr-xr-x)。
[root@ip-172-31-11-170 deployment]# zipinfo app_source_bundle
Archive: app_source_bundle
Zip file size: 993 bytes, number of entries: 5
drwxr-xr-x 3.0 unx 0 bx stor 21-Jun-13 03:08 .platform/
drwxr-xr-x 3.0 unx 0 bx stor 21-Jun-13 03:08 .platform/hooks/
drwxr-xr-x 3.0 unx 0 bx stor 21-Jun-13 03:08 .platform/hooks/prebuild/
-rwxr-xr-x 3.0 unx 58 tx defN 21-Jun-13 03:09 .platform/hooks/prebuild/build.sh
-rw-r--r-- 3.0 unx 98 tx defN 21-Jun-13 03:08 docker-compose.prod.yml
当我 initialize and create 使用 EB CLI 和完全相同的文件时,build.sh 没有具有可执行权限 (-rw-rw-rw-)。
[ec2-user@ip-172-31-5-39 deployment]$ zipinfo app_source_bundle
Archive: app_source_bundle
Zip file size: 1092 bytes, number of entries: 5
drwxrwxrwx 2.0 fat 0 b- stor 21-Jun-12 20:32 ./
-rw-rw-rw- 2.0 fat 98 b- defN 21-Jun-12 20:08 docker-compose.prod.yml
-rw-rw-rw- 2.0 fat 993 b- defN 21-Jun-12 20:15 myzip.zip
drwxrwxrwx 2.0 fat 0 b- stor 21-Jun-12 20:08 .platform/hooks/prebuild/
-rw-rw-rw- 2.0 fat 58 b- defN 21-Jun-12 20:09 .platform/hooks/prebuild/build.sh
因此,我认为这是 AWS EB CLI 部署命令在如何为 Windows 用户压缩文件方面的错误。
【问题讨论】:
-
commands似乎可以工作,因为它必须在您当前工作的 eb 环境中运行。commands在你的 zip 文件被解压之前执行。 -
另外,只是为了在更新后澄清。当您提供正确的文件名时,一切都在 EB 中工作?所以问题是如何将 docker-compose.prod.yml 重命名为 docker-compose.yml?
-
是的。我有一个工作项目。当我在项目的根目录中有一个名为
docker-compose.yml的文件时,它可以工作。当我将其重命名为docker-compose.prod.yml时,我想配置 Elastic Beanstalk 以在此过程中的正确时间将此文件重命名为docker-compose.yml。 -
我用我的复制品和解决方案更新了答案。
标签: amazon-web-services docker-compose amazon-elastic-beanstalk