自托管 gitlab CI/CD 将注册表推送到 ECS 服务
self hosted gitlab CI/CD push registry to ECS service
我在 ubuntu 16.04 上使用自托管的 gitlab。我已成功创建 ECS 和服务。现在我想将我的微服务部署到 aws ecs。我不知道如何将我的私有注册表 docker 映像推送到 ecs。我有 gitlab-ci.yml 文件:
image: docker:latest
services:
- docker:dind
stages:
- build
- package
- deploy
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
DOCKER_DRIVER: overlay
before_script:
# - echo `pwd` # debug
# - echo "$CI_BUILD_NAME, $CI_BUILD_REF_NAME $CI_BUILD_STAGE" # debug
- export GRADLE_USER_HOME=`pwd`/.gradle
- export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
- chmod +x gradlew
cache:
paths:
- .gradle/wrapper
- .gradle/caches
build:
stage: build
image: openjdk:8-jdk
tags:
- tag
script:
- ./gradlew assemble
artifacts:
paths:
- build/libs/*.jar
expire_in: 1 week
only:
- master
docker-build:
stage: package
tags:
- tag
script:
- docker build -t registry.gitlab.example.com/root/abc:latest .
- docker login registry.gitlab.example.com -u gitlab-ci-token -p xyz
- docker push registry.gitlab.example.com/root/abc:latest
deploy:
tags:
- tag
script:
after_script:
- echo "End CI"
gitlab.rb 文件中的外部注册表 url 是:
registry.gitlab.example.com
但是如何在 ecs 部署中使用它?
我有 public 个 ubuntu 机器的 IP。
您可能可以选择将 ECR 与 ECS 一起使用。要推送到 AWS ECS,您需要一个 URL;看起来像: xxxxxxxxxxxx.dkr.ecr.your-region.amazonaws.com/url 。然后你可以在你的 gitlab-ci.yml:
中做类似下面的事情
variables:
REPOSITORY_URL: your_url
build:
stage: build
script:
- $(aws ecr get-login --no-include-email --region us-east-1)
- docker build -t $REPOSITORY_URL .
- docker push $REPOSITORY_URL
tags:
- docker
不要忘记在设置中设置这些环境变量 (AWS_ACCESS_KEY_ID & AWS_SECRET_ACCESS_KEY)。您可能还想在 before-script
中安装 aws-cli
另请检查 GitLab 13.3(2020 年 8 月)是否对您的情况有所帮助:
ECS task definition from local JSON
Today, GitLab’s ECS deployment template updates existing task definitions that are already defined in your attached AWS account. It’s also common to update your task-definition as part of your GitLab flow.
Now, you can update the JSON task definition in your local repository and push it knowing the task will get appropriately created in the AWS account, improving your standard development flow.
See Documentation and Issue.
此外,GitLab 13.6(2020 年 11 月)
Create job to stop ECS review Apps
We recently added support for AWS ECS so you can use it as a deployment target for Auto DevOps.
However, review apps for ECS targets weren’t automatically stopped.
To rectify this, the Deploy_ECS
template has been extended to automatically stop review apps as part of the Auto DevOps flow so that resources don’t go to waste.
This ensures a similar experience for Auto DevOps users deploying to ECS and those using Kubernetes, where things work automatically without the need to manually stop and keep track of review apps.
See Documentation and Issue.
我在 ubuntu 16.04 上使用自托管的 gitlab。我已成功创建 ECS 和服务。现在我想将我的微服务部署到 aws ecs。我不知道如何将我的私有注册表 docker 映像推送到 ecs。我有 gitlab-ci.yml 文件:
image: docker:latest
services:
- docker:dind
stages:
- build
- package
- deploy
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
DOCKER_DRIVER: overlay
before_script:
# - echo `pwd` # debug
# - echo "$CI_BUILD_NAME, $CI_BUILD_REF_NAME $CI_BUILD_STAGE" # debug
- export GRADLE_USER_HOME=`pwd`/.gradle
- export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
- chmod +x gradlew
cache:
paths:
- .gradle/wrapper
- .gradle/caches
build:
stage: build
image: openjdk:8-jdk
tags:
- tag
script:
- ./gradlew assemble
artifacts:
paths:
- build/libs/*.jar
expire_in: 1 week
only:
- master
docker-build:
stage: package
tags:
- tag
script:
- docker build -t registry.gitlab.example.com/root/abc:latest .
- docker login registry.gitlab.example.com -u gitlab-ci-token -p xyz
- docker push registry.gitlab.example.com/root/abc:latest
deploy:
tags:
- tag
script:
after_script:
- echo "End CI"
gitlab.rb 文件中的外部注册表 url 是:
registry.gitlab.example.com
但是如何在 ecs 部署中使用它? 我有 public 个 ubuntu 机器的 IP。
您可能可以选择将 ECR 与 ECS 一起使用。要推送到 AWS ECS,您需要一个 URL;看起来像: xxxxxxxxxxxx.dkr.ecr.your-region.amazonaws.com/url 。然后你可以在你的 gitlab-ci.yml:
中做类似下面的事情variables:
REPOSITORY_URL: your_url
build:
stage: build
script:
- $(aws ecr get-login --no-include-email --region us-east-1)
- docker build -t $REPOSITORY_URL .
- docker push $REPOSITORY_URL
tags:
- docker
不要忘记在设置中设置这些环境变量 (AWS_ACCESS_KEY_ID & AWS_SECRET_ACCESS_KEY)。您可能还想在 before-script
另请检查 GitLab 13.3(2020 年 8 月)是否对您的情况有所帮助:
ECS task definition from local JSON
Today, GitLab’s ECS deployment template updates existing task definitions that are already defined in your attached AWS account. It’s also common to update your task-definition as part of your GitLab flow.
Now, you can update the JSON task definition in your local repository and push it knowing the task will get appropriately created in the AWS account, improving your standard development flow.
See Documentation and Issue.
此外,GitLab 13.6(2020 年 11 月)
Create job to stop ECS review Apps
We recently added support for AWS ECS so you can use it as a deployment target for Auto DevOps.
However, review apps for ECS targets weren’t automatically stopped.To rectify this, the
Deploy_ECS
template has been extended to automatically stop review apps as part of the Auto DevOps flow so that resources don’t go to waste.
This ensures a similar experience for Auto DevOps users deploying to ECS and those using Kubernetes, where things work automatically without the need to manually stop and keep track of review apps.
See Documentation and Issue.