Project の setting -> CI/CD -> variableでAWSのcredentialを設定する
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION
.gitlab-ci.yml
stages: - dev - deploy # GitLab Container Repositoryにpush build-job: stage: dev image: docker:latest services: - docker:dind before_script: - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY script: - docker build --pull -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA . - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA # GitLab Container RepositoryのimageをECRにpush deploy-job: stage: deploy image: docker:latest services: - docker:dind before_script: - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $ECR_REPOSITORY_NAME:$CI_COMMIT_SHA - docker logout - apk add --update py-pip - pip install awscli - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY - aws configure set region $AWS_DEFAULT_REGION - aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin $ECR_REPOSITORY script: - docker push $ECR_REPOSITORY_NAME:$CI_COMMIT_SHA
なるほどー
中々面白い