-
-
Save vmptk/c27d340c8fd649da1ce9140897218906 to your computer and use it in GitHub Desktop.
Gitlab CI with Nomad
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
# Disable the Gradle daemon for Continuous Integration servers as correctness | |
# is usually a priority over speed in CI environments. Using a fresh | |
# runtime for each build is more reliable since the runtime is completely | |
# isolated from any previous builds. | |
variables: | |
GRADLE_OPTS: "-Dorg.gradle.daemon=false" | |
DOCKER_TLS_CERTDIR: "" | |
before_script: | |
- export GRADLE_USER_HOME=`pwd`/.gradle | |
stages: | |
- build | |
- test | |
- package | |
- plan | |
- deploy | |
build: | |
image: gradle:5.2.1 | |
stage: build | |
script: gradle --build-cache clean assemble shadowJar | |
tags: | |
- java | |
cache: | |
key: "$CI_COMMIT_REF_NAME" | |
untracked: true | |
paths: | |
- .gradle | |
artifacts: | |
paths: | |
- build/libs/*.jar | |
expire_in: 1 hrs | |
test: | |
image: gradle:5.2.1 | |
stage: test | |
script: gradle check | |
needs: | |
- build | |
tags: | |
- java | |
cache: | |
key: "$CI_COMMIT_REF_NAME" | |
policy: pull | |
paths: | |
- .gradle | |
artifacts: | |
reports: | |
junit: | |
- ./build/test-results/test/**/TEST-*.xml | |
- ./build/test-results/test/TEST-*.xml | |
expire_in: 1 weeks | |
docker-build: | |
image: docker:19.03.1 | |
needs: | |
- build | |
tags: | |
- server | |
services: | |
- docker:19.03.1-dind | |
stage: package | |
script: | |
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin | |
- docker pull $CI_REGISTRY_IMAGE:latest || true | |
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA --tag $CI_REGISTRY_IMAGE:latest . | |
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA | |
- docker push $CI_REGISTRY_IMAGE:latest | |
# Only run on new tag | |
- if [ "x$CI_COMMIT_TAG" != "x" ]; then docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG; fi | |
- if [ "x$CI_COMMIT_TAG" != "x" ]; then docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG; fi | |
plan new version: | |
image: saboteurkid/nomad-levant:0.10.2-0.2.9 | |
variables: | |
DOCKER_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG | |
tags: | |
- internal | |
- production | |
stage: plan | |
needs: | |
- docker-build | |
script: | |
- levant render -out=deployment/job.nomad deployment/job.nomadtpl | |
- nomad plan deployment/job.nomad || if [ $? -eq 1 ]; then echo "OK"; fi | |
artifacts: | |
paths: | |
- deployment/*.nomad | |
expire_in: 1 hours | |
rules: | |
- if: $CI_COMMIT_TAG | |
Manual deploy: | |
image: saboteurkid/nomad-levant:0.10.2-0.2.9 | |
tags: | |
- internal | |
- production | |
needs: | |
- docker-build | |
stage: deploy | |
script: | |
- if [ "x$DOCKER_IMAGE" = "x" ]; then export DOCKER_IMAGE=$CI_REGISTRY_IMAGE:latest; fi | |
- echo $NOMAD_ADDR | |
- levant render -out=deployment/job.nomad deployment/job.nomadtpl | |
- nomad plan deployment/job.nomad || if [ $? -eq 1 ]; then echo "OK"; fi | |
- nomad run deployment/job.nomad | |
artifacts: | |
paths: | |
- deployment/*.nomad | |
expire_in: 1 hours | |
rules: | |
- changes: | |
- Dockerfile | |
- deployment/job.nomadtpl | |
- conf/ | |
- build/libs/ | |
when: manual | |
deploy: | |
image: saboteurkid/nomad-levant:0.10.2-0.2.9 | |
needs: | |
- plan new version | |
tags: | |
- internal | |
- production | |
stage: deploy | |
script: | |
- nomad run deployment/job.nomad | |
rules: | |
- if: $CI_COMMIT_TAG | |
when: manual |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment