-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildspec.yml
52 lines (44 loc) · 2.05 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
version: 0.2
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR
- aws --version
- $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
- 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
- echo Set environment variables
- REPOSITORY_URI=012345678912.dkr.ecr.us-west-2.amazonaws.com/nodejswebapp:latest
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=build-$(echo $CODEBUILD_BUILD_ID | awk -F":" '{print $2}')
- EKS_CLUSTER_NAME=nodejs-eks
- AWS_ACCESS_KEY_ID=
- AWS_SECRET_ACCESS_KEY=
build:
commands:
- $(aws ecr get-login --no-include-email)
- export KUBECONFIG=$HOME/.kube/config
- echo Build started on `date`
- echo Building the Docker image...
- docker build -t $REPOSITORY_URI:latest .
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker images...
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG
- echo Writing image deploy file...
- printf '[{"name":"nodeapp","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > deploy.json
- cat deploy.json
- echo Change container image in deployment.yaml file
- sed -i 's@CONTAINER_IMAGE@'"$REPOSITORY_URI:$IMAGE_TAG"'@' deployment.yaml
- curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- export PATH=$PWD/:$PATH
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
- aws eks update-kubeconfig --name $EKS_CLUSTER_NAME
- kubectl apply -f deployment.yaml