Created
June 17, 2020 07:02
-
-
Save velotiotech/4ec6859ac9de7cd5f27e376a503f52a9 to your computer and use it in GitHub Desktop.
CircleCI configuraton for helloapp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 2 | |
jobs: | |
build&pushImage: | |
working_directory: /go/src/hello-app | |
docker: | |
- image: circleci/golang:1.10 | |
steps: | |
- checkout | |
- run: | |
name: build the binary | |
command: go build -o hello-app | |
- setup_remote_docker: | |
docker_layer_caching: true | |
- run: | |
name: Set the tag for the image, we will concatenate the app verson and circle build number with a `-` char in between | |
command: echo 'export TAG=$(cat VERSION)-$CIRCLE_BUILD_NUM' >> $BASH_ENV | |
- run: | |
name: Build the docker image | |
command: docker build . -t ${CIRCLE_PROJECT_REPONAME}:$TAG | |
- run: | |
name: Install AWS cli | |
command: export TZ=Europe/Minsk && sudo ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > sudo /etc/timezone && sudo apt-get update && sudo apt-get install -y awscli | |
- run: | |
name: Login to ECR | |
command: $(aws ecr get-login --region $AWS_REGION | sed -e 's/-e none//g') | |
- run: | |
name: Tag the image with ECR repo name | |
command: docker tag ${CIRCLE_PROJECT_REPONAME}:$TAG ${HELLOAPP_ECR_REPO}:$TAG | |
- run: | |
name: Push the image the ECR repo | |
command: docker push ${HELLOAPP_ECR_REPO}:$TAG | |
deploy: | |
docker: | |
- image: circleci/golang:1.10 | |
steps: | |
- attach_workspace: | |
at: /tmp/workspace | |
- checkout | |
- run: | |
name: Install AWS cli | |
command: export TZ=Europe/Minsk && sudo ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > sudo /etc/timezone && sudo apt-get update && sudo apt-get install -y awscli | |
- run: | |
name: Set the tag for the image, we will concatenate the app verson and circle build number with a `-` char in between | |
command: echo 'export TAG=$(cat VERSION)-$CIRCLE_PREVIOUS_BUILD_NUM' >> $BASH_ENV | |
- run: | |
name: Install and confgure kubectl | |
command: sudo curl -L https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl && sudo chmod +x /usr/local/bin/kubectl | |
- run: | |
name: Install and confgure kubectl aws-iam-authenticator | |
command: curl -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 && sudo chmod +x ./aws-iam-authenticator && sudo cp ./aws-iam-authenticator /bin/aws-iam-authenticator | |
- run: | |
name: Install latest awscli version | |
command: sudo apt install unzip && curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip" && unzip awscli-bundle.zip &&./awscli-bundle/install -b ~/bin/aws | |
- run: | |
name: Get the kubeconfig file | |
command: export KUBECONFIG=$HOME/.kube/kubeconfig && /home/circleci/bin/aws eks --region $AWS_REGION update-kubeconfig --name $EKS_CLUSTER_NAME | |
- run: | |
name: Install and configuire helm | |
command: sudo curl -L https://storage.googleapis.com/kubernetes-helm/helm-v2.11.0-linux-amd64.tar.gz | tar xz && sudo mv linux-amd64/helm /bin/helm && sudo rm -rf linux-amd64 | |
- run: | |
name: Initialize helm | |
command: helm init --client-only --kubeconfig=$HOME/.kube/kubeconfig | |
- run: | |
name: Install tiller plugin | |
command: helm plugin install https://github.com/rimusz/helm-tiller --kubeconfig=$HOME/.kube/kubeconfig | |
- run: | |
name: Release helloapp using helm chart | |
command: bash scripts/release-helloapp.sh $TAG | |
workflows: | |
version: 2 | |
primary: | |
jobs: | |
- build&pushImage | |
- deploy: | |
requires: | |
- build&pushImage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment