-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuildspec.yml
More file actions
41 lines (40 loc) · 2.1 KB
/
buildspec.yml
File metadata and controls
41 lines (40 loc) · 2.1 KB
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
---
version: 0.2
env:
secrets-manager:
secret_docker_username: docker-credentials:DOCKERHUB_USERNAME
secret_docker_password: docker-credentials:DOCKERHUB_PASSWORD
phases:
install:
commands:
- curl -sS -o aws-iam-authenticator https://s3.us-west-2.amazonaws.com/amazon-eks/1.21.2/2021-07-05/bin/linux/amd64/aws-iam-authenticator
- curl -sS -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.21.2/2021-07-05/bin/linux/amd64/kubectl
- chmod +x ./kubectl ./aws-iam-authenticator
- export PATH=$PWD/:$PATH
- apt-get update && apt-get -y install nodejs nodejs-dev node-gyp libssl1.0-dev python3-pip python3-dev && pip3 install --upgrade awscli
- apt-get update && apt-get -y install npm
pre_build:
commands:
- echo logging in docker hub
- echo $secret_docker_password | docker login --username $secret_docker_username --password-stdin
- TAG="$REPOSITORY_NAME.$REPOSITORY_BRANCH.$ENVIRONMENT_NAME.$(date +%Y-%m-%d.%H.%M.%S).$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8)"
- $(aws ecr get-login --no-include-email)
- export KUBECONFIG=$HOME/.kube/config
build:
commands:
- npm install
- yarn build
- docker build --tag $REPOSITORY_URI:$TAG .
post_build:
commands:
- docker push $REPOSITORY_URI:$TAG
- CREDENTIALS=$(aws sts assume-role --role-arn $EKS_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_CLUSTER_NAME
- kubectl set image deployment/guestbook-ui guestbook-ui=$REPOSITORY_URI:$TAG -n vmc-demo --record=true
- printf '[{"name":"guestbook-ui","imageUri":"%s"}]' $REPOSITORY_URI:$TAG > build.json
artifacts:
files: build.json