Skip to content

Commit

Permalink
Enable CircleCI and all new workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
rslota committed Nov 21, 2019
1 parent be689a7 commit 91bcc14
Show file tree
Hide file tree
Showing 41 changed files with 1,112 additions and 668 deletions.
285 changes: 285 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
version: 2.1

filters: &all_tags
tags:
only: /.*/

executors:
elixir-builder:
parameters:
erlang_version:
type: string
default: "22.0"
elixir_version:
type: string
default: "1.9"
env:
type: string
default: test
docker:
- image: rslota/beam-builder:erlang-<< parameters.erlang_version >>_elixir-<< parameters.elixir_version >>
- image: rslota/fcm-http2-mock-server
- image: mobify/apns-http2-mock-server
working_directory: ~/app
environment:
MIX_ENV: << parameters.env >>

commands:
test:
steps:
- checkout
- restore_cache:
keys:
- mix-cache-{{ .Environment.CACHE_VERSION }}-legacy-{{ .Branch }}-{{ .Revision }}
- restore_cache:
keys:
- build-${CIRCLE_JOB}-cache-{{ .Environment.CACHE_VERSION }}-legacy-{{ .Branch }}-{{ .Revision }}
- run:
name: Wait for FCM mock
command: dockerize -wait tcp://localhost:443 -timeout 1m
- run:
name: Wait for APNS mock
command: dockerize -wait tcp://localhost:2197 -timeout 1m

- run: MIX_ENV=test mix do certs.dev, coveralls.circle

- save_cache:
key: build-${CIRCLE_JOB}-cache-{{ .Environment.CACHE_VERSION }}-legacy-{{ .Branch }}-{{ .Revision }}
paths:
- "_build"
- store_artifacts:
path: cover
destination: coverage_results

jobs:
pre-build:
executor: elixir-builder

steps:
- checkout

- run: mix local.hex --force
- run: mix local.rebar --force

- run: mix deps.get
- run: echo "$OTP_VERSION $ELIXIR_VERSION" > .version_file
- save_cache:
key: mix-cache-{{ .Environment.CACHE_VERSION }}-legacy-{{ .Branch }}-{{ .Revision }}
paths:
- deps
- ~/.mix


dialyzer:
executor: elixir-builder

steps:
- checkout
- run: echo "$OTP_VERSION $ELIXIR_VERSION" > .version_file
- restore_cache:
keys:
- mix-cache-{{ .Environment.CACHE_VERSION }}-legacy-{{ .Branch }}-{{ .Revision }}
- restore_cache:
keys:
- plt-cache-{{ .Environment.CACHE_VERSION }}-legacy-{{ checksum ".version_file" }}-{{ checksum "mix.lock" }}
- plt-cache-{{ .Environment.CACHE_VERSION }}-legacy-{{ checksum ".version_file" }}
- run: mix dialyzer --plt
- save_cache:
key: plt-cache-{{ .Environment.CACHE_VERSION }}-legacy-{{ checksum ".version_file" }}-{{ checksum "mix.lock" }}
paths:
- .dialyzer
- _build
- save_cache:
key: plt-cache-{{ .Environment.CACHE_VERSION }}-legacy-{{ checksum ".version_file" }}
paths:
- .dialyzer
- run:
name: Execute dialyzer
command: mix deps.get && mix dialyzer --halt-exit-status

release:
executor:
name: elixir-builder
env: prod

steps:
- checkout
- restore_cache:
keys:
- mix-cache-{{ .Environment.CACHE_VERSION }}-legacy-{{ .Branch }}-{{ .Revision }}
- restore_cache:
keys:
- release-cache-{{ .Environment.CACHE_VERSION }}-legacy-{{ .Branch }}-{{ .Revision }}
- run: mix do certs.dev, distillery.release
- run: tar -czf mongoose_push.tar.gz -C _build/${MIX_ENV}/rel/mongoose_push .
- save_cache:
key: release-cache-{{ .Environment.CACHE_VERSION }}-legacy-{{ .Branch }}-{{ .Revision }}
paths:
- "_build"
- "mongoose_push.tar.gz"


test-erlang-22_elixir-1-9:
executor:
name: elixir-builder
env: test
erlang_version: "22.0"
elixir_version: "1.9"

steps:
- test

test-erlang-22_elixir-1-8:
executor:
name: elixir-builder
env: test
erlang_version: "22.0"
elixir_version: "1.8"

steps:
- test

test-erlang-22_elixir-1-7:
executor:
name: elixir-builder
env: test
erlang_version: "22.0"
elixir_version: "1.7"

steps:
- test

test-erlang-21_elixir-1-9:
executor:
name: elixir-builder
env: test
erlang_version: "21.3"
elixir_version: "1.9"

steps:
- test

test-erlang-21_elixir-1-8:
executor:
name: elixir-builder
env: test
erlang_version: "21.3"
elixir_version: "1.8"

steps:
- test

test-erlang-21_elixir-1-7:
executor:
name: elixir-builder
env: test
erlang_version: "21.3"
elixir_version: "1.7"

steps:
- test

format_check:
executor:
name: elixir-builder

steps:
- checkout
- restore_cache:
keys:
- mix-cache-{{ .Environment.CACHE_VERSION }}-legacy-{{ .Branch }}-{{ .Revision }}

- run: mix format --check-formatted

deploy:
executor:
name: elixir-builder
env: prod

steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- restore_cache:
keys:
- release-cache-{{ .Environment.CACHE_VERSION }}-legacy-{{ .Branch }}-{{ .Revision }}
- run:
name: Generate image tag
command: |
set -x
if [ -n "$CIRCLE_TAG" ]; then
DOCKER_TAG="$CIRCLE_TAG"
elif [ "$CIRCLE_BRANCH" == "master" ]; then
DOCKER_TAG="${CIRCLE_SHA1:0:7}"
else
DOCKER_TAG=`echo $CIRCLE_BRANCH | sed 's,/,_,g'`
fi
env | sort
echo "export DOCKER_TAG=$DOCKER_TAG" >> $BASH_ENV
echo "export DOCKER_IMAGE=mongoose-push" >> $BASH_ENV
- run:
name: Login to DockerHub
command: docker login -u "${DOCKERHUB_USER}" -p "${DOCKERHUB_PASS}"

- run:
name: Build docker image
command: docker build -f Dockerfile.release --build-arg MIX_ENV=prod -t $DOCKER_IMAGE:$DOCKER_TAG .
- run:
name: Tag and push docker image
command: |
set -x
docker tag $DOCKER_IMAGE:$DOCKER_TAG $DOCKERHUB_REPOSITORY/$DOCKER_IMAGE:$DOCKER_TAG
docker push $DOCKERHUB_REPOSITORY/$DOCKER_IMAGE:$DOCKER_TAG
if [ "$CIRCLE_BRANCH" == "master" ]; then
docker tag $DOCKER_IMAGE:$DOCKER_TAG $DOCKERHUB_REPOSITORY/$DOCKER_IMAGE:latest
docker push $DOCKERHUB_REPOSITORY/$DOCKER_IMAGE:latest
echo "Image has been pushed as: '$DOCKERHUB_REPOSITORY/$DOCKER_IMAGE:latest'"
fi
echo "Image has been pushed as: '$DOCKERHUB_REPOSITORY/$DOCKER_IMAGE:$DOCKER_TAG'"
workflows:
version: 2
build_and_test:
jobs:
- pre-build:
filters: *all_tags
- format_check:
requires:
- pre-build
filters: *all_tags

- test-erlang-22_elixir-1-9:
requires:
- pre-build
filters: *all_tags
- test-erlang-22_elixir-1-8:
requires:
- pre-build
filters: *all_tags
- test-erlang-22_elixir-1-7:
requires:
- pre-build
filters: *all_tags
- test-erlang-21_elixir-1-9:
requires:
- pre-build
filters: *all_tags
- test-erlang-21_elixir-1-8:
requires:
- pre-build
filters: *all_tags
- test-erlang-21_elixir-1-7:
requires:
- pre-build
filters: *all_tags

- release:
requires:
- pre-build
filters: *all_tags
- deploy:
requires:
- test-erlang-22_elixir-1-9
- release
filters: *all_tags
4 changes: 1 addition & 3 deletions .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
# set this value to 0 (zero).
{Credo.Check.Design.TagTODO, exit_status: 2},
{Credo.Check.Design.TagFIXME},

{Credo.Check.Readability.FunctionNames},
{Credo.Check.Readability.LargeNumbers},
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 100},
Expand Down Expand Up @@ -102,7 +101,6 @@
{Credo.Check.Refactor.PipeChainStart},
{Credo.Check.Refactor.UnlessWithElse},
{Credo.Check.Refactor.VariableRebinding},

{Credo.Check.Warning.BoolOperationOnSameValues},
{Credo.Check.Warning.IExPry},
{Credo.Check.Warning.IoInspect},
Expand All @@ -119,7 +117,7 @@
{Credo.Check.Warning.UnusedPathOperation},
{Credo.Check.Warning.UnusedRegexOperation},
{Credo.Check.Warning.UnusedStringOperation},
{Credo.Check.Warning.UnusedTupleOperation},
{Credo.Check.Warning.UnusedTupleOperation}

# Custom checks can be created using `mix credo.gen.check`.
#
Expand Down
Empty file added .dialyzer/.keep
Empty file.
7 changes: 7 additions & 0 deletions .dialyzer_ignore.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
~r/unmatched_return/,
~r/Function :asn1ct.compile\/2 does not exist/,
~r/lib\/mix\//,
{"lib/mongoose_push/router.ex"},
{"test/support/api.ex"}
]
3 changes: 3 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}"]
]
40 changes: 0 additions & 40 deletions .travis.yml

This file was deleted.

19 changes: 16 additions & 3 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,20 @@ config :plug, :statuses, %{
460 => "Invalid device token"
}

lager_formater_config = [:date, 'T', :time, :color, ' [', :severity, '] ', :pid, ' ', :message, '\e[0m\r\n']
lager_formater_config = [
:date,
'T',
:time,
:color,
' [',
:severity,
'] ',
:pid,
' ',
:message,
'\e[0m\r\n'
]

config :lager,
colored: false,
handlers: [
Expand All @@ -49,10 +62,10 @@ config :lager,
level: :info,
formatter: :lager_default_formatter,
formatter_config: lager_formater_config
]
]
]

import_config "#{Mix.env}.exs"
import_config "#{Mix.env()}.exs"

# Globally disable maru's "test mode". If we don't disable it explicitly
# it will crash a release.
Expand Down
Loading

0 comments on commit 91bcc14

Please sign in to comment.