-
Notifications
You must be signed in to change notification settings - Fork 5
/
buildspec.yaml
42 lines (37 loc) · 1.76 KB
/
buildspec.yaml
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
version: 0.2
phases:
install:
commands:
- echo Installing app dependencies...
- curl -LO https://dl.k8s.io/release/v1.27.2/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
- echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
- source ~/.bashrc
- echo 'Check kubectl version'
- kubectl version --short --client
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin 069279771141.dkr.ecr.us-east-2.amazonaws.com
- IMAGE_REPO_NAME=069279771141.dkr.ecr.us-east-2.amazonaws.com/nodejs-webapp
- IMAGE_TAG=v1.0.0.RELEASE
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build --tag $IMAGE_REPO_NAME:$IMAGE_TAG .
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $IMAGE_REPO_NAME:$IMAGE_TAG
- aws eks update-kubeconfig --name k8s-boy --region us-east-2
- echo Push the latest image to cluster
# Get AWS Credential using STS Assume Role for kubectl
- echo "Setting Environment Variables related to AWS CLI for Kube Config Setup"
- 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')
- kubectl apply -f deployment.yml