Skip to content
This repository has been archived by the owner on Dec 21, 2019. It is now read-only.

Commit

Permalink
Merge branch 'docker-ci-cleanup-3' into 'master'
Browse files Browse the repository at this point in the history
Docker and CI cleanup part 3

See merge request Astarte-NG/astarte_realm_management_api!118
  • Loading branch information
bettio committed Nov 27, 2019
2 parents cc9d3cc + be65003 commit 7b3e52e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 13 deletions.
36 changes: 35 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mix:test-coverage:
stage: test
image: elixir:1.8.1
services:
- rabbitmq:3.7.15
- rabbitmq:3.7.21
cache:
key: "$CI_COMMIT_REF_SLUG"
paths:
Expand All @@ -23,6 +23,24 @@ mix:test-coverage:
- mix format --check-formatted
- mix coveralls --exclude wip

mix:test-dialyzer:
stage: test
image: elixir:1.8.1
cache:
key: "$CI_COMMIT_REF_SLUG"
paths:
- deps
- _build
- dialyzer_cache
before_script:
- mix local.hex --force
- mix local.rebar
- export MIX_ENV=ci
- mix deps.get
script:
# TODO: we do this until we fix all dialyzer errors to force a CI success, so that plts get cached
- mix dialyzer || echo "Done"

docker:test-container:
stage: test
image: docker:latest
Expand All @@ -49,3 +67,19 @@ docker:snapshot-prod-container:
- export IMAGE_TAG=$([[ $CI_COMMIT_REF_NAME == "master" ]] && echo "snapshot" || echo $CI_COMMIT_REF_NAME | sed 's/release-\(.*\)/\1-snapshot/g')
- docker build -t $CI_REGISTRY/astarte-ng/astarte_realm_management_api:$IMAGE_TAG .
- docker push $CI_REGISTRY/astarte-ng/astarte_realm_management_api:$IMAGE_TAG

docker:snapshot-dev-container:
stage: deploy
image: docker:latest
only:
- branches@Astarte-NG/astarte_realm_management_api
services:
- docker:stable-dind
before_script:
- docker info
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
script:
- export IMAGE_TAG=$([[ $CI_COMMIT_REF_NAME == "master" ]] && echo "snapshot" || echo $CI_COMMIT_REF_NAME | sed 's/release-\(.*\)/\1-snapshot/g')-dev
- docker build --build-arg BUILD_ENV=dev -t $CI_REGISTRY/astarte-ng/astarte_realm_management_api:$IMAGE_TAG .
- docker push $CI_REGISTRY/astarte-ng/astarte_realm_management_api:$IMAGE_TAG

36 changes: 25 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
FROM elixir:1.8.1-slim as builder
FROM elixir:1.8.1 as builder

RUN apt-get -qq update
RUN apt-get -qq install git build-essential curl
WORKDIR /app

# Install hex
RUN mix local.hex --force && \
mix local.rebar --force && \
mix hex.info
mix local.rebar --force && \
mix hex.info

WORKDIR /app
ENV MIX_ENV prod
# Pass --build-arg BUILD_ENV=dev to build a dev image
ARG BUILD_ENV=prod

ENV MIX_ENV=$BUILD_ENV

# Cache elixir deps
ADD mix.exs mix.lock ./
RUN mix do deps.get, deps.compile

# Add all the rest
ADD . .
RUN mix deps.get
RUN mix release --env=$MIX_ENV

# Build and release
RUN mix do compile, release

# Note: it is important to keep Debian versions in sync, or incompatibilities between libcrypto will happen
FROM debian:stretch-slim

WORKDIR /app

RUN apt-get -qq update

# Set the locale
Expand All @@ -23,7 +35,9 @@ ENV LANG C.UTF-8
# We need SSL
RUN apt-get -qq install libssl1.1

WORKDIR /app
COPY --from=builder /app/_build/prod/rel/astarte_realm_management_api .
# We have to redefine this here since it goes out of scope for each build stage
ARG BUILD_ENV=prod

COPY --from=builder /app/_build/$BUILD_ENV/rel/astarte_realm_management_api .

CMD ["./bin/astarte_realm_management_api", "foreground"]
1 change: 1 addition & 0 deletions config/ci.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use Mix.Config
12 changes: 11 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ defmodule Astarte.RealmManagement.API.Mixfile do
"coveralls.post": :test,
"coveralls.html": :test
],
dialyzer_cache_directory: dialyzer_cache_directory(Mix.env()),
deps: deps() ++ astarte_required_modules(System.get_env("ASTARTE_IN_UMBRELLA"))
]
end
Expand All @@ -56,6 +57,14 @@ defmodule Astarte.RealmManagement.API.Mixfile do
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]

defp dialyzer_cache_directory(:ci) do
"dialyzer_cache"
end

defp dialyzer_cache_directory(_) do
nil
end

defp astarte_required_modules("true") do
[
{:astarte_core, in_umbrella: true},
Expand Down Expand Up @@ -84,7 +93,8 @@ defmodule Astarte.RealmManagement.API.Mixfile do
{:distillery, "~> 1.5", runtime: false},
{:excoveralls, "~> 0.11", only: :test},
{:pretty_log, "~> 0.1"},
{:plug_logger_with_meta, "~> 0.1"}
{:plug_logger_with_meta, "~> 0.1"},
{:dialyzex, github: "Comcast/dialyzex", only: [:dev, :ci]}
]
end
end
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"cyanide": {:git, "https://github.com/ispirata/cyanide.git", "b29af008ba93181df3d2cb352261900acd17e3f7", []},
"decimal": {:hex, :decimal, "1.8.0", "ca462e0d885f09a1c5a342dbd7c1dcf27ea63548c65a65e67334f4b61803822e", [:mix], [], "hexpm"},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"},
"dialyzex": {:git, "https://github.com/Comcast/dialyzex.git", "5e17345b61ba18bc5402a5d1b44a0bf04f2fb85c", []},
"distillery": {:hex, :distillery, "1.5.5", "c6132d5c0152bdce6850fb6c942d58f1971b169b6965d908dc4e8767cfa51a95", [:mix], [], "hexpm"},
"ecto": {:hex, :ecto, "3.1.7", "fa21d06ef56cdc2fdaa62574e8c3ba34a2751d44ea34c30bc65f0728421043e5", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.11.1", "dd677fbdd49114fdbdbf445540ec735808250d56b011077798316505064edb2c", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
Expand Down

0 comments on commit 7b3e52e

Please sign in to comment.