forked from aviacommerce/avia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
125 lines (92 loc) · 3.1 KB
/
Dockerfile
File metadata and controls
125 lines (92 loc) · 3.1 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# syntax=docker/dockerfile:experimental
#########################################################
## BUILD STAGE - Development image with necessary deps ##
#########################################################
FROM verybigthings/elixir:1.10.4 AS build
ARG APP_USER=user
ARG WORKDIR=/opt/app
ENV APP_USER=$APP_USER
ENV CACHE_DIR=/opt/cache
ENV BUILD_PATH=$CACHE_DIR/_build
ENV HEX_HOME=$CACHE_DIR/hex
ENV MIX_HOME=$CACHE_DIR/mix
ENV PHOENIX_VERSION 1.5.4
ENV REBAR_CACHE_DIR=$CACHE_DIR/rebar
ENV WORKDIR=$WORKDIR
RUN apt-get update && apt-get install -y \
curl \
gcc \
git \
libfontconfig1 \
libxext6 \
libxrender1 \
locales \
gnupg \
make \
postgresql-client \
postgresql-contrib \
vim \
wget
RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
RUN tar vxf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
RUN cp wkhtmltox/bin/wk* /usr/local/bin/
WORKDIR $WORKDIR
RUN mix local.hex --force && mix local.rebar --force
RUN mix archive.install hex phx_new $PHOENIX_VERSION --force
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com > ~/.ssh/known_hosts
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["/bin/bash", "-c", "while true; do sleep 10; done;"]
######################################################################################
## PRE-RELEASE STAGE - compiles code and bundles the application to Erlang release ##
######################################################################################
FROM build AS pre-release
ARG APP_NAME
ENV APP_NAME=${APP_NAME}
COPY . .
RUN --mount=type=ssh MIX_ENV=prod mix do deps.get, deps.compile, compile
RUN cd apps/admin_app/assets && \
yarn install && \
yarn deploy && \
cd - && \
mix phx.digest
RUN MIX_ENV=prod mix do release
############################################
## RELEASE STAGE - production application ##
############################################
FROM debian:10-slim AS release
ARG APP_NAME
ARG APP_USER=user
ARG WORKDIR=/opt/app
ENV APP_NAME=${APP_NAME}
ENV APP_USER=$APP_USER
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV WORKDIR=$WORKDIR
RUN apt-get update && apt-get install -y \
gcc \
git \
libfontconfig1 \
libxext6 \
libxrender1 \
locales \
gnupg \
make \
wget \
xz-utils
RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
RUN tar vxf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
RUN cp wkhtmltox/bin/wk* /usr/local/bin/
RUN useradd --create-home ${APP_USER}
WORKDIR $WORKDIR
COPY --from=pre-release /opt/cache/_build/prod/rel/${APP_NAME} .
RUN chmod +x ./bin/*
RUN chown -R ${APP_USER}: ${WORKDIR}
USER ${APP_USER}
CMD trap 'exit' INT; ${WORKDIR}/bin/${APP_NAME} start
############################################################################
###### RELEASE PHASE - run migrations before production application ########
############################################################################
FROM release AS release-phase
CMD trap 'exit' INT; /opt/app/bin/migrate_all.sh