-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildspec.yml
34 lines (30 loc) · 1.72 KB
/
buildspec.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
version: 0.2
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- echo -e "$AWS_ACCESS_KEY_ID\n$AWS_SECRET_ACCESS_KEY\n$AWS_DEFAULT_REGION\n$AWS_DEFAULT_OUTPUT_FORMAT" | aws configure
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
- TAG="$(date +%Y-%m-%d.%H.%M.%S).$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8)"
- echo $TAG
- echo "Update Kube Config"
- aws eks update-kubeconfig --name $EKS_CLUSTER_NAME
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build -f aws.Dockerfile -t $IMAGE_REPO_NAME:$IMAGE_TAG -t $IMAGE_REPO_NAME:$TAG .
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
- docker tag $IMAGE_REPO_NAME:$TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$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/$IMAGE_REPO_NAME --all-tags
- echo "Apply changes to k8s"
- kubectl set image deployment/$EKS_DEPLOYMENT_NAME $EKS_CONTAINER_NAME=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$TAG
- echo "Completed applying changes to Kubernetes Objects"
- printf '[{"name":"'"$IMAGE_REPO_NAME"'","imageUri":"'"$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE"'"}]' > imagedefinitions.json
artifacts:
files:
- "imagedefinitions.json"