-
Notifications
You must be signed in to change notification settings - Fork 48
/
Dockerfile
68 lines (58 loc) · 2.5 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
# Use edge to get dub v1.30 instead of v1.28 (3.16),
# as we otherwise hit https://github.com/dlang/dub/issues/2192
# Change to alpine:3.17 when released.
ARG BASE_IMAGE=alpine:edge
# ----------------------------------- Base ----------------------------------- #
FROM $BASE_IMAGE AS base
RUN apk --no-cache add build-base \
dub dtools ldc \
openssl-dev zlib-dev openblas-dev
WORKDIR /src
# ------------------------ Gather dub package metadata ----------------------- #
FROM base as dub-cache
COPY . .
RUN mkdir /out \
&& find . -name "dub.sdl" -o -name "dub.json" -o -name "dub.selections.json" | \
xargs cp -v --parents -t /out \
# Keep only the name and dependencies of each dub package manifest:
&& find /out -name "dub.sdl" | \
xargs sed -i -n '/dependency\|name/p' \
# Create empty D files for each app to avoid the
# warning: '...package <name> contains no source files...'
&& mkdir -p /out/source && echo -e 'module app;\nvoid main() {}' > /out/source/app.d \
;
# ---------------------------------------------------------------------------- #
# Builders #
# ---------------------------------------------------------------------------- #
# ----------------------------- Dub Cache builder ---------------------------- #
FROM base AS dependencies-cache
COPY --from=dub-cache /out .
RUN dub --cache=local build
# ------------------------------- App builders ------------------------------- #
FROM dependencies-cache AS app-builder
COPY source ./source
COPY views ./views
COPY dub.sdl .
COPY config.yml .
RUN dub --cache=local build -c executable
FROM app-builder AS prod-builder
RUN dub --cache=local build -c executable --build=release-debug
# ------------------------------- Test runners ------------------------------- #
FROM app-builder AS unit-test-runner
COPY public ./public
RUN dub --cache=local test
FROM unit-test-runner AS integration-test-runner
RUN dub --cache=local run -- --sanitycheck
# ---------------------------------------------------------------------------- #
# Runner #
# ---------------------------------------------------------------------------- #
FROM $BASE_IMAGE as runner-cache
RUN apk --no-cache add ldc-runtime libgcc tzdata docker-cli
EXPOSE 8080
WORKDIR /app
FROM runner-cache AS runner
COPY --from=prod-builder /src/build/dlang-tour .
COPY docker/config.docker.yml .
COPY docker/docker.start.sh .
COPY public ./public
ENTRYPOINT [ "/app/docker.start.sh" ]