forked from bonfire-networks/CommonsPub-Server
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile.nginx
121 lines (93 loc) · 3.4 KB
/
Dockerfile.nginx
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
# The version of Elixir to use
# ATTENTION: when changing Elixir version, make sure to update the `ALPINE_VERSION` arg
# as well as the Elixir version in mix.exs and .gitlab-ci.yml and Dockerfile.dev and .tool-versions
ARG ELIXIR_VERSION=1.10.4
# The version of Alpine to use for the final image
# This should match the version of Alpine that the current elixir image (in Step 1) uses
# To find this you need to:
# 1. Locate the dockerfile for the elixir image to get the erlang image version
# e.g. https://github.com/c0b/docker-elixir/blob/master/1.10/alpine/Dockerfile
# 2. Locate the dockerfile for the corresponding erlang image
# e.g. https://github.com/erlang/docker-erlang-otp/blob/master/22/alpine/Dockerfile
ARG ALPINE_VERSION=3.11
# The following are build arguments used to change variable parts of the image, they should be set as env variables.
# The name of your application/release (required)
ARG APP_NAME
# The version of the application we are building (required)
ARG APP_VSN
# What web server to use
ARG WEBSERVER_CHOICE="nginx"
# Step 1 - Build our app
FROM elixir:${ELIXIR_VERSION}-alpine as builder
ENV HOME=/opt/app/ TERM=xterm MIX_ENV=prod
WORKDIR $HOME
# useful deps
RUN apk add --no-cache curl git rust cargo npm
# dependencies for comeonin
RUN apk add --no-cache make gcc libc-dev
# Cache elixir deps
COPY mix.exs mix.lock ./
RUN mix do local.hex --force, local.rebar --force, deps.get --only prod, deps.compile
COPY assets/package* ./assets/
RUN npm install --prefix assets
COPY . .
RUN npm run deploy --prefix ./assets
RUN mix phx.digest
RUN mix release
# Step 2 - Prepare the server image
# From this line onwards, we're in a new image, which will be the image used in production
FROM alpine:${ALPINE_VERSION}
# The name of your application/release (required)
ARG APP_NAME
ARG APP_VSN
ARG APP_BUILD
ARG PROXY_FRONTEND_URL
ENV APP_NAME=${APP_NAME} APP_VSN=${APP_VSN} APP_REVISION=${APP_VSN}-${APP_BUILD}
ENV ACME_AGREE="true"
ENV S6_OVERLAY_VERSION=v1.22.1.0
# Essentials
RUN apk add --update --no-cache \
ca-certificates \
git \
mailcap \
openssh-client \
openssl-dev \
tzdata \
bash \
build-base \
curl \
gettext
# why are git and build-base needed here?
# install s6
RUN set -eux; \
ARCH="$(apk --print-arch)"; echo ${ARCH}; \
case "${ARCH}" in \
amd64|x86_64) \
curl -sSL https://github.com/just-containers/s6-overlay/releases/download/${S6_OVERLAY_VERSION}/s6-overlay-amd64.tar.gz | tar xfz - -C / \
;; \
i386) \
curl -sSL https://github.com/just-containers/s6-overlay/releases/download/${S6_OVERLAY_VERSION}/s6-overlay-x86.tar.gz | tar xfz - -C / \
;; \
armv7) \
curl -sSL https://github.com/just-containers/s6-overlay/releases/download/${S6_OVERLAY_VERSION}/s6-overlay-arm.tar.gz | tar xfz - -C / \
;; \
*) \
curl -sSL https://github.com/just-containers/s6-overlay/releases/download/${S6_OVERLAY_VERSION}/s6-overlay-${ARCH}.tar.gz | tar xfz - -C / \
;; \
esac;
# install nginx
RUN apk add --update --no-cache nginx nginx-mod-http-lua && \
chown -R nginx:www-data /var/lib/nginx
# redirect logs to st output
RUN ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log
# copy s6 and web server config
COPY config/deployment/ /
WORKDIR /opt/app
# install app
COPY --from=builder /opt/app/_build/prod/rel/commons_pub /opt/app
# prepare to run
RUN chmod +x /utils/shutdown-instance.sh
# start
ENTRYPOINT ["/init"]
CMD []