Skip to content

Instantly share code, notes, and snippets.

@pedromlcosta
Created November 6, 2018 15:15
Show Gist options
  • Save pedromlcosta/8d5d244ebe37b2ed70f3df5a9ae2108f to your computer and use it in GitHub Desktop.
Save pedromlcosta/8d5d244ebe37b2ed70f3df5a9ae2108f to your computer and use it in GitHub Desktop.
# .circleci/config.yml
defaults: &defaults
parallelism: 1 # run only one instance of this job in parallel
working_directory: ~/app # directory where steps will run
docker: # run the steps with Docker
- image: circleci/elixir:1.7.3 # ...with this image as the primary container; this is where all `steps` will run
environment: # environment variables for primary container
MIX_ENV: test
# database image
- image: circleci/postgres:10.4-alpine-postgis-ram
# fakes3
- image: circleci/fakes3:0.2.4
version: 2 # use CircleCI 2.0 instead of CircleCI Classic
jobs: # basic units of work in a run
test:
<<: *defaults
steps: # commands that comprise the `build` job
- checkout # check out source code to working directory
- run: mix local.hex --force # install Hex locally (without prompt)
- run: mix local.rebar --force # fetch a copy of rebar (without prompt)
- restore_cache: # restores saved mix cache for the deps folder
keys: # list of cache keys, in decreasing specificity
- v1-mix-cache-{{ checksum "mix.lock" }}
- v1-mix-cache-{{ .Branch }}
- v1-mix-cache
- restore_cache: # restores saved build cache
keys:
- v1-build-cache-{{ .Branch }}
- v1-build-cache
- run: # special utility that stalls main process until DB is ready
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run: mix do deps.get, compile # get updated dependencies & compile them
- save_cache: # generate and store cache so `restore_cache` works for the deps folder
key: v1-mix-cache-{{ checksum "mix.lock" }}
paths: "deps"
- save_cache: # make another less specific cache
key: v1-mix-cache-{{ .Branch }}
paths: "deps"
- save_cache: # you should really save one more cache just in case
key: v1-mix-cache
paths: "deps"
- save_cache: # don't forget to save a *build* cache, too
key: v1-build-cache-{{ .Branch }}
paths: "_build"
- save_cache: # and one more build cache for good measure
key: v1-build-cache
paths: "_build"
- run: mix ecto.create
- run: mix ecto.migrate
- run: fakes3 -r $HOME/.s3bucket -p 4567 &
- run: mix test # run all tests in project
deploy:
<<: *defaults
steps:
- checkout # check out source code to working directory
- run: mix local.hex --force # install Hex locally (without prompt)
- run: mix local.rebar --force # fetch a copy of rebar (without prompt)
- run: mix do deps.get, compile # get updated dependencies & compile them
# TODO: we should only run this steps on merge, right now we do the check on the script itself which does not prevent the checkout and all the other run steps to occur
- run:
name: Deploy if tests pass and branch is develop
command: bash scripts/deploy.sh
workflows:
version: 2
build-test-and-deploy-staging:
jobs:
- test:
context: lixomarinho-staging
- deploy:
context: lixomarinho-staging
requires:
- test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment