-
Notifications
You must be signed in to change notification settings - Fork 7
/
buildspec.deploy.yml
51 lines (42 loc) · 1.53 KB
/
buildspec.deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
version: 0.2
env:
variables:
AWS_ACCOUNT_ID:
AWS_REGION:
CLUSTER_NAME:
IMAGE_NAME:
IMAGE_TAG:
SERVICE_NAME:
phases:
install:
runtime-versions:
docker: 18
pre_build:
commands:
# Short commit hash
- GIT_COMMIT_HASH=$(git rev-parse --short=7 --verify HEAD)
# Container repository location
- REPO_URL=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_NAME
# Use IMAGE_TAG passed in from the build, fallback to 'latest' if blank.
- TAG=${IMAGE_TAG:-latest}
# Log in to ECR
- $(aws ecr get-login --no-include-email --region $AWS_REGION)
# Log into docker hub
- docker login -u $DHUSER -p $DHPASSWD
# Pull this image for the build to cache from.
- docker pull $REPO_URL:$TAG || true
build:
commands:
- echo Cache from $REPO_URL:$TAG
- docker build --build-arg app_version=$GIT_COMMIT_HASH --cache-from $REPO_URL:$TAG -t $IMAGE_NAME:$GIT_COMMIT_HASH -t $IMAGE_NAME:$TAG .
- docker tag $IMAGE_NAME:$TAG $REPO_URL:$TAG
- docker tag $IMAGE_NAME:$TAG $REPO_URL:$GIT_COMMIT_HASH
post_build:
commands:
- docker push $REPO_URL:$TAG
- docker push $REPO_URL:$GIT_COMMIT_HASH
# Update the service.
# Discard the default output (json full description of the service.)
- aws ecs update-service --cluster $CLUSTER_NAME --service $SERVICE_NAME --force-new-deployment 1>/dev/null
- echo Build completed.
- echo Service $SERVICE_NAME in cluster $CLUSTER_NAME is now updating...