Skip to content

Instantly share code, notes, and snippets.

@mazz
Created September 14, 2021 03:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mazz/c2141f41d0a484e6397f51b9c7c6c962 to your computer and use it in GitHub Desktop.
Save mazz/c2141f41d0a484e6397f51b9c7c6c962 to your computer and use it in GitHub Desktop.
phx 1.6rc0
# STEP 1 - BUILD RELEASE
# cannot use alpine 3.14.0 because of issue here with bcrypt-elxir compiling using make on docker:
# https://github.com/riverrun/bcrypt_elixir/issues/26#issuecomment-881966412
FROM hexpm/elixir:1.12.3-erlang-24.0.6-alpine-3.13.5 AS build
# install build dependencies
RUN apk add --update git \
build-base \
nodejs-current \
nodejs-npm \
yarn
RUN mkdir /app
WORKDIR /app
# install Hex + Rebar
RUN mix do local.hex --force, local.rebar --force
# set build ENV
ENV MIX_ENV=prod
ENV HOSTNAME=faithfulaudio.org
ENV DATABASE_URL=ecto://postgres:postgres@postgres/goshen
ENV SECRET_KEY_BASE=secret
# install mix dependencies
COPY mix.exs mix.lock ./
COPY config config
RUN npm install --prefix ./assets
COPY assets assets
RUN mix deps.get --only $MIX_ENV
RUN mix assets.deploy
RUN mix deps.compile
# build project
COPY priv priv
COPY lib lib
RUN mix compile
# build release
# at this point we should copy the rel directory but
# we are not using it so we can omit it
# COPY rel rel
RUN mix release
####################################################################################################
# STEP 2 - FINAL
FROM alpine:3.13.5 as app
# install runtime dependencies
# https://stackoverflow.com/questions/68010688/docker-run-error-loading-shared-library-libstdc-so-6-and-libgcc-s-so-1
RUN apk upgrade --no-cache && \
apk add --update bash \
openssl \
postgresql-client \
libstdc++
EXPOSE 4000
ENV MIX_ENV=prod
ENV DATABASE_URL=ecto://postgres:postgres@postgres/goshen
ENV SECRET_KEY_BASE=secret
# prepare app directory
RUN mkdir /app
WORKDIR /app
# copy release to app container
COPY --from=build /app/_build/prod/rel/goshen .
COPY entrypoint.sh .
RUN chown -R nobody: /app
USER nobody
ENV HOME=/app
CMD ["bash", "/app/entrypoint.sh"]
# File: my_app/entrypoint.sh
#!/bin/bash
# docker entrypoint script.
# assign a default for the database_user
# DB_USER=${DATABASE_USER:-postgres}
# # wait until Postgres is ready
# while ! pg_isready -q -h $DATABASE_HOST -p 5432 -U $DB_USER
# do
# echo "$(date) - waiting for database to start"
# sleep 2
# done
bin="/app/bin/goshen"
if [ "$PERFORM_DB_SEED" == "true" ]
then
eval "$bin eval \"Goshen.ReleaseTasks.seed\""
fi
# ReleaseTasks.seed does both migrate and seed
# eval "$bin eval \"FaithfulWord.ReleaseTasks.seed\""
# start the elixir application
exec "$bin" "start"
#!/bin/sh
# Sets and enables heart (recommended only in daemon mode)
# case $RELEASE_COMMAND in
# daemon*)
# HEART_COMMAND="$RELEASE_ROOT/bin/$RELEASE_NAME $RELEASE_COMMAND"
# export HEART_COMMAND
# export ELIXIR_ERL_OPTIONS="-heart"
# ;;
# *)
# ;;
# esac
# Set the release to work across nodes. If using the long name format like
# the one below (my_app@127.0.0.1), you need to also uncomment the
# RELEASE_DISTRIBUTION variable below. Must be "sname", "name" or "none".
# export RELEASE_DISTRIBUTION=name
# export RELEASE_NODE=<%= @release.name %>@127.0.0.1
echo "running env.sh.eex..."
if [ "$RELEASE_COMMAND" = "start" ]; then
echo "Beginning migration script..."
bin/goshen eval "Goshen.ReleaseTasks.migrate()"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment