-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
89 lines (67 loc) · 1.91 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
FROM hexpm/elixir:1.15.7-erlang-26.1-debian-bookworm-20230612-slim as base
# install build dependencies
# --allow-releaseinfo-change allows to pull from 'oldstable'
RUN apt-get update --allow-releaseinfo-change -y && \
apt-get install -y \
build-essential \
git \
openssl \
ca-certificates \
inotify-tools && \
apt-get clean && \
rm -f /var/lib/apt/lists/*_*
# Install hex
RUN mix local.hex --force && \
mix local.rebar --force && \
mix hex.info
WORKDIR /src
FROM base as deps
ARG BUILD_ENV=prod
ENV MIX_ENV=${BUILD_ENV}
# Cache elixir deps
ADD mix.exs mix.lock ./
RUN mix do deps.get --only ${MIX_ENV}, deps.compile
FROM deps as builder
ENV MIX_ENV=${BUILD_ENV}
# Add all the rest
ADD . .
ENTRYPOINT [ "/bin/sh", "-c" ]
# ------------------------
# Only for production
FROM builder as release
ENV MIX_ENV=${BUILD_ENV}
COPY --from=builder /src .
WORKDIR /src
RUN mix do compile, release
RUN mkdir -p /rel && \
cp -r _build/$BUILD_ENV/rel /rel
# Check if entrypoint.sh exists,
# otherwise a default script is created
RUN if [ -f "./entrypoint.sh" ]; then \
cp ./entrypoint.sh /rel/entrypoint.sh; \
else \
echo '#!/bin/bash' >> /rel/entrypoint.sh; \
echo exec \$@ >> /rel/entrypoint.sh; \
fi; \
chmod +x /rel/entrypoint.sh
# Note: it is important to keep Debian versions in sync,
# or incompatibilities between libcrypto will happen
FROM debian:bookworm-slim
# Set the locale
ENV LANG C.UTF-8
# We need SSL
RUN apt-get -qq update -y && \
apt-get -qq install \
openssl \
ca-certificates \
&& apt-get clean \
&& rm -f /var/lib/apt/lists/*_*
WORKDIR /app
COPY --from=release --chown=nobody:nobody /rel/* .
# Symlink to the service, to make a single entry point
# for all the apps
RUN APP_NAME=$(ls | head -n 1) && \
ln -s ${APP_NAME}/bin/${APP_NAME} astarte-service
USER nobody
ENTRYPOINT [ "./entrypoint.sh" ]
CMD ["./astarte-service", "start"]