Created
October 8, 2018 12:26
-
-
Save wunki/896be2e2069a2ba1f06bd402b0423b40 to your computer and use it in GitHub Desktop.
Continuous integration and deployment for a Clojure project on Gitlab
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
# Note, this dockerfile only works if you move the .jar | |
# file into the project directory first. This was done | |
# to get a clean, without any paths, artifact on Gitlab | |
FROM openjdk:8-jre-alpine | |
RUN mkdir -p /app /app/resources | |
WORKDIR /app | |
COPY *-standalone.jar . | |
COPY resources/pegasus/public . | |
CMD java -jar pegasus-0.1.0-SNAPSHOT-standalone.jar | |
EXPOSE 3000 |
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
image: "docker:latest" | |
services: | |
- docker:dind | |
variables: | |
BUILD_IMAGE: clojure:lein-2.8.1-alpine | |
CONTAINER_BASE_NAME: registry.wunki.org/wunki/pegasus | |
CONTAINER_TEST_IMAGE: $CONTAINER_BASE_NAME:$CI_BUILD_REF_SLUG | |
CONTAINER_RELEASE_IMAGE: $CONTAINER_BASE_NAME:latest | |
# For caching, we need to move the .m2 directory | |
# into the project directory. | |
LEIN_JVM_OPTS: -Duser.home=$CI_PROJECT_DIR | |
stages: | |
- test | |
- build | |
- image | |
- deploy | |
test:lein: | |
stage: test | |
image: $BUILD_IMAGE | |
script: | |
- lein test | |
cache: | |
paths: | |
- .m2 | |
tags: | |
- docker | |
build:uberjar: | |
stage: build | |
image: $BUILD_IMAGE | |
script: | |
- lein uberjar | |
# copy the artifact to the project directory so | |
# we don't have the directory name in the zip | |
- mv target/pegasus-0.1.0-SNAPSHOT-standalone.jar $CI_PROJECT_DIR | |
cache: | |
paths: | |
- .m2 | |
artifacts: | |
name: "pegasus_${CI_BUILD_REF_NAME}_${CI_BUILD_ID}" | |
paths: | |
- pegasus-0.1.0-SNAPSHOT-standalone.jar | |
only: | |
- master | |
tags: | |
- docker | |
image:docker: | |
stage: image | |
script: | |
- "docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY" | |
- "export VERSION=${CI_COMMIT_SHA:0:8}" | |
- "export CONTAINER_VERSION_IMAGE=\"${CONTAINER_BASE_NAME}:${VERSION}\"" | |
- "docker build -t $CONTAINER_TEST_IMAGE -t $CONTAINER_RELEASE_IMAGE -t $CONTAINER_VERSION_IMAGE ." | |
- "docker push $CONTAINER_VERSION_IMAGE" | |
- "docker push $CONTAINER_TEST_IMAGE" | |
- "docker push $CONTAINER_RELEASE_IMAGE" | |
only: | |
- master | |
tags: | |
- docker | |
# Using nomad (nomad.io) for continuous deployment. | |
# We only need to update the version in consul and consul-template | |
# will push an updated job to nomad. | |
deploy:consul: | |
stage: deploy | |
script: | |
- "export VERSION=${CI_COMMIT_SHA:0:8}" | |
- "consul kv put pegasus/config/production/version $VERSION" | |
only: | |
- master | |
tags: | |
- shell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment