1+ version : 0.2
2+ phases :
3+ install :
4+ commands :
5+ - echo "Install Phase - if you need additional package, add it in this stage"
6+ pre_build :
7+ commands :
8+ # This Docker Image tag will have date, time and Codecommit version
9+ - TAG="$(date +%Y-%m-%d.%H.%M.%S).$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8)"
10+ # Updating Docker Image tag in your Kubernetes Deployment Manifest
11+ - echo "Update Image tag in kubernetes manifest"
12+ - sed -i 's@CONTAINER_IMAGE@'"$REPOSITORY_URL:$TAG"'@' manifests/deployment.yaml
13+ # Check AWS CLI Version
14+ - echo "Checking AWS CLI Version..."
15+ - aws --version
16+ # Login to ECR Registry
17+ - echo "Login in to Amazon ECR Registry"
18+ - $(aws ecr get-login --no-include-email)
19+ # Update Kube config Home Directory
20+ - export KUBECONFIG=$HOME/.kube/config
21+ build :
22+ commands :
23+ # Building Docker Image
24+ - echo "Docker build started on `date`"
25+ - echo "Building the Docker image..."
26+ - docker build --tag $REPOSITORY_URL:$TAG .
27+ post_build :
28+ commands :
29+ # Push Docker Image to ECR Repository
30+ - echo "Docker build completed on `date`"
31+ - echo "Pushing the Docker image to ECR Repository"
32+ - docker push $REPOSITORY_URL:$TAG
33+ - echo "Docker Push to ECR Repository Completed - $REPOSITORY_URL:$TAG"
34+ # Get AWS Credential using STS Assume Role for kubectl
35+ - echo "Setting Environment Variables related to AWS CLI for Kube Config Setup"
36+ - CREDENTIALS=$(aws sts assume-role --role-arn $EKS_ROLE_ARN --role-session-name eks-codebuild --duration-seconds 900)
37+ - export AWS_ACCESS_KEY_ID="$(echo ${CREDENTIALS} | jq -r '.Credentials.AccessKeyId')"
38+ - export AWS_SECRET_ACCESS_KEY="$(echo ${CREDENTIALS} | jq -r '.Credentials.SecretAccessKey')"
39+ - export AWS_SESSION_TOKEN="$(echo ${CREDENTIALS} | jq -r '.Credentials.SessionToken')"
40+ - export AWS_EXPIRATION=$(echo ${CREDENTIALS} | jq -r '.Credentials.Expiration')
41+ # Updating kubectl with your EKS Cluster
42+ - echo "Update Kube Config configuration"
43+ - aws eks update-kubeconfig --name $EKS_CLUSTERNAME
44+ # Show time, applying manifests changes using kubectl
45+ - echo "Apply changes to kube manifests"
46+ - kubectl apply -f manifests/
47+ - echo "All done!!!! Kubernetes changes applied"
48+ # Create Artifacts which we can use if we want to continue our pipeline for other stages
49+ - printf '[{"name":"deployment.yaml","imageUri":"%s"}]' $REPOSITORY_URL:$TAG > build.json
50+ artifacts :
51+ files :
52+ - build.json
53+ - manifests/*
0 commit comments