Skip to content

Instantly share code, notes, and snippets.

@kwmiebach
Created November 3, 2018 08:34
Show Gist options
  • Save kwmiebach/17174d0949c0e32a406007400af14b4d to your computer and use it in GitHub Desktop.
Save kwmiebach/17174d0949c0e32a406007400af14b4d to your computer and use it in GitHub Desktop.
GitLab CI example for Elixir (distillery, docker)
# This file is a template, and might need editing before it works on your project.
# This template uses the non default language docker image
# The image already has Hex installed.
image: alpine-elixir:1.4.0
# Pick zero or more services to be used on all builds.
# Only needed when using a docker container to run your tests in.
# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-service
variables:
MODULE_NAME: "YOUR_MODULE"
DOCKER_HUB: "YOUR_HUB"
# ES_JAVA_OPTS: "-Xms512m -Xmx512m"
build:staging:
stage: build
cache:
paths:
- deps/
- _build/
variables:
MIX_ENV: staging
script:
- mix do deps.get
- mix release --env staging --verbose
tags:
- elixir
artifacts:
name: "staging"
expire_in: 1 hour
paths:
- rel/$MODULE_NAME
- Dockerfile
only:
- master
build:production:
stage: build
cache:
paths:
- deps/
- _build/
variables:
MIX_ENV: prod
script:
- mix do deps.get
- mix release --env prod --verbose
tags:
- elixir
artifacts:
name: "$CI_BUILD_TAG"
expire_in: 1 hour
paths:
- rel/$MODULE_NAME
- Dockerfile
only:
- tags
testing:
stage: test
# services:
# - mongo:3.2
# - elasticsearch:5.1
cache:
paths:
- deps/
- _build/
variables:
MIX_ENV: ci
script:
- mix do deps.get
- mix test
tags:
- elixir
only:
- master
- tags
staging:
stage: deploy
image: docker:latest
services:
- docker:dind
environment: staging
variables:
DOCKER_DRIVER: overlay
GIT_STRATEGY: none
script:
- docker build -t $DOCKER_HUB/$MODULE_NAME:staging .
- docker push $DOCKER_HUB/$MODULE_NAME:staging
dependencies:
- build:staging
tags:
- docker-build
only:
- master
production:current:
stage: deploy
image: docker:latest
services:
- docker:dind
environment: production
variables:
DOCKER_DRIVER: overlay
GIT_STRATEGY: none
script:
- docker build -t $DOCKER_HUB/$MODULE_NAME:$CI_BUILD_TAG .
- docker push $DOCKER_HUB/$MODULE_NAME:$CI_BUILD_TAG
dependencies:
- build:production
tags:
- docker-build
only:
- tags
production:latest:
stage: deploy
image: docker:latest
services:
- docker:dind
environment: production
variables:
DOCKER_DRIVER: overlay
GIT_STRATEGY: none
script:
- docker build -t $DOCKER_HUB/$MODULE_NAME:latest .
- docker push $DOCKER_HUB/$MODULE_NAME:latest
dependencies:
- build:production
tags:
- docker-build
only:
- tags
use Mix.Releases.Config,
# This sets the default release built by `mix release`
default_release: :default,
# This sets the default environment used by `mix release`
default_environment: :dev
# For a full list of config options for both releases
# and environments, visit https://hexdocs.pm/distillery/configuration.html
# You may define one or more environments in this file,
# an environment's settings will override those of a release
# when building in that environment, this combination of release
# and environment configuration is called a profile
environment :dev do
set dev_mode: true
set include_erts: true
set cookie: "YOUR_COOKIE"
end
environment :staging do
set include_erts: true
set include_system_libs: true
set include_src: false
set cookie: "YOUR_COOKIE"
set output_dir: "rel/YOUR_MODULE"
end
environment :prod do
set include_erts: true
set include_system_libs: true
set include_src: false
set cookie: "YOUR_COOKIE"
set output_dir: "rel/YOUR_MODULE"
end
# You may define one or more releases in this file.
# If you have not set a default release, or selected one
# when running `mix release`, the first release in the file
# will be used by default
release :YOUR_MODULE do
set version: current_version(:YOUR_MODULE)
end
FROM alpine:3.6
LABEL maintainer="YOU"
# Important! Update this no-op ENV variable when this Dockerfile
# is updated with the current date. It will force refresh of all
# of the base images and things like `apt-get update` won't be using
# old cached versions when the Dockerfile is built.
ENV REFRESHED_AT=2017-10-11 \
MIX_ENV=prod
WORKDIR /opt/app
# Install deps
RUN \
apk --no-cache upgrade && \
# Install Erlang/OTP deps
apk add --no-cache \
ca-certificates \
openssl-dev \
ncurses-dev \
unixodbc-dev \
zlib-dev \
bash
ADD ./rel/YOUR_MODULE .
HEALTHCHECK CMD bin/YOUR_MODULE ping
EXPOSE 80
CMD ["bin/YOUR_MODULE", "foreground"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment