version: 0.2 phases: install: # Install AWS cli, kubectl and Helm3 commands: - apt-get update - apt-get install -y git python3 python3-pip - pip install awscli - curl -o aws-iam-authenticator https://s3.us-west-2.amazonaws.com/amazon-eks/1.21.2/2021-07-05/bin/linux/amd64/aws-iam-authenticator - chmod +x ./aws-iam-authenticator - mkdir -p $HOME/bin && cp ./aws-iam-authenticator $HOME/bin/aws-iam-authenticator && export PATH=$PATH:$HOME/bin - curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.21.0/bin/linux/amd64/kubectl - chmod +x kubectl - mv ./kubectl /usr/local/bin/kubectl - curl -sSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash - helm repo add stable https://charts.helm.sh/stable && helm repo update pre_build: # Check helm version and Add kubeconfig to access to EKS cluster and check readiness of the cluster commands: - "helm version" - "mkdir ~/.kube/" - "aws eks --region $AWS_DEFAULT_REGION update-kubeconfig --name $EKS_CLUSTER_NAME --role-arn $EKS_CODEBUILD_ROLE_ARN" - "chmod 0600 ~/.kube/config" - "aws sts get-caller-identity" build: # Deploy app via Helm commands: - "helm upgrade -i $EKS_CODEBUILD_APP_NAME-$ENV helm_charts/$EKS_CODEBUILD_APP_NAME -f helm_charts/$EKS_CODEBUILD_APP_NAME/values.$ENV.yaml --set image.repository=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME --set image.tag=$CODEBUILD_RESOLVED_SOURCE_VERSION" post_build: # Display the endpoint of the application commands: - bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi" - sleep 60 - JAVA_APP_ENDPOINT=`kubectl get svc $EKS_CODEBUILD_APP_NAME-$ENV -o jsonpath="{.status.loadBalancer.ingress[*].hostname}"` - echo -e "\nThe Java application can be accessed nw via http://$JAVA_APP_ENDPOINT/hello"