eb create
命令之前,我该如何告诉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日
我尝试使用以下代码将docker-compose.prod.yml
重命名为docker-compose.yml
,并放置在.ebextensions/docker-settings.config
中:
container_commands:
rename_docker_compose:
command: mv docker-compose.prod.yml docker-compose.yml
>eb deploy:
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
看起来it成功地进行了替换:
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。我cd
到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在线界面手动上传来重现Marcin的例子。当我这样做并检查源包时,它显示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
当我使用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部署命令的一个bug,涉及到它如何为Windows用户压缩文件。
docker-compose.yml
的文件时,它可以正常工作。当我将其重命名为docker-compose.prod.yml
时,我希望能够在适当的时间配置Elastic Beanstalk将此文件重命名为docker-compose.yml
。 - Jarad