This repository has been archived by the owner on Sep 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.yml
58 lines (53 loc) · 3.2 KB
/
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
52
53
54
55
56
57
58
---
version: 0.2
phases:
install:
commands:
- echo installing required packages for EKS setup...
- WORKAROUND="{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"date\":\"`date +'%s'`\"}}}}}"
- 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 -o aws-auth-cm.yaml https://amazon-eks.s3-us-west-2.amazonaws.com/cloudformation/2019-11-15/aws-auth-cm.yaml
- 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
- export KUBECONFIG=$HOME/.kube/config
runtime-versions:
docker: 18
nodejs: 10
pre_build:
commands:
- echo creating temporary credentials...
- 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')
- echo updating kubeconfig...
- aws eks --region $AWS_DEFAULT_REGION update-kubeconfig --name $EKS_CLUSTER_NAME
# - echo create namespace only run once...
# - kubectl create namespace $NAMESPACE
- echo getting deployments...
- kubectl describe deployments --namespace=$NAMESPACE
build:
commands:
- echo updating deployment...
- aws s3 cp $SERVICE_PATH .
- aws s3 cp $DEPLOY_PATH .
#- kubectl delete deployment.apps/middleware-deployment service/middleware-service --namespace=$NAMESPACE
#- kubectl set image deployment.apps/middleware-deployment middleware=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$REPO:$IMAGE_TAG --record --namespace=$NAMESPACE
post_build:
commands:
- echo exposing deployment to load balancer...
- kubectl apply -f deploy.yml --validate=false
- echo exposing deployment to load balancer...
- kubectl apply -f service.yml --validate=false
- kubectl get deployments --namespace=$NAMESPACE
- kubectl patch deployment.extensions/middleware-deployment --namespace=$NAMESPACE --patch $WORKAROUND
- echo retrieving pods in eks cluster...
- kubectl get pods --namespace=$NAMESPACE
- echo getting external ips from cluster...
- kubectl get services -o wide --namespace=$NAMESPACE
#uncomment BELOW to rollback to previous deployment version
#- echo rollback to previous deployment version...
#- kubectl rollout undo deployments/$APP_NAME