Last active
April 10, 2019 14:47
-
-
Save pereira-a/bc7b40f5f31f183856fcd06af08eed84 to your computer and use it in GitHub Desktop.
Gitlab CICD stages to build a project, upload docker image to Google Container Registry and update the container of a pre configured Kubernetes Engine Project
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
services: | |
- docker:dind | |
stages: | |
- build | |
- package | |
- deploy | |
build: | |
stage: build | |
image: gradle:slim | |
script: | |
- ./gradlew build | |
artifacts: | |
paths: | |
- build/libs/*.jar | |
expire_in: 1 week | |
only: | |
- master | |
docker: | |
stage: package | |
image: docker:latest | |
variables: | |
DOCKER_IMAGE_TAG: '<image url>' | |
script: | |
# Build image | |
- docker build --cache-from "${DOCKER_IMAGE_TAG}" -t "${DOCKER_IMAGE_TAG}" . | |
# Log in to GCR | |
- echo "$SERVICE_ACCOUNT_KEY" | docker login -u _json_key --password-stdin https://eu.gcr.io/cn-2019 | |
# Push the image | |
- docker push ${DOCKER_IMAGE_TAG} | |
only: | |
- master | |
deploy: | |
stage: deploy | |
image: google/cloud-sdk:latest | |
variables: | |
PROJECT: '<project>' | |
DEPLOYMENT_PROJ: '<deployment project>' | |
script: | |
- echo "$SERVICE_ACCOUNT_KEY" > key.json | |
- gcloud auth activate-service-account --key-file=key.json | |
- gcloud config set project ${PROJECT} | |
- gcloud config set container/cluster ${DEPLOYMENT_PROJ} | |
- gcloud config set compute/zone europe-west1-b | |
- gcloud container clusters get-credentials ${DEPLOYMENT_PROJ} | |
- kubectl scale --replicas=0 deployment ${DEPLOYMENT_PROJ} | |
- kubectl scale --replicas=1 deployment ${DEPLOYMENT_PROJ} | |
only: | |
- master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment