-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
87 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
ARG RUST_VERSION=1.79.0 | ||
ARG APP_NAME=fibonacci | ||
|
||
FROM rust:${RUST_VERSION}-alpine AS build | ||
ARG APP_NAME | ||
WORKDIR /app | ||
|
||
RUN apk add --no-cache clang lld musl-dev git | ||
|
||
# Build the application. | ||
# Leverage a cache mount to /usr/local/cargo/registry/ | ||
# for downloaded dependencies, a cache mount to /usr/local/cargo/git/db | ||
# for git repository dependencies, and a cache mount to /app/target/ for | ||
# compiled dependencies which will speed up subsequent builds. | ||
# Leverage a bind mount to the src directory to avoid having to copy the | ||
# source code into the container. Once built, copy the executable to an | ||
# output directory before the cache mounted /app/target is unmounted. | ||
RUN --mount=type=bind,source=src,target=src \ | ||
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \ | ||
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \ | ||
--mount=type=cache,target=/app/target/ \ | ||
--mount=type=cache,target=/usr/local/cargo/git/db \ | ||
--mount=type=cache,target=/usr/local/cargo/registry/ \ | ||
cargo build --locked --release && \ | ||
cp ./target/release/$APP_NAME /bin/server | ||
|
||
FROM alpine:3.18 AS final | ||
|
||
# Create a non-privileged user that the app will run under. | ||
# See https://docs.docker.com/go/dockerfile-user-best-practices/ | ||
ARG UID=10001 | ||
RUN adduser \ | ||
--disabled-password \ | ||
--gecos "" \ | ||
--home "/nonexistent" \ | ||
--shell "/sbin/nologin" \ | ||
--no-create-home \ | ||
--uid "${UID}" \ | ||
appuser | ||
USER appuser | ||
|
||
COPY --from=build /bin/server /bin/ | ||
|
||
EXPOSE 8080 | ||
|
||
CMD ["/bin/server"] |
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
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
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