Skip to content

Commit 7ce32d0

Browse files
Paul Beltbelt
Paul Belt
authored andcommitted
feat: Dockerfile (based on Alpine)
1 parent 6a22b20 commit 7ce32d0

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

Diff for: .dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.git
2+
.github
3+
.gitignore
4+
.pre-commit-config.yaml
5+
.taplo.toml

Diff for: docker/Dockerfile

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
FROM rust:alpine AS bootstrap_os
2+
# hadolint ignore=DL3018
3+
RUN apk upgrade --update-cache --available
4+
5+
FROM alpine:latest AS bootstrap_cargo_config_scache
6+
RUN mkdir -p .cargo \
7+
&& { \
8+
echo '[build]'; \
9+
echo 'rustc-wrapper = "/bin/sccache"'; \
10+
} > .cargo/config.toml
11+
12+
FROM bootstrap_os AS bootstrap_build_deps
13+
RUN set -ex; \
14+
apk add --no-cache --virtual .rust-builder clang musl-dev make pkgconfig \
15+
&& apk add --no-cache --virtual .bootstrap-sccache libressl-dev \
16+
&& apk add --no-cache --virtual .runtime-sccache libressl
17+
18+
19+
FROM bootstrap_build_deps AS bootstrap_builder
20+
ENV RUST_BACKTRACE=1 \
21+
CC=clang \
22+
CXX=clang++ \
23+
MAKEOPTS="-j$(getconf _NPROCESSORS_ONLN)"
24+
25+
WORKDIR /src
26+
27+
COPY . .
28+
29+
# Note: more code == more security footprints
30+
# add something like the following to limit features to only that in which is used
31+
#
32+
# cargo build --release --no-default-features --features=local|s3|redis|gcs|memcached|azure|gha|webdav|oss
33+
#
34+
# ref: https://github.com/mozilla/sccache?tab=readme-ov-file#storage-options
35+
RUN cargo build --release --message-format short \
36+
&& apk del .bootstrap-sccache \
37+
&& apk del .rust-builder
38+
39+
# docker build -f docker/Dockerfile.alpine -t sccache:latest --compress . --target=pipeline
40+
FROM alpine:latest AS pipeline
41+
# hadolint ignore=SC2016
42+
RUN --mount=type=bind,source=/etc,target=/mnt_etc,from=bootstrap_os set -ex; \
43+
apk update \
44+
&& apk add shfmt \
45+
&& apk upgrade --update-cache --available \
46+
&& { \
47+
echo '#!/bin/sh'; \
48+
echo 'set -eu'; \
49+
echo 'if [ "${#}" -gt 0 ] && [ "${1#-}" = "${1}" ] \'; \
50+
echo ' && command -v "${1}" > "/dev/null" 2>&1; then'; \
51+
echo ' exec "${@}"'; \
52+
echo 'else exec /usr/bin/shfmt "${@}"; fi'; \
53+
echo 'exit 0'; \
54+
} > /init && chmod +x /init
55+
56+
COPY --from=bootstrap_builder /src/target/release/sccache /usr/local/cargo/bin/
57+
58+
WORKDIR /usr/local/cargo/bin
59+
60+
SHELL [ "/bin/ash", "-o", "pipefail", "-c" ]
61+
62+
RUN find . -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \
63+
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); gsub(".*/", "", so); print so }' \
64+
| xargs -r apk search -f | awk '{ so = $(NF-1); gsub(/-\d+.*$/, "", so); print so }' \
65+
| xargs -r apk add --no-cache --virtual .runtime
66+
67+
ENV PATH="/usr/local/cargo/bin:${PATH}" \
68+
RUSTC_WRAPPER="/usr/local/cargo/bin/sccache"
69+
70+
WORKDIR /root
71+
72+
HEALTHCHECK --retries=1 --timeout=15s CMD /usr/local/cargo/bin/sccache --version
73+
74+
ENTRYPOINT [ "/init" ]
75+
76+
FROM scratch
77+
ENV RUSTC_WRAPPER="/bin/sccache"
78+
79+
COPY --from=bootstrap_builder /usr/local/cargo/bin/sccache /bin/
80+
COPY --from=bootstrap_cargo_config_scache /root/.cargo/config.toml ${HOME}/.cargo/config.toml
81+
82+
ENTRYPOINT [ "/bin/sccache" ]
83+
84+
CMD [ "/bin/sccache" ]
85+
86+
# vi: nospell

0 commit comments

Comments
 (0)