当来自 gitlab ci 的 运行 时,为什么 aws cli 正在执行旧的 docker 图像?
Why aws cli is executing old docker image when run from gitlab ci?
我正在将我的 docker 图像推送到我的私人 docker 中心帐户,然后我 运行 aws cli 从 docker 图像启动一个实例。但是,aws cli 始终执行图像的先前版本,而不是最新版本。因此,为了执行最新版本,我有时需要手动重新部署甚至重启实例。我检查了 docker 集线器图像在 docker 集线器中更新后 45 秒后 aws cli 是否启动。然后作为测试,我在 运行 aws cli.
之前在部署阶段的 gitlab yaml 文件中添加了 sleep 300
seconds before_script
Elastic beanstalk 中似乎存在某种缓存,无法正确更新环境。
有没有人 运行 遇到过这样的问题?
这是我子项目中的 gitlab yaml 配置:
.build-docker-image:
image: docker:18
stage: build
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
services:
- docker:dind
script:
- echo branch $CI_COMMIT_REF_NAME tag $CI_COMMIT_TAG
- docker build .
- docker push "$CI_REGISTRY_IMAGE"
except:
variables:
- $SKIP_BUILD == "1"
docker-build-staging:
extends: .build-docker-image
environment:
name: subprojectname
only:
variables:
- $CI_COMMIT_REF_NAME == "staging"
variables:
CI_REGISTRY_IMAGE: myproject/subproject:staging
amazon_beanstalk_staging:
extends: .amazon_beanstalk
environment:
name: subprojectname
url: 'https://subprojectname.com'
variables:
AWS_VERSION: $STAGING_AWS_VERSION_BETA
AWS_ENV_NAME: $STAGING_AWS_ENV_BETA
only:
variables:
- $CI_COMMIT_REF_NAME == "staging"
这是包含所有子项目的根文件夹中的 gitlab yaml:
image: node
stages:
- build
- deploy
# sleep 300 seconds in order to prevent aws running old docker image
.amazon_beanstalk:
stage: deploy
image: garland/aws-cli-docker:latest
before_script:
- sleep 300
script:
- sh -c "aws configure set region '$AWS_REGION' && aws elasticbeanstalk update-environment --environment-name '$AWS_ENV_NAME' --version-label '$AWS_VERSION'"
include:
- local: 'pathToMySubproject/.gitlab-ci.yml'
(在@hitchhiker 发表评论后更新):要获得清晰的故障排除输出,请确保为您的环境启用了 CloudWatch Logs,并查看 ecs-agent.log
的日志,您可以看到代理执行的 PULL 步骤.当环境更新或环境重新启动时,我能够看到非常具体的 PULL 步骤。
得知您仍有问题,我们深感遗憾。感谢您确认您是 运行 v2。我确实尝试猜测您的任务设置并重现它。在 运行 update-environment
后,系统自动对我的更新图像执行 PULL,即使我使用了完全相同的版本标签。此外,在重新启动实例后(从 Elastic Beanstalk 控制台),将拉取一个新图像。
原回复:
如果您使用的是单一容器方法:
在您的 Dockerrun.aws.json
文件中,请确认您的 "Update": "true" 在您的 "Image" 部分中。这会指示 Elastic Beanstalk 始终检查您的 Docker Hub 存储库是否有新图像。如果此设置为 "false",则 Elastic Beanstalk 服务将优先使用之前下载的图像。
When you specify an image in the Dockerrun.aws.json
file, each
instance in your Elastic Beanstalk environment will run docker pull
on
that image and run it. Optionally, include the Update key. The default
value is true
and instructs Elastic Beanstalk to check the repository,
pull any updates to the image, and overwrite any cached images.
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "janedoe/image",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "1234"
}
],
"Volumes": [
{
"HostDirectory": "/var/app/mydb",
"ContainerDirectory": "/etc/mysql"
}
],
"Logging": "/var/log/nginx",
"Entrypoint": "/app/bin/myapp",
"Command": "--argument"
}
另请注意 ECS container definition documentation,如果您有旧任务 运行,它们将不会自动更新:
When a new task starts, the Amazon ECS container agent pulls the
latest version of the specified image and tag for the container to
use. However, subsequent updates to a repository image are not
propagated to already running tasks.
我正在将我的 docker 图像推送到我的私人 docker 中心帐户,然后我 运行 aws cli 从 docker 图像启动一个实例。但是,aws cli 始终执行图像的先前版本,而不是最新版本。因此,为了执行最新版本,我有时需要手动重新部署甚至重启实例。我检查了 docker 集线器图像在 docker 集线器中更新后 45 秒后 aws cli 是否启动。然后作为测试,我在 运行 aws cli.
之前在部署阶段的 gitlab yaml 文件中添加了sleep 300
seconds before_script
Elastic beanstalk 中似乎存在某种缓存,无法正确更新环境。 有没有人 运行 遇到过这样的问题?
这是我子项目中的 gitlab yaml 配置:
.build-docker-image:
image: docker:18
stage: build
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
services:
- docker:dind
script:
- echo branch $CI_COMMIT_REF_NAME tag $CI_COMMIT_TAG
- docker build .
- docker push "$CI_REGISTRY_IMAGE"
except:
variables:
- $SKIP_BUILD == "1"
docker-build-staging:
extends: .build-docker-image
environment:
name: subprojectname
only:
variables:
- $CI_COMMIT_REF_NAME == "staging"
variables:
CI_REGISTRY_IMAGE: myproject/subproject:staging
amazon_beanstalk_staging:
extends: .amazon_beanstalk
environment:
name: subprojectname
url: 'https://subprojectname.com'
variables:
AWS_VERSION: $STAGING_AWS_VERSION_BETA
AWS_ENV_NAME: $STAGING_AWS_ENV_BETA
only:
variables:
- $CI_COMMIT_REF_NAME == "staging"
这是包含所有子项目的根文件夹中的 gitlab yaml:
image: node
stages:
- build
- deploy
# sleep 300 seconds in order to prevent aws running old docker image
.amazon_beanstalk:
stage: deploy
image: garland/aws-cli-docker:latest
before_script:
- sleep 300
script:
- sh -c "aws configure set region '$AWS_REGION' && aws elasticbeanstalk update-environment --environment-name '$AWS_ENV_NAME' --version-label '$AWS_VERSION'"
include:
- local: 'pathToMySubproject/.gitlab-ci.yml'
(在@hitchhiker 发表评论后更新):要获得清晰的故障排除输出,请确保为您的环境启用了 CloudWatch Logs,并查看 ecs-agent.log
的日志,您可以看到代理执行的 PULL 步骤.当环境更新或环境重新启动时,我能够看到非常具体的 PULL 步骤。
得知您仍有问题,我们深感遗憾。感谢您确认您是 运行 v2。我确实尝试猜测您的任务设置并重现它。在 运行 update-environment
后,系统自动对我的更新图像执行 PULL,即使我使用了完全相同的版本标签。此外,在重新启动实例后(从 Elastic Beanstalk 控制台),将拉取一个新图像。
原回复:
如果您使用的是单一容器方法:
在您的 Dockerrun.aws.json
文件中,请确认您的 "Update": "true" 在您的 "Image" 部分中。这会指示 Elastic Beanstalk 始终检查您的 Docker Hub 存储库是否有新图像。如果此设置为 "false",则 Elastic Beanstalk 服务将优先使用之前下载的图像。
When you specify an image in the
Dockerrun.aws.json
file, each instance in your Elastic Beanstalk environment will rundocker pull
on that image and run it. Optionally, include the Update key. The default value istrue
and instructs Elastic Beanstalk to check the repository, pull any updates to the image, and overwrite any cached images.
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "janedoe/image",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "1234"
}
],
"Volumes": [
{
"HostDirectory": "/var/app/mydb",
"ContainerDirectory": "/etc/mysql"
}
],
"Logging": "/var/log/nginx",
"Entrypoint": "/app/bin/myapp",
"Command": "--argument"
}
另请注意 ECS container definition documentation,如果您有旧任务 运行,它们将不会自动更新:
When a new task starts, the Amazon ECS container agent pulls the latest version of the specified image and tag for the container to use. However, subsequent updates to a repository image are not propagated to already running tasks.