【发布时间】:2022-11-20 09:14:26
【问题描述】:
我正在尝试使用 githubaction 做 aws 管道并部署到 aws fargate。我可以创建我的 docker 镜像,但无法使用 github 操作推送到 ECR 存储库。
姓名:CI 上: 推: 分支机构:[开发] 拉请求: 分支机构:[开发] 工作: 建造: 运行:ubuntu-latest 脚步: # 在 $GITHUB_WORKSPACE 下签出你的仓库,这样你的工作就可以访问它 - 使用:actions/checkout@v2
# Runs a single command using the runners shell
- name: Lint code
run: echo "Linting repository!"
# Runs a set of commands using the runners shell
- name: Run unit tests
run: |
echo "Running unit tests"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: cmssdemo
IMAGE_TAG: latest
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ secrets.ECS_CONTAINER_DEFINITION }} \
--query taskDefinition > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ secrets.ECS_CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ secrets.ECS_SERVICE }}
cluster: ${{ secrets.ECS_CLUSTER }}
wait-for-service-stability: true
我的 githubaction 脚本
【问题讨论】:
标签: dockerfile github-actions aws-fargate cicd amazon-ecr