Skip to content

Instantly share code, notes, and snippets.

@1c7
Created February 17, 2020 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1c7/b0b0c0e25521da8adf5d068fc210a3bd to your computer and use it in GitHub Desktop.
Save 1c7/b0b0c0e25521da8adf5d068fc210a3bd to your computer and use it in GitHub Desktop.
AWS Codebuild buildspec.yml
version: 0.2
# Docker caching:
# https://github.com/aws/aws-codebuild-docker-images/issues/26#issuecomment-370177343
phases:
install:
runtime-versions:
docker: 18
pre_build:
commands:
- docker version
- echo Logging in to Amazon ECR...
- $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
- docker pull $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com.cn/$IMAGE_REPO_NAME:$IMAGE_TAG || true
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
# 我们这里让 Docker 使用阿里云的镜像服务
# 开发者需要开通阿里开发者帐户,再使用阿里的加速服务
# 登录后阿里开发者帐户后,在 https://cr.console.aliyun.com/undefined/instances/mirrors 查看您的专属加速器地址
- mkdir -p /etc/docker
- |
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://6ctjkwa0.mirror.aliyuncs.com"]
}
EOF
- docker build --cache-from $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com.cn/$IMAGE_REPO_NAME:$IMAGE_TAG -t $IMAGE_REPO_NAME:$IMAGE_TAG --build-arg APP_ENV=production .
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com.cn/$IMAGE_REPO_NAME:$IMAGE_TAG
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com.cn/$IMAGE_REPO_NAME:$IMAGE_TAG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment