Skip to content

Instantly share code, notes, and snippets.

@gtors
Forked from aviadlevy/.gitlab-ci.yml
Created July 16, 2021 10:47
Show Gist options
  • Save gtors/34c1579b3e0ed9b179cad413174bc16e to your computer and use it in GitHub Desktop.
Save gtors/34c1579b3e0ed9b179cad413174bc16e to your computer and use it in GitHub Desktop.
.gitlab-ci.yml with versioning and changelog
image: docker:latest
services:
- docker:dind
stages:
- build
- integration
- dev-release
- prod-release
# Cache downloaded dependencies and plugins between builds.
cache:
paths:
- .m2/repository
key: "$CI_JOB_NAME"
variables:
DOCKER_DRIVER: overlay
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
CONTAINER_RELEASE_IMAGE_LATEST: $CI_REGISTRY_IMAGE:latest
DEV_KUBECTL_CONFIG: $k8s_deploy_config_kube1
EU_PROD_KUBECTL_CONFIG: $k8s_deploy_config_eu_west_1_kube2
US_PROD_KUBECTL_CONFIG: $k8s_deploy_config_us_east_1_kube1
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
KUBE_CONFIG_PATH: "/root/.kube/config"
IMAGE_NAME: *******
maven-build:
image: snirnx/docker-maven:3.5.4
stage: build
script:
- mvn clean install
- docker build -t $IMAGE_NAME docker/
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker tag $IMAGE_NAME $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA
- docker tag $IMAGE_NAME $CI_REGISTRY_IMAGE/$IMAGE_NAME:latest
- docker push $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA
- docker push $CI_REGISTRY_IMAGE/$IMAGE_NAME:latest
## In CI pipeline, set Total.*?([0-9]{1,3})% for test coverage
- cat target/site/jacoco/index.html
tags:
- gitlab-docker
integration test:
image: snirnx/docker-maven:3.5.4
stage: integration
script:
- git clone https://gitlab-ci-token:$CI_JOB_TOKEN@**********************.git
- cd *************/
- bash ci_scripts/run_tests.sh
tags:
- integration-tests
artifacts:
name: "CI_COMMIT_SHA-results"
when: always
expire_in: 4 days
paths:
- integration-test/target/site/
- integration-test/log/
changelog:
image: golang:latest
stage: dev-release
before_script:
- git remote set-url origin https://${CI_PUSH_USER}:${CI_PUSH_TOKEN}@${GITLAB_HOST}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}.git
- git config --global user.name "${CI_PUSH_USER}"
- git config --global user.email "${CI_PUSH_USER}@${GITLAB_HOST}"
- git checkout master
- git fetch --all
- git reset --hard origin/master
script:
- go get -u github.com/git-chglog/git-chglog/cmd/git-chglog
- git-chglog -o CHANGELOG.md
- sed -i -e 's/\(TCA-[0-9]\+\)/[\1](https:\/\/jira.*******.com\/browse\/\1)/g' CHANGELOG.md
- git add CHANGELOG.md
- git commit -m 'edit CHANGELOG.md [skip ci]' || true
- git push origin master || true
tags:
- gitlab-docker
only:
- master
- tags
deploy to dev:
image: snirnx/kubectl:v1.8.6
stage: dev-release
script:
- echo "$DEV_KUBECTL_CONFIG" | base64 -d > $KUBE_CONFIG_PATH
- sed -i s/latest/$CI_COMMIT_SHA/g k8s/dev/deployment.yaml
- kubectl apply -f k8s/dev/deployment.yaml
- kubectl -n dev get deploy
- kubectl -n dev get pods
tags:
- gitlab-docker
environment:
name: staging
only:
- master
version:
image: snirnx/docker-maven:3.5.4
stage: prod-release
before_script:
- git config --global user.name "${CI_PUSH_USER}"
- git config --global user.email "${CI_PUSH_USER}@$${GITLAB_HOST}"
script:
- pip install semver
- chmod 777 ci/gen-semver.py
- ci/gen-semver.py > version
artifacts:
paths:
- version
only:
- master
when: manual
deploy to prod us:
image: snirnx/kubectl:v1.8.6
stage: prod-release
script:
- echo "$US_PROD_KUBECTL_CONFIG" | base64 -d > $KUBE_CONFIG_PATH
- sed -i s/latest/$CI_COMMIT_SHA/g k8s/prod/deployment.yaml
- kubectl apply -f k8s/prod/deployment.yaml
- kubectl -n prod get deploy
- kubectl -n prod get pods
tags:
- gitlab-docker
environment:
name: production
only:
- master
when: manual
deploy to prod eu:
image: snirnx/kubectl:v1.8.6
stage: prod-release
script:
- echo "$EU_PROD_KUBECTL_CONFIG" | base64 -d > $KUBE_CONFIG_PATH
- sed -i s/latest/$CI_COMMIT_SHA/g k8s/prod/deployment.yaml
- kubectl apply -f k8s/prod/deployment.yaml
- kubectl -n prod get deploy
- kubectl -n prod get pods
tags:
- gitlab-docker
environment:
name: production
only:
- master
when: manual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment