-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
103 lines (74 loc) · 2.43 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
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
# build with: docker build -t emischorr/mqtt_velux_gw:latest .
# or on mac: docker buildx build --platform=linux/amd64 --no-cache -t emischorr/mqtt_velux_gw:latest .
# run with: docker run -d --rm -e MQTT_HOST=$MQTT_HOST -e MQTT_USER=$MQTT_USER -e MQTT_PW=$MQTT_PW -e VELUX_IP=$VELUX_IP -e VELUX_PW=$VELUX_PW emischorr/mqtt_velux_gw:latest start
# push with: docker push emischorr/mqtt_velux_gw:latest
ARG RELEASE_NAME=mqtt_velux_gw
ARG ELIXIR_VERSION="1.16.3"
ARG ERLANG_VERSION="26.2.5"
ARG ALPINE_VERSION="3.18.6"
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${ERLANG_VERSION}-alpine-${ALPINE_VERSION}"
ARG RUNNER_IMAGE="alpine:${ALPINE_VERSION}"
# -----------------------------------------------------------------------------
ARG MIX_ENV="prod"
# build stage
FROM ${BUILDER_IMAGE} AS builder
# install build dependencies
RUN apk add --no-cache build-base git python3 curl
# sets work dir
WORKDIR /app
# install hex + rebar
RUN mix local.hex --force && \
mix local.rebar --force
# redeclare it as it is lost after the FROM above
ARG MIX_ENV
ENV MIX_ENV="${MIX_ENV}"
# needed for cross platform builds with new erlang.
# see: https://elixirforum.com/t/mix-deps-get-memory-explosion-when-doing-cross-platform-docker-build/57157/3
ENV ERL_FLAGS="+JPperf true"
# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
# copy compile configuration files
RUN mkdir config
COPY config/config.exs config/$MIX_ENV.exs config/
# compile dependencies
RUN mix deps.compile
# copy assets
#COPY priv priv
#COPY assets assets
# Compile assets
#RUN mix assets.deploy
# compile project
COPY lib lib
RUN mix compile
# copy runtime configuration file
COPY config/runtime.exs config/
# assemble release
RUN mix release $RELEASE_NAME
# -----------------------------------------------------------------------------
# app stage
FROM ${RUNNER_IMAGE} AS runner
ARG RELEASE_NAME
ARG MIX_ENV
# install runtime dependencies
RUN apk add --no-cache libstdc++ openssl ncurses-libs
ENV USER="elixir"
WORKDIR "/home/${USER}/app"
# Create unprivileged user to run the release
RUN \
addgroup \
-g 1000 \
-S "${USER}" \
&& adduser \
-s /bin/sh \
-u 1000 \
-G "${USER}" \
-h "/home/${USER}" \
-D "${USER}" \
&& su "${USER}"
# run as user
USER "${USER}"
# copy release executables
COPY --from=builder --chown="${USER}":"${USER}" /app/_build/"${MIX_ENV}"/rel/"${RELEASE_NAME}" ./
ENTRYPOINT ["bin/mqtt_velux_gw"]
CMD ["start"]