Skip to content

Instantly share code, notes, and snippets.

@wunki wunki/Dockerfile
Created Oct 8, 2018

Embed
What would you like to do?
Continuous integration and deployment for a Clojure project on Gitlab
# 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
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
You can’t perform that action at this time.