From 9d5a6636fbfc0ebff4228d43ff3eef7dd7457dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9on=20Boudier?= Date: Thu, 26 Nov 2026 14:05:02 +0100 Subject: [PATCH] feat(docker): build the erc7730 serve image and publish it to GHCR on release Co-Authored-By: Claude Opus 5.5 --- .dockerignore | 6 ++++ .github/workflows/release.yml | 53 +++++++++++++++++++++++++++++++++++ Dockerfile | 26 +++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..b8d4d4bc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +* +!pyproject.toml +!pdm.lock +!README.md +!LICENSE +!src/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 53abb974..80bc9c01 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,6 @@ name: ✨ release +# RC: `gh release create vX.Y.Z-rcN --prerelease --target ` publishes the image only, not the wheel on: release: types: [published] @@ -12,6 +13,7 @@ permissions: jobs: publish: name: publish artifacts + if: ${{ !github.event.release.prerelease }} timeout-minutes: 60 runs-on: public-ledgerhq-shared-small steps: @@ -60,3 +62,54 @@ jobs: uses: LedgerHQ/actions-security/actions/sign-blob@actions/sign-blob-1 with: path: dist + + image: + name: publish image + timeout-minutes: 30 + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout + timeout-minutes: 10 + uses: actions/checkout@v7 + + - name: Setup mise + timeout-minutes: 10 + uses: jdx/mise-action@v5.2.7 + + - name: Get versions + id: version + env: + TAG: ${{ github.event.release.tag_name }} + run: | + { + echo "version=${TAG#v}" + echo "pdm=$(mise current pdm)" + echo "python=$(mise current python)" + } >> "$GITHUB_OUTPUT" + + - name: Login to GitHub Container Registry + timeout-minutes: 10 + uses: docker/login-action@v4 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup buildx + timeout-minutes: 10 + uses: docker/setup-buildx-action@v4 + + - name: Build and push image + timeout-minutes: 20 + uses: docker/build-push-action@v7 + with: + context: . + build-args: | + VERSION=${{ steps.version.outputs.version }} + PDM_VERSION=${{ steps.version.outputs.pdm }} + PYTHON_VERSION=${{ steps.version.outputs.python }} + tags: ghcr.io/ledgerhq/python-erc7730:${{ steps.version.outputs.version }} + push: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..f556cdef --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +ARG PYTHON_VERSION + +FROM python:${PYTHON_VERSION:?}-slim AS builder + +WORKDIR /build +ARG PDM_VERSION +RUN pip install --no-cache-dir "pdm==${PDM_VERSION:?}" +COPY pyproject.toml pdm.lock ./ +RUN pdm export --prod --output requirements.txt \ + && python -m venv /venv \ + && /venv/bin/pip install --no-cache-dir --require-hashes --requirement requirements.txt + +COPY README.md LICENSE ./ +COPY src src +ARG VERSION +RUN PDM_PEP517_SCM_VERSION="${VERSION:?}" /venv/bin/pip install --no-cache-dir --no-deps . + +FROM python:${PYTHON_VERSION:?}-slim + +LABEL org.opencontainers.image.source=https://github.com/LedgerHQ/python-erc7730 +COPY --from=builder /venv /venv +ENV PATH=/venv/bin:$PATH +USER 65532:65532 +EXPOSE 8730 +ENTRYPOINT ["erc7730"] +CMD ["serve", "--host", "0.0.0.0", "--port", "8730"]