forked from doublej472/test-flask-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildspec-deploy.yaml
41 lines (41 loc) · 2.21 KB
/
buildspec-deploy.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
version: 0.2
phases:
install: # Install AWS cli, and kubectl.
commands:
- echo Set parameter
- echo $CODEBUILD_RESOLVED_SOURCE_VERSION
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_HASH:=latest}
- EKS_NAME=my-cluster
- DEPLOYMENT_NAME=simple-webapp
- REPOSITORY_URI=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${IMAGE_REPO_NAME}
- echo Logging to AWS ECR…
- echo Installing necessary library...
- apt-get update
- apt install -y awscli git python3
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com
# - curl -o aws-iam-authenticator https://amazon-eks.s3.us-west-2.amazonaws.com/1.21.2/2021-07-05/bin/linux/amd64/aws-iam-authenticator
- curl -Lo aws-iam-authenticator https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v0.5.9/aws-iam-authenticator_0.5.9_linux_amd64
- chmod +x ./aws-iam-authenticator
- mkdir -p ~/bin && cp ./aws-iam-authenticator ~/bin/aws-iam-authenticator && export PATH=~/bin:$PATH
# - curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
- curl -LO "https://dl.k8s.io/release/v1.22.15/bin/linux/amd64/kubectl"
- chmod +x kubectl
- mv ./kubectl /usr/local/bin/kubectl
pre_build: # Add kubeconfig to access to EKS cluster
commands:
- echo Update kubeconfig…
- aws eks update-kubeconfig --name ${EKS_NAME} --region ${AWS_DEFAULT_REGION}
build: # Build Docker image and tag it with the commit sha
commands:
- echo Building docker image…
- docker build -t $REPOSITORY_URI:latest --file Dockerfile .
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
post_build: # Push the Docker image to the ECR and deploy it to the cluster
commands:
- echo Pushing ECR…
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG
- echo Rollout new version
- kubectl set image deployment.apps/${DEPLOYMENT_NAME} ${DEPLOYMENT_NAME}=${REPOSITORY_URI}:${IMAGE_TAG}
- echo GREAT SUCCESS!!!