Skip to content

Commit

Permalink
Merge pull request #46 from felipelincoln/refactor/dockerfile
Browse files Browse the repository at this point in the history
Refactor dockerfile
  • Loading branch information
felipelincoln authored Apr 18, 2021
2 parents 4c94f57 + f082fd1 commit c188cfb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
docker build --target build --build-arg MIX_ENV=test --cache-from docker.pkg.github.com/felipelincoln/branchpage/dev-cache:latest --tag branchpage:latest .
- name: Start container
run: docker-compose run -d -e MIX_ENV=test -e CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} -v /app/deps -v /app/_build --name branchpage web /bin/sh
run: docker-compose run -d -e MIX_ENV=test -e CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} -v /branchpage/deps -v /branchpage/_build --name branchpage web /bin/sh

- name: Code format
run: docker exec branchpage mix format --check-formatted
Expand Down
60 changes: 42 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,70 @@
FROM hexpm/elixir:1.11.4-erlang-23.2.7.2-alpine-3.13.3 AS build
# -----------------
# BASE
# -----------------
FROM hexpm/elixir:1.11.4-erlang-23.2.7.2-alpine-3.13.3 AS base

# setup compile env
WORKDIR /app
ARG MIX_ENV=prod
WORKDIR /branchpage

# install hex and rebar
RUN mix do local.hex --force, local.rebar --force

# install dependencies
RUN apk add inotify-tools npm curl bash git
RUN apk add inotify-tools


# -----------------
# BUILD
# -----------------
FROM base AS build

RUN apk add curl bash git

ARG MIX_ENV=prod
ENV MIX_ENV=$MIX_ENV

# install mix dependencies
COPY mix.exs mix.lock ./
COPY apps/web/mix.exs apps/web/mix.exs
COPY config config
RUN mix do deps.get, deps.compile --skip-umbrella-children

# install application
COPY . ./
RUN mix compile


# -----------------
# RELEASE
# -----------------
FROM build AS release

RUN apk add npm

# install node dependencies
COPY apps/web/assets/package.json apps/web/assets/package-lock.json apps/web/assets/
RUN npm ci --prefix ./apps/web/assets --no-audit

# generate static files
COPY apps/web apps/web
RUN npm run --prefix ./apps/web/assets deploy

# digests and compresses static files
RUN mix phx.digest

# install umbrella apps and create release
COPY . ./
RUN mix do compile, release
# generate release executable
RUN mix release


# production stage
FROM alpine:3.13
# -----------------
# PRODUCTION
# -----------------
FROM alpine:3.13.3

WORKDIR /branchpage

ARG MIX_ENV=prod
ENV MIX_ENV=$MIX_ENV

# install dependencies
RUN apk add ncurses-libs curl

# setup app
WORKDIR /app
ARG MIX_ENV=prod
COPY --from=build /app/_build/$MIX_ENV/rel/web ./
COPY --from=release /branchpage/_build/$MIX_ENV/rel/web ./

# start application
CMD ["bin/web", "start"]
Expand Down
6 changes: 2 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ services:
web:
build:
context: .
target: build
args:
- MIX_ENV=dev
target: base
image: branchpage:latest
container_name: branchpage_web
command: mix phx.server
restart: unless-stopped
ports:
- 4000:4000
volumes:
- .:/app
- .:/branchpage
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%{
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
"certifi": {:hex, :certifi, "2.6.1", "dbab8e5e155a0763eea978c913ca280a6b544bfa115633fa20249c3d396d9493", [], [], "hexpm", "524c97b4991b3849dd5c17a631223896272c6b0af446778ba4675a1dff53bb7e"},
"certifi": {:hex, :certifi, "2.6.1", "dbab8e5e155a0763eea978c913ca280a6b544bfa115633fa20249c3d396d9493", [:rebar3], [], "hexpm", "524c97b4991b3849dd5c17a631223896272c6b0af446778ba4675a1dff53bb7e"},
"combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"},
"cowboy": {:hex, :cowboy, "2.8.0", "f3dc62e35797ecd9ac1b50db74611193c29815401e53bac9a5c0577bd7bc667d", [:rebar3], [{:cowlib, "~> 2.9.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "4643e4fba74ac96d4d152c75803de6fad0b3fa5df354c71afdd6cbeeb15fac8a"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.3.1", "ebd1a1d7aff97f27c66654e78ece187abdc646992714164380d8a041eda16754", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a6efd3366130eab84ca372cbd4a7d3c3a97bdfcfb4911233b035d117063f0af"},
Expand Down

0 comments on commit c188cfb

Please sign in to comment.