-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
81 lines (63 loc) · 2.14 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
ARG CRYSTAL_VERSION=latest
FROM placeos/crystal:$CRYSTAL_VERSION as build
WORKDIR /app
# Set the commit via a build arg
ARG PLACE_COMMIT="DEV"
# Set the platform version via a build arg
ARG PLACE_VERSION="DEV"
# Create a non-privileged user, defaults are appuser:10001
ARG IMAGE_UID="10001"
ENV UID=$IMAGE_UID
ENV USER=appuser
# See https://stackoverflow.com/a/55757473/12429735RUN
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
# Install shards for caching
COPY shard.yml shard.yml
COPY shard.override.yml shard.override.yml
COPY shard.lock shard.lock
RUN shards install --production --ignore-crystal-version --skip-postinstall --skip-executables
# Add source last for efficient caching
COPY src /app/src
# Build application
RUN UNAME_AT_COMPILE_TIME=true \
PLACE_COMMIT=$PLACE_COMMIT \
PLACE_VERSION=$PLACE_VERSION \
shards build --production --error-trace
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
# Extract binary dependencies
RUN for binary in /app/bin/*; do \
ldd "$binary" | \
tr -s '[:blank:]' '\n' | \
grep '^/' | \
xargs -I % sh -c 'mkdir -p $(dirname deps%); cp % deps%;'; \
done
# Build a minimal docker image
FROM scratch
WORKDIR /
ENV PATH=$PATH:/
# Copy the user information over
COPY --from=build /etc/passwd /etc/passwd
COPY --from=build /etc/group /etc/group
# These are required for communicating with external services
COPY --from=build /etc/hosts /etc/hosts
# These provide certificate chain validation where communicating with external services over TLS
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
# This is required for Timezone support
COPY --from=build /usr/share/zoneinfo/ /usr/share/zoneinfo/
# Copy the app into place
COPY --from=build /app/deps /
COPY --from=build /app/bin /
# Use an unprivileged user.
USER appuser:appuser
# Run the app binding on port 3000
EXPOSE 3000
HEALTHCHECK CMD ["/source", "-c", "http://127.0.0.1:3000/api/source/v1/"]
CMD ["/source", "-b", "0.0.0.0", "-p", "3000"]