Files
DDNS/docker/Dockerfile
T
dd16df78b7 ci(build): persist incremental compiler caches (#730)
* ci(build): persist compiler caches

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* ci(build): restrict compiler cache writes

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: NewFuture <6290356+NewFuture@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-08-17 14:13:55 +08:00

77 lines
3.5 KiB
Docker
Executable File

# https://alpinelinux.org/releases/
# https://hub.docker.com/_/alpine/tags
ARG HOST_VERSION=3.20
# prebuilt image to speed up to speed up: ghcr.io/newfuture/nuitka-buider:master
ARG BUILDER=base-builder
ARG PATCHELF_VERSION=0.19.1
ARG PYTHON_VERSION=3.8
ARG NUITKA_VERSION=main # 新增此行,定义构建参数并提供默认值
# https://hub.docker.com/_/python/tags?name=3.8-alpine3.20
FROM python:${PYTHON_VERSION}-alpine${HOST_VERSION} AS base-builder
# RUN apk add --no-cache python3-dev py3-pip py3-cffi py3-zstandard py3-ordered-set patchelf clang ccache
RUN apk add --no-cache patchelf gcc ccache libffi-dev build-base zstd-libs\
&& rm -rf /var/lib/apt/lists/* /var/cache/* /tmp/* /var/log/*
ARG PATCHELF_VERSION
RUN wget -O /tmp/patchelf.tar.gz "https://github.com/NixOS/patchelf/releases/download/${PATCHELF_VERSION}/patchelf-${PATCHELF_VERSION}.tar.gz" \
&& tar -xzf /tmp/patchelf.tar.gz -C /tmp \
&& cd "/tmp/patchelf-${PATCHELF_VERSION}" \
&& ./configure --prefix=/usr/local \
&& make -j"$(nproc)" \
&& make install \
&& rm -rf /tmp/patchelf.tar.gz "/tmp/patchelf-${PATCHELF_VERSION}"
ARG NUITKA_VERSION
RUN python3 -m pip install --no-cache-dir --prefer-binary \
"Nuitka[onefile] @ https://github.com/Nuitka/Nuitka/archive/${NUITKA_VERSION}.zip" \
--disable-pip-version-check \
--break-system-packages \
&& rm -rf /var/cache/* /tmp/* /var/log/* /root/.cache
WORKDIR /app
FROM alpine:${HOST_VERSION} AS base
RUN find /lib /usr/lib /usr/local/lib -name '*.so*' | sed 's|.*/||' | awk '{print "--noinclude-dlls="$0}' > nuitka_exclude_so.txt
FROM ${BUILDER} AS builder
ARG PATCHELF_VERSION
ARG TARGETARCH
ARG TARGETVARIANT
COPY run.py .
COPY ddns ddns
COPY web web
COPY --from=base /nuitka_exclude_so.txt nuitka_exclude_so.txt
RUN if patchelf --version 2>/dev/null | grep -q ' 0[.]18[.]0$'; then \
wget -O /tmp/patchelf.tar.gz "https://github.com/NixOS/patchelf/releases/download/${PATCHELF_VERSION}/patchelf-${PATCHELF_VERSION}.tar.gz" \
&& tar -xzf /tmp/patchelf.tar.gz -C /tmp \
&& cd "/tmp/patchelf-${PATCHELF_VERSION}" \
&& ./configure --prefix=/usr/local \
&& make -j"$(nproc)" \
&& make install \
&& rm -rf /tmp/patchelf.tar.gz "/tmp/patchelf-${PATCHELF_VERSION}"; \
fi
RUN --mount=type=cache,target=/root/.cache/ccache,sharing=shared \
--mount=type=cache,target=/root/.cache/nuitka-module,sharing=shared \
cache_subdir="${TARGETARCH}${TARGETVARIANT:+-${TARGETVARIANT}}" \
&& export CCACHE_DIR="/root/.cache/ccache/${cache_subdir}" \
&& export NUITKA_CACHE_DIR_MODULE_CACHE="/root/.cache/nuitka-module/${cache_subdir}" \
&& mkdir -p "${CCACHE_DIR}" "${NUITKA_CACHE_DIR_MODULE_CACHE}" \
&& ccache --set-config=compiler_check=content \
&& ccache --set-config=compression=true \
&& ccache --set-config=compression_level=6 \
&& ccache --set-config=max_size=1G \
&& echo "Nuitka module cache files before build: $(find "${NUITKA_CACHE_DIR_MODULE_CACHE}" -type f | wc -l)" \
&& python3 -O -m nuitka run.py \
--remove-output \
--lto=yes \
$(cat nuitka_exclude_so.txt) \
&& echo "Nuitka module cache files after build: $(find "${NUITKA_CACHE_DIR_MODULE_CACHE}" -type f | wc -l)" \
&& ccache --show-stats
RUN mkdir /output && cp dist/ddns /output/
COPY docker/entrypoint.sh /output/
FROM alpine:${HOST_VERSION}
RUN apk add --no-cache tini
COPY --from=builder /output/* /bin/
WORKDIR /ddns
ENTRYPOINT [ "/sbin/tini", "-g", "--", "/bin/entrypoint.sh" ]