-
Notifications
You must be signed in to change notification settings - Fork 627
/
Dockerfile
81 lines (64 loc) · 3.7 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
##############################################################################################################################
## ##
## We recommend building with buildx: ##
## ##
## // Note: you can use the standard `docker build` command, but there is no multi-CPU architecture support ##
## ##
## // Create buildx instance ##
## docker buildx create --driver docker-container --name builder --bootstrap --use ##
## ##
## // Login to Rregistry ##
## docker login [REGSITRY_ADDRESS] ##
## ##
## // Build the docker image (both x86 and amd64 are supported) ##
## docker buildx build --platform=linux/amd64,linux/arm64 --push -t [REGSITRY_ADDRESS]/REGSITRY_USERNAME/gitignore.io . ##
## ##
##############################################################################################################################
# Build swift backend
FROM swift:5.6-focal AS swift-builder
COPY . /gitignore.io
WORKDIR /gitignore.io
RUN set -ex \
&& apt update \
&& apt install libssl-dev -y \
&& swift package clean \
&& swift package update \
&& swift build -Xswiftc -static-stdlib -j $(nproc) -c release \
&& mv $(swift build -Xswiftc -static-stdlib -c release --show-bin-path)/Run /tmp/Run
# Build node frontend
FROM node:lts AS node-builder
COPY . /gitignore.io
WORKDIR /gitignore.io
RUN set -ex \
&& yarn install \
&& yarn build \
&& rm -rf node_modules
# Build final image
FROM debian:stable-slim AS dest
WORKDIR /app
# The environment variable is set to empty(use the default value)
ARG HOST_ORIGIN
ARG BASE_PREFIX
ARG GOOGLE_ANALYTICS_UID
# Copy the project and remove the node frontend
COPY . ./
COPY .git ./
# Install some necessary dependencies
RUN set -ex \
&& apt update \
&& apt install git ca-certificates libcurl4 dumb-init --no-install-recommends -y \
&& git submodule update --init --recursive \
&& rm -rf /app/Public /app/Resources \
&& apt autoremove -y \
&& apt autoclean -y
# Copy all newly compiled files to the final image
COPY --from=swift-builder /tmp/Run /app/Run
COPY --from=node-builder /gitignore.io/Public /app/Public
COPY --from=node-builder /gitignore.io/Resources /app/Resources
EXPOSE 8080/tcp
# Add dump-init to ensure container can respond to exit signals
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
# System signals are taken over by dump-init, we can use `exec` to execute
# commands without worrying about signal forwarding and zombie processes
# See Also: https://docs.docker.com/engine/reference/builder/#cmd
CMD ["/app/Run", "serve", "-e", "prod", "-b", "0.0.0.0"]