Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
87 lines (68 loc) · 3.44 KB
/
Copy pathDockerfile
File metadata and controls
87 lines (68 loc) · 3.44 KB
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
82
83
84
85
86
87
# syntax=docker.io/docker/dockerfile:1
# The builder runs natively on the build machine and cross-compiles for the
# target platform, so images for other architectures do not have to be built
# under QEMU emulation.
FROM --platform=$BUILDPLATFORM docker.io/rust:1-slim-trixie AS builder
WORKDIR /app
RUN rm -f /etc/apt/apt.conf.d/docker-clean \
&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
ARG BUILDARCH TARGETARCH TARGETVARIANT
# Install a Debian cross toolchain for the target (the native one is already
# there) and write the environment that points cargo and cc at it.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
case "${TARGETARCH}${TARGETVARIANT}" in \
386) rust=i686-unknown-linux-gnu gnu=i686-linux-gnu deb=i386 ;; \
amd64) rust=x86_64-unknown-linux-gnu gnu=x86_64-linux-gnu deb=amd64 ;; \
armv7) rust=armv7-unknown-linux-gnueabihf gnu=arm-linux-gnueabihf deb=armhf ;; \
arm64) rust=aarch64-unknown-linux-gnu gnu=aarch64-linux-gnu deb=arm64 ;; \
ppc64le) rust=powerpc64le-unknown-linux-gnu gnu=powerpc64le-linux-gnu deb=ppc64el ;; \
riscv64) rust=riscv64gc-unknown-linux-gnu gnu=riscv64-linux-gnu deb=riscv64 ;; \
s390x) rust=s390x-unknown-linux-gnu gnu=s390x-linux-gnu deb=s390x ;; \
*) echo "Unsupported platform: ${TARGETARCH}${TARGETVARIANT}" >&2 && exit 1 ;; \
esac \
&& packages="cmake make" \
&& if [ "${TARGETARCH}" != "${BUILDARCH}" ]; then \
packages="${packages} gcc-$(echo "${gnu}" | tr _ -) libc6-dev-${deb}-cross"; \
fi \
&& apt-get update \
&& apt-get install -y --no-install-recommends ${packages} \
&& rustup target add "${rust}" \
&& env_rust="$(echo "${rust}" | tr a-z- A-Z_)" \
&& { \
echo "export CARGO_BUILD_TARGET=${rust}"; \
echo "export CARGO_TARGET_${env_rust}_LINKER=${gnu}-gcc"; \
echo "export CC_$(echo "${rust}" | tr - _)=${gnu}-gcc"; \
echo "export AR_$(echo "${rust}" | tr - _)=${gnu}-ar"; \
} > /etc/cross-env
ARG TARGETPLATFORM
RUN --mount=source=src,target=src \
--mount=source=Cargo.toml,target=Cargo.toml \
--mount=source=Cargo.lock,target=Cargo.lock \
--mount=type=cache,id=proxy-scraper-checker-target-${TARGETPLATFORM},target=/app/target,sharing=locked \
--mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
. /etc/cross-env \
&& cargo build --release --locked \
&& cp "target/${CARGO_BUILD_TARGET}/release/proxy-scraper-checker" .
FROM docker.io/debian:trixie-slim AS final
WORKDIR /app
RUN rm -f /etc/apt/apt.conf.d/docker-clean \
&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates
ARG \
UID=1000 \
GID=1000
# UID and GID come from the host and can be anything, 0 and IDs the image uses included.
RUN groupadd --non-unique --gid "${GID}" app \
&& useradd --gid "${GID}" --no-log-init --create-home --non-unique --uid "${UID}" app \
&& mkdir -p /home/app/.cache/proxy_scraper_checker \
&& chown "${UID}:${GID}" /home/app/.cache/proxy_scraper_checker
# Docker finds the home by UID, and that may belong to a user of the image.
ENV HOME=/home/app
COPY --link LICENSE* ./
COPY --from=builder --link /app/proxy-scraper-checker .
USER app
CMD ["/app/proxy-scraper-checker"]