Use Dockerfile provided by Phoenix generator
This commit is contained in:
18
.dockerignore
Normal file
18
.dockerignore
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
.dockerignore
|
||||||
|
# there are valid reasons to keep the .git, namely so that you can get the
|
||||||
|
# current commit hash
|
||||||
|
#.git
|
||||||
|
.log
|
||||||
|
tmp
|
||||||
|
|
||||||
|
# Mix artifacts
|
||||||
|
_build
|
||||||
|
deps
|
||||||
|
*.ez
|
||||||
|
releases
|
||||||
|
|
||||||
|
# Generate on crash by the VM
|
||||||
|
erl_crash.dump
|
||||||
|
|
||||||
|
# Static artifacts
|
||||||
|
node_modules
|
||||||
89
Dockerfile
89
Dockerfile
@@ -1,55 +1,76 @@
|
|||||||
FROM hexpm/elixir:1.13.3-erlang-23.2.3-alpine-3.15.0 as build
|
# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian instead of
|
||||||
|
# Alpine to avoid DNS resolution issues in production.
|
||||||
|
#
|
||||||
|
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
|
||||||
|
# https://hub.docker.com/_/ubuntu?tab=tags
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# This file is based on these images:
|
||||||
|
#
|
||||||
|
# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
|
||||||
|
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20210902-slim - for the release image
|
||||||
|
# - https://pkgs.org/ - resource for finding needed packages
|
||||||
|
# - Ex: hexpm/elixir:1.13.3-erlang-23.2.3-debian-bullseye-20210902-slim
|
||||||
|
#
|
||||||
|
ARG DOCKER_IMAGE="hexpm/elixir:1.13.3-erlang-23.2.3-alpine-3.15.0"
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
|
|
||||||
|
FROM ${DOCKER_IMAGE} as builder
|
||||||
|
|
||||||
|
# install build dependencies
|
||||||
RUN apk add gcc git librdkafka-dev musl-dev
|
RUN apk add gcc git librdkafka-dev musl-dev
|
||||||
|
|
||||||
# install Hex + Rebar
|
# prepare build dir
|
||||||
RUN mix do local.hex --force, local.rebar --force
|
WORKDIR /app
|
||||||
|
|
||||||
|
# install hex + rebar
|
||||||
|
RUN mix local.hex --force && \
|
||||||
|
mix local.rebar --force
|
||||||
|
|
||||||
# set build ENV
|
# set build ENV
|
||||||
ENV MIX_ENV=prod
|
ENV MIX_ENV="prod"
|
||||||
|
|
||||||
# install mix dependencies
|
# install mix dependencies
|
||||||
COPY mix.exs mix.lock ./
|
COPY mix.exs mix.lock ./
|
||||||
COPY config config
|
|
||||||
RUN mix deps.get --only $MIX_ENV
|
|
||||||
RUN DEBUG=1 mix deps.compile
|
|
||||||
#
|
|
||||||
## build assets
|
|
||||||
#COPY assets assets
|
|
||||||
#RUN cd assets && npm install && npm run deploy
|
|
||||||
#RUN mix phx.digest
|
|
||||||
|
|
||||||
# build project
|
RUN mix deps.get --only $MIX_ENV
|
||||||
#COPY priv priv
|
RUN mkdir config
|
||||||
|
|
||||||
|
# copy compile-time config files before we compile dependencies
|
||||||
|
# to ensure any relevant config change will trigger the dependencies
|
||||||
|
# to be re-compiled.
|
||||||
|
COPY config/config.exs config/${MIX_ENV}.exs config/
|
||||||
|
RUN mix deps.compile
|
||||||
|
|
||||||
|
# Compile the release
|
||||||
COPY lib lib
|
COPY lib lib
|
||||||
|
|
||||||
RUN mix compile
|
RUN mix compile
|
||||||
|
|
||||||
# build release
|
# Changes to config/runtime.exs don't require recompiling the code
|
||||||
# at this point we should copy the rel directory but
|
COPY config/runtime.exs config/
|
||||||
# we are not using it so we can omit it
|
|
||||||
# COPY rel rel
|
COPY rel rel
|
||||||
RUN mix release
|
RUN mix release
|
||||||
|
|
||||||
# prepare release image
|
# start a new build stage so that the final image will only contain
|
||||||
FROM hexpm/elixir:1.13.3-erlang-23.2.3-alpine-3.15.0 AS app
|
# the compiled release and other runtime necessities
|
||||||
|
FROM ${DOCKER_IMAGE}
|
||||||
|
|
||||||
# install runtime dependencies
|
# Set the locale
|
||||||
#RUN apk add --update bash openssl postgresql-client
|
#RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
|
||||||
|
|
||||||
EXPOSE 4000
|
#ENV LANG en_US.UTF-8
|
||||||
ENV MIX_ENV=prod
|
#ENV LANGUAGE en_US:en
|
||||||
|
#ENV LC_ALL en_US.UTF-8
|
||||||
|
|
||||||
# prepare app directory
|
WORKDIR "/app"
|
||||||
RUN mkdir /app
|
RUN chown nobody /app
|
||||||
WORKDIR /app
|
|
||||||
|
# Only copy the final release from the build stage
|
||||||
|
COPY --from=builder --chown=nobody:root /app/_build/prod/rel/kafkaex_lag_exporter ./
|
||||||
|
|
||||||
# copy release to app container
|
|
||||||
COPY --from=build /app/_build/prod/rel/kafkaex_lag_exporter .
|
|
||||||
# COPY entrypoint.sh .
|
|
||||||
RUN chown -R nobody: /app
|
|
||||||
USER nobody
|
USER nobody
|
||||||
|
|
||||||
ENV HOME=/app
|
CMD ["/app/bin/server"]
|
||||||
CMD ["/app/bin/kafkaex_lag_exporter", "start"]
|
|
||||||
|
|||||||
3
rel/overlays/bin/server
Executable file
3
rel/overlays/bin/server
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
cd -P -- "$(dirname -- "$0")"
|
||||||
|
PHX_SERVER=true exec ./kafkaex_lag_exporter start
|
||||||
Reference in New Issue
Block a user