From 4260629751818164ab458ea1a3cb53e5ea1d06fa Mon Sep 17 00:00:00 2001 From: New Future Date: Tue, 27 May 2025 09:14:27 +0800 Subject: [PATCH 1/3] docker build multi-arch (#457) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * full arch support: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/riscv64,linux/s390x * 启动立即执行一次 #451 break changes: * 二进制 ddns 文件移到到 /bin/ddns #451 * 启动workdir /ddns * 默认配置文件 /ddns/config.json --- .build/Dockerfile | 13 +++++++++++++ entrypoint.sh => .build/entrypoint.sh | 5 +++-- .build/nuitka.cmd | 2 +- .github/workflows/build.yml | 8 +++++--- .github/workflows/publish.yml | 6 ++++-- Dockerfile | 10 ---------- run.py | 3 +-- 7 files changed, 27 insertions(+), 20 deletions(-) create mode 100755 .build/Dockerfile rename entrypoint.sh => .build/entrypoint.sh (63%) delete mode 100755 Dockerfile diff --git a/.build/Dockerfile b/.build/Dockerfile new file mode 100755 index 000000000..76b376d5b --- /dev/null +++ b/.build/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:latest +WORKDIR /app +COPY . . +RUN apk add --no-cache python3 py3-pip python3-dev patchelf build-base +RUN pip3 install -U nuitka --break-system-packages +RUN .build/nuitka.cmd + +FROM alpine:latest +LABEL maintainer="NN708, newfuture" +WORKDIR /ddns +COPY --from=0 /app/.build/entrypoint.sh / +COPY --from=0 /app/dist/ddns /bin/ +ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/entrypoint.sh b/.build/entrypoint.sh similarity index 63% rename from entrypoint.sh rename to .build/entrypoint.sh index c697c6b85..765dc8e3d 100755 --- a/entrypoint.sh +++ b/.build/entrypoint.sh @@ -2,12 +2,13 @@ if [ $# -eq 0 ]; then printenv > /etc/environment - echo "*/5 * * * * /ddns -c /config.json" > /etc/crontabs/root + echo "*/5 * * * * cd /ddns && /bin/ddns" > /etc/crontabs/root + /bin/ddns exec crond -f else first=`echo $1 | cut -c1` if [ "$first" = "-" ]; then - exec /ddns $@ + exec /bin/ddns $@ else exec $@ fi diff --git a/.build/nuitka.cmd b/.build/nuitka.cmd index bb2f88721..c12673744 100755 --- a/.build/nuitka.cmd +++ b/.build/nuitka.cmd @@ -1 +1 @@ -nuitka --standalone --onefile --output-dir=./dist --output-filename=ddns --remove-output --include-module=dns.dnspod --include-module=dns.alidns --include-module=dns.dnspod_com --include-module=dns.dnscom --include-module=dns.cloudflare --include-module=dns.he --include-module=dns.huaweidns --include-module=dns.callback --macos-app-name="DDNS" --product-name=DDNS --file-description="DDNS Client 自动更新域名解析到本机IP" --company-name="New Future" --copyright="https://ddns.newfuture.cc" --windows-icon-from-ico="favicon.ico" --linux-icon=".build/icon.png" --macos-app-icon=".build/icon.png" --assume-yes-for-downloads run.py \ No newline at end of file +nuitka run.py --standalone --onefile --output-dir=./dist --no-deployment-flag=self-execution --output-filename=ddns --remove-output --include-module=dns.dnspod --include-module=dns.alidns --include-module=dns.dnspod_com --include-module=dns.dnscom --include-module=dns.cloudflare --include-module=dns.he --include-module=dns.huaweidns --include-module=dns.callback --product-name=DDNS --file-description="DDNS Client 自动更新域名解析到本机IP" --company-name="New Future" --copyright="https://ddns.newfuture.cc" --windows-icon-from-ico="favicon.ico" --assume-yes-for-downloads --lto=yes \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 78c64846f..db470c821 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -121,13 +121,14 @@ jobs: if: runner.os == 'Linux' run: | sudo apt-get update && sudo apt install -y patchelf ccache + echo " --static-libpython=yes --linux-icon=.build/icon.png" >> .build/nuitka.cmd cp /etc/ssl/certs/ca-certificates.crt cert.pem && export SSL_CERT_FILE=${PWD}/cert.pem - name: setup on macOS if: runner.os == 'macOS' run: | python3 -m pip install imageio - + echo " --macos-app-name=DDNS --macos-app-icon=.build/icon.png" >> .build/nuitka.cmd - run: python ./run.py -h @@ -154,6 +155,7 @@ jobs: with: context: . load: true + file: .build/Dockerfile tags: ddns:test - name: test help command run: docker run --rm ddns:test -h @@ -189,8 +191,7 @@ jobs: name: preview url: https://github.com/NewFuture/DDNS/pkgs/container/ddns/?tag=master env: - arch: linux/amd64,linux/arm,linux/arm64 - # arch: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/riscv64,linux/s390x + arch: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/riscv64,linux/s390x permissions: packages: write steps: @@ -218,6 +219,7 @@ jobs: - uses: docker/build-push-action@v6 with: context: . + file: .build/Dockerfile platforms: ${{ env.arch }} push: true tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 98bda1ad9..a3f27ffb3 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,8 +18,7 @@ jobs: packages: write env: DOCKER_BUILD_RECORD_UPLOAD: false - arch: linux/amd64,linux/arm,linux/arm64 - # arch: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/riscv64,linux/s390x + arch: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/riscv64,linux/s390x steps: - uses: actions/checkout@v4 - run: sed -i -e "s#\${BUILD_VERSION}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py @@ -45,6 +44,7 @@ jobs: - uses: docker/build-push-action@v6 with: context: . + file: .build/Dockerfile platforms: ${{ env.arch }} push: true tags: ${{ steps.meta.outputs.tags }} @@ -98,12 +98,14 @@ jobs: if: runner.os == 'Linux' run: | apt-get update && apt install -y patchelf ccache + echo " --static-libpython=yes --linux-icon=.build/icon.png" >> .build/nuitka.cmd cp /etc/ssl/certs/ca-certificates.crt cert.pem && export SSL_CERT_FILE=${PWD}/cert.pem - name: setup on macOS if: runner.os == 'macOS' run: | python3 -m pip install imageio + echo " --macos-app-name=DDNS --macos-app-icon=.build/icon.png" >> .build/nuitka.cmd - name: Package binary run: ./.build/nuitka.cmd diff --git a/Dockerfile b/Dockerfile deleted file mode 100755 index ed3bfdf9d..000000000 --- a/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM six8/pyinstaller-alpine:alpine-3.6-pyinstaller-v3.4 -WORKDIR /app -COPY . . -RUN pyinstaller --onefile --noconfirm --clean ./.build/ddns.spec - -FROM alpine:latest -LABEL maintainer="NN708" -COPY --from=0 /app/entrypoint.sh / -COPY --from=0 /app/dist/ddns / -ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/run.py b/run.py index d792ecb49..b91975abf 100755 --- a/run.py +++ b/run.py @@ -5,8 +5,7 @@ @author: New Future @modified: rufengsuixing """ -# nuitka-project-if: {OS} == "Linux": -# nuitka-project: --static-libpython=yes + # nuitka-project-if: os.getenv("BUILD_VERSION") is not None: # nuitka-project: --product-version=${BUILD_VERSION} # nuitka-project-else: From 6c0dccfbe0c9633d9340e2313f94996b643b63cb Mon Sep 17 00:00:00 2001 From: New Future Date: Tue, 27 May 2025 09:37:10 +0800 Subject: [PATCH 2/3] fix docker release job --- .github/workflows/build.yml | 2 +- .github/workflows/publish.yml | 2 +- README.md | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index db470c821..b936278a0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -185,7 +185,7 @@ jobs: preview-docker: runs-on: ubuntu-latest if: github.event_name == 'push' - timeout-minutes: 5 + timeout-minutes: 12 needs: [docker] environment: name: preview diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a3f27ffb3..3847d9a0e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,7 +10,7 @@ permissions: jobs: publish-docker: runs-on: ubuntu-latest - timeout-minutes: 5 + timeout-minutes: 15 environment: name: publish url: https://hub.docker.com/r/newfuture/ddns diff --git a/README.md b/README.md index 1e3e7f39b..d9c86121d 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ - [x] 多系统兼容 ![cross platform](https://img.shields.io/badge/platform-windows_%7C%20linux_%7C%20osx-success.svg?style=social) - [x] python3 支持 ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ddns.svg?style=social)(2.x支持python2和python3) - [x] PIP 安装 ![PyPI - Wheel](https://img.shields.io/pypi/wheel/ddns.svg?style=social) - - [x] Docker 支持(@NN708) + - [x] Docker 支持(@NN708) - 域名支持: - [x] 多个域名支持 - [x] 多级域名解析 @@ -71,10 +71,10 @@ --network host \ newfuture/ddns ``` - - 使用配置文件: + - 使用配置文件(docker 工作目录`/ddds/`,默认配置位置`/ddns/config.json`): ``` docker run -d \ - -v /path/to/config.json:/config.json \ + -v /local/config/path/:/ddns/ \ --network host \ newfuture/ddns ``` From e5eab2a5fa62e574e9183a32299d247e159ce292 Mon Sep 17 00:00:00 2001 From: New Future Date: Tue, 27 May 2025 02:12:15 +0000 Subject: [PATCH 3/3] add libffi-dev --- .build/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.build/Dockerfile b/.build/Dockerfile index 76b376d5b..a3d62482b 100755 --- a/.build/Dockerfile +++ b/.build/Dockerfile @@ -1,7 +1,7 @@ FROM alpine:latest WORKDIR /app COPY . . -RUN apk add --no-cache python3 py3-pip python3-dev patchelf build-base +RUN apk add --no-cache python3 py3-pip python3-dev patchelf build-base libffi-dev RUN pip3 install -U nuitka --break-system-packages RUN .build/nuitka.cmd