chore(build): create dockerfile for release deployment

Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
Amogh Lele 2021-08-13 14:12:49 +05:30
parent aa86d9a4b9
commit 30bbc9b78d
No known key found for this signature in database
GPG Key ID: ED5C54FBBB920E51
5 changed files with 90 additions and 4 deletions

35
.dockerignore Normal file
View File

@ -0,0 +1,35 @@
# The directory Mix will write compiled artifacts to.
/_build/
# If you run "mix test --cover", coverage assets end up here.
/cover/
# The directory Mix downloads your dependencies sources to.
/deps/
# Where 3rd-party dependencies like ExDoc output generated docs.
/doc/
# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch
# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez
# Ignore package tarball (built via "mix hex.build").
ketbin-*.tar
# If NPM crashes, it generates a log, let's ignore it too.
npm-debug.log
# The directory NPM downloads your dependencies sources to.
/assets/node_modules/
# Since we are building assets from assets/,
# we ignore priv/static. You may want to comment
# this depending on your deployment strategy.
/priv/static/
.idea

3
.gitignore vendored
View File

@ -32,4 +32,5 @@ npm-debug.log
# we ignore priv/static. You may want to comment
# this depending on your deployment strategy.
/priv/static/
.idea
.idea
.env

50
Dockerfile Normal file
View File

@ -0,0 +1,50 @@
FROM elixir:alpine AS build
# install build dependencies
RUN apk add --no-cache build-base npm git curl py-pip
# prepare build dir
WORKDIR /app
# install hex + rebar
RUN mix local.hex --force && \
mix local.rebar --force
# set build ENV
ENV MIX_ENV=prod
# install mix dependencies
COPY mix.exs mix.lock ./
COPY config config
RUN mix do deps.get, deps.compile
# build assets
COPY assets/package.json assets/package-lock.json ./assets/
RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
COPY priv priv
COPY assets assets
RUN npm run --prefix ./assets deploy
RUN mix phx.digest
# compile and build release
COPY lib lib
# uncomment COPY if rel/ exists
# COPY rel rel
RUN mix do compile, release
# prepare release image
FROM alpine:3.9 AS app
RUN apk add --no-cache openssl ncurses-libs libstdc++
WORKDIR /app
RUN chown nobody:nobody /app
USER nobody:nobody
COPY --from=build --chown=nobody:nobody /app/_build/prod/rel/ketbin ./
ENV HOME=/app
CMD ["bin/ketbin", "start"]

View File

@ -52,4 +52,4 @@ config :logger, level: :info
# Finally import the config/prod.secret.exs which loads secrets
# and configuration from environment variables.
import_config "prod.secret.exs"
# import_config "prod.secret.exs"

View File

@ -2,7 +2,7 @@
# from environment variables. You can also hardcode secrets,
# although such is generally not recommended and you have to
# remember to add this file to your .gitignore.
use Mix.Config
import Config
database_url =
System.get_env("DATABASE_URL") ||
@ -35,7 +35,7 @@ config :ketbin, KetbinWeb.Endpoint,
# If you are doing OTP releases, you need to instruct Phoenix
# to start each relevant endpoint:
#
# config :ketbin, KetbinWeb.Endpoint, server: true
config :ketbin, KetbinWeb.Endpoint, server: true
#
# Then you can assemble a release by calling `mix release`.
# See `mix help release` for more information.