Skip to content

Instantly share code, notes, and snippets.

@szobov
Created April 23, 2018 08:44
Show Gist options
  • Save szobov/1c88d8ba4e49ec9ea432451d34eb0ada to your computer and use it in GitHub Desktop.
Save szobov/1c88d8ba4e49ec9ea432451d34eb0ada to your computer and use it in GitHub Desktop.
gitlab-ci.yaml elixir deploy
stages:
- init
- test
- deploy
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- deps/
- _build/
init:
stage: init
image: virviil/asdf-elixir:latest
variables:
MIX_ENV: "test"
script:
- mix deps.get
- mix compile
test:
stage: test
image: virviil/asdf-elixir:latest
services:
- postgres:latest
variables:
MIX_ENV: "test"
script:
- mix ecto.reset
- mix test
code_analysis:
stage: test
image: virviil/asdf-elixir:latest
services:
- postgres:latest
variables:
MIX_ENV: "test"
script:
- mix format mix.exs "apps/**/*.{ex,exs}" "test/**/*.{ex,exs}" "config/**/*.{ex,exs}" --check-formatted
- mix credo
- mix compile --warnings-as-errors
deploy_stage1:
stage: deploy
image: virviil/asdf-elixir:latest
before_script:
- git fetch origin $CI_COMMIT_REF_NAME:$CI_COMMIT_REF_NAME --force
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- if git config remote.stage1.url > /dev/null; then git remote set-url origin dokku@iilhub.com:hota-core-s1; else git remote add stage1 dokku@iilhub.com:hota-core-s1; fi
- git push stage1 $CI_COMMIT_REF_NAME:master
cache: {}
environment:
name: stage1
url: http://hota-core-s1.iilhub.com
when: manual
# auto_deploy_stage1:
# stage: deploy
# image: virviil/asdf-elixir:latest
# before_script:
# - eval $(ssh-agent -s)
# - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
# - mkdir -p ~/.ssh
# - chmod 700 ~/.ssh
# - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
# - chmod 644 ~/.ssh/known_hosts
# script:
# - git push stage1 master
# cache: {}
# only:
# - master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment