Skip to content

Commit

Permalink
dockerize app
Browse files Browse the repository at this point in the history
  • Loading branch information
nmenag committed Mar 30, 2024
1 parent b3a4efa commit f3e897b
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
121 changes: 121 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
FROM hexpm/elixir:1.16.1-erlang-26.2.3-debian-buster-20240130 AS elixir-builder

RUN apt update && apt install -y git build-essential

# If you're using a hex mirror:
# ENV HEX_MIRROR=https://my_hex_mirror

RUN mix local.hex --force
RUN mix local.rebar --force

# -----------------------------------
# Base Image #2: Elixir Runner
# - Elixir Application Runner
# This is used as a simple operating
# system image to host your
# application
# -----------------------------------
FROM debian:buster as elixir-runner

# You can add any libraries required by your application
# here:

RUN apt-get update && \
apt-get install -y \
# If you're using `:crypto`, you'll need openssl installed \
libssl-dev \
locales \
curl \
openssh-client

RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# -----------------------------------
# - stage: install
# - job: dependencies
# -----------------------------------
FROM elixir-builder AS deps

ENV MIX_ENV=prod

# If you're using a hex mirror:
# ENV HEX_MIRROR=https://my_hex_mirror

WORKDIR /src

COPY config /src/config
COPY mix.exs mix.lock /src/
COPY apps/core/mix.exs /src/apps/core/mix.exs
COPY apps/web/mix.exs /src/apps/web/mix.exs

# Download public key for github.com
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts

# If inside an umbrella project, you also need to add all `mix.exs`
# e.g
# COPY apps/my_app_1/mix.exs /src/apps/my_app_1/mix.exs
# COPY apps/my_app_2/mix.exs /src/apps/my_app_2/mix.exs

RUN --mount=type=ssh mix deps.get --only $MIX_ENV

# -----------------------------------
# - stage: build
# - job: compile_deps
# -----------------------------------
FROM deps AS compile_deps
WORKDIR /src

ENV MIX_ENV=prod
RUN mix deps.compile

# -----------------------------------
# - stage: build
# - job: compile_app
# -----------------------------------
FROM compile_deps AS compile_app
WORKDIR /src

ENV MIX_ENV=prod

COPY . .

RUN mix compile --warnings-as-errors
RUN cd apps/web && mix phx.digest

# -----------------------------------
# - stage: release
# - job: mix_release
# -----------------------------------
FROM compile_app AS mix_release

WORKDIR /src

ENV MIX_ENV=prod

RUN mix release --path /app --quiet

# -----------------------------------
# - stage: release
# - job: release_image
# -----------------------------------
FROM elixir-runner AS release_image

# If you need to inject the app revision into the container,
# uncomment below:
ARG APP_REVISION=latest
ENV APP_REVISION=$APP_REVISION

ENV MIX_ENV=prod

USER nobody

COPY --from=mix_release --chown=nobody:nogroup /app /app
COPY --from=mix_release /src/liveness.sh /app/
WORKDIR /app

ENTRYPOINT ["/app/bin/go_escuela_lms"]
CMD ["start"]
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.2"

services:
postgres:
image: sameersbn/postgresql
restart: always
environment:
- PG_PASSWORD=postgres
ports:
- "5432:5432"
7 changes: 7 additions & 0 deletions liveness.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
if ( curl --silent --fail "http://localhost:4000/api" > /dev/null --max-time 10 ) ; then
echo "Main Health Endpoint - ok"
else
echo "Main Health Endpoint - Time Out"
exit 1
fi

0 comments on commit f3e897b

Please sign in to comment.