-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
66 lines (52 loc) · 1.88 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
FROM nebo15/alpine-elixir:latest
MAINTAINER Nebo#15 [email protected]
# Configure environment variables and other settings
ENV MIX_ENV=prod \
APP_NAME=report_api \
APP_PORT=4000
WORKDIR ${HOME}
# Required for elixir_make to work, which is used by some very popular libs
RUN apk add --update --no-cache make
# Install and compile project dependencies
COPY mix.* ./
RUN mix do deps.get, deps.compile
# Add project sources
COPY . .
# Compile project for Erlang VM
RUN mix do compile, release --verbose
# Reduce container size
RUN apk del --no-cache make
# Move release to /opt/$APP_NAME
RUN set -e; \
mkdir -p /var/log && \
mkdir -p $HOME/priv && \
mkdir -p /opt/${APP_NAME}/log && \
mkdir -p /opt/${APP_NAME}/var && \
mkdir -p /opt/${APP_NAME}/bin/hooks && \
cp -R $HOME/priv /opt/${APP_NAME}/ && \
cp -R $HOME/bin/hooks /opt/${APP_NAME}/bin/ && \
APP_TARBALL=$(find $HOME/_build/$MIX_ENV/rel/${APP_NAME}/releases -maxdepth 2 -name ${APP_NAME}.tar.gz) && \
cp $APP_TARBALL /opt/${APP_NAME}/ && \
cd /opt/${APP_NAME} && \
tar -xzf ${APP_NAME}.tar.gz && \
rm ${APP_NAME}.tar.gz && \
rm -rf /opt/app/* && \
rm -rf /opt/app && \
chmod -R 777 /opt/${APP_NAME}/log && \
chmod -R 777 /opt/${APP_NAME}/releases && \
chmod -R 777 /opt/${APP_NAME}/var && \
chmod -R 777 /var/log
# Change user to "default"
USER default
# Allow to read ENV vars for mix configs
ENV REPLACE_OS_VARS=true
# Exposes this port from the docker container to the host machine
EXPOSE ${APP_PORT}
# Change workdir to a released directory
WORKDIR /opt
# Pre-run hook that allows you to add initialization scripts.
# All Docker hooks should be located in bin/hooks directory.
RUN $APP_NAME/bin/hooks/pre-run.sh
# The command to run when this image starts up.
# To run migrations on start set DB_MIGRATE=true env when starting container.
CMD $APP_NAME/bin/$APP_NAME foreground