-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuildspec.yml
35 lines (35 loc) · 1.82 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
35
---
version: 0.2
phases:
install:
commands:
- curl -sS -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/linux/amd64/aws-iam-authenticator
- curl -sS -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/kubectl
- chmod +x ./kubectl ./aws-iam-authenticator
- export PATH=$PWD/:$PATH
- apt-get update && apt-get -y install jq python3-pip python3-dev && pip3 install --upgrade awscli
- apt-get install openjdk-11-jdk -y
pre_build:
commands:
- IMAGE_TAG=$IMAGE_TAG_PREFIX-$CODEBUILD_BUILD_NUMBER
- sed -i 's@CONTAINER_IMAGE@'"$REPOSITORY_URI:$IMAGE_TAG"'@' deployment.yml
- $(aws ecr get-login --no-include-email)
- export KUBECONFIG=$HOME/.kube/config
build:
commands:
- ./gradlew clean build
- docker build -t $IMAGE_TAG_PREFIX:$CODEBUILD_BUILD_NUMBER .
- docker tag $IMAGE_TAG_PREFIX:$CODEBUILD_BUILD_NUMBER $REPOSITORY_URI:$IMAGE_TAG
- docker push $REPOSITORY_URI:$IMAGE_TAG
post_build:
commands:
- CREDENTIALS=$(aws sts assume-role --role-arn $KUBECTL_ROLE_ARN --role-session-name codebuild-kubectl --duration-seconds 900)
- export AWS_ACCESS_KEY_ID="$(echo ${CREDENTIALS} | jq -r '.Credentials.AccessKeyId')"
- export AWS_SECRET_ACCESS_KEY="$(echo ${CREDENTIALS} | jq -r '.Credentials.SecretAccessKey')"
- export AWS_SESSION_TOKEN="$(echo ${CREDENTIALS} | jq -r '.Credentials.SessionToken')"
- export AWS_EXPIRATION=$(echo ${CREDENTIALS} | jq -r '.Credentials.Expiration')
- aws eks update-kubeconfig --name $EKS_NAME
- kubectl apply -f deployment.yml
- printf '[{"name":"cryto-currency-wallet-deployment","imageUri":"%s","buildNumber":"$CODEBUILD_BUILD_NUMBER"}]' $REPOSITORY_URI:$TAG > build.json
artifacts:
files: build.json