-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docker): Optimize dockerfile (#582)
* chore(docker): Optimize dockerfile Optimize dockerfile Signed-off-by: kovacs <[email protected]> * chore(docker): remove STOPSIGNAL remove STOPSIGNAL Signed-off-by: kovacs <[email protected]> * chore(docker): add dump-init add dump-init Signed-off-by: kovacs <[email protected]> * chore(docker): refactor dockerfile refactor dockerfile Signed-off-by: kovacs <[email protected]> * chore(docker): update CMD, add comments update CMD, add comments Signed-off-by: kovacs <[email protected]> * chore(docker): fix docker compose fix docker compose Signed-off-by: kovacs <[email protected]> * chore(docker): rollback dev changes rollback dev changes Signed-off-by: kovacs <[email protected]> Signed-off-by: kovacs <[email protected]>
- Loading branch information
Showing
2 changed files
with
80 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,81 @@ | ||
FROM swift:4.2.4 | ||
############################################################################################################################## | ||
## ## | ||
## 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 . ./ | ||
RUN git submodule update --init --recursive | ||
RUN swift package clean | ||
RUN swift build -c release | ||
RUN mkdir /app/bin | ||
RUN mv `swift build -c release --show-bin-path` /app/bin | ||
EXPOSE 8080 | ||
ENTRYPOINT ["/app/bin/release/Run", "serve", "-e", "prod", "-b", "0.0.0.0"] | ||
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters