Created
February 17, 2020 07:30
-
-
Save 1c7/b0b0c0e25521da8adf5d068fc210a3bd to your computer and use it in GitHub Desktop.
AWS Codebuild buildspec.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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