From ebadab8f0603522945e7aaca4a3564b270de73d5 Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Sat, 9 May 2026 20:02:59 +0800 Subject: [PATCH] ci: publish docker images by digest --- .github/workflows/build.yaml | 88 +++++++++++++++++++++++ .github/workflows/publish-ppa.yaml | 17 ++++- .github/workflows/release.yaml | 110 ++++++++++++++++++++++++++++- 3 files changed, 211 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index d760829..e0b327f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -179,6 +179,63 @@ jobs: path: | build-gp-${{ matrix.package }}/artifacts/* + build-docker-image: + strategy: + fail-fast: false + matrix: + include: + - runner: ubuntu-latest + platform: linux/amd64 + - runner: ubuntu-24.04-arm + platform: linux/arm64 + runs-on: ${{ matrix.runner }} + steps: + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> "$GITHUB_ENV" + - name: Checkout GlobalProtect-openconnect + uses: actions/checkout@v6 + with: + token: ${{ secrets.GH_PAT }} + repository: yuezk/GlobalProtect-openconnect + ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} + submodules: recursive + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + - name: Login to Docker Hub + uses: docker/login-action@v4 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + - name: Build and push by digest + id: build + uses: docker/build-push-action@v7 + with: + context: . + file: packaging/docker/alpine/Dockerfile + platforms: ${{ matrix.platform }} + outputs: type=image,name=yuezk/globalprotect-openconnect,push-by-digest=true,name-canonical=true,push=true + - name: Verify CLI tools + env: + IMAGE: yuezk/globalprotect-openconnect + DIGEST: ${{ steps.build.outputs.digest }} + run: | + docker run --rm "$IMAGE@$DIGEST" --help + docker run --rm --entrypoint gpauth "$IMAGE@$DIGEST" --help + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + - name: Upload digest + uses: actions/upload-artifact@v7 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + build-gpgui: needs: - setup-matrix @@ -251,6 +308,7 @@ jobs: - tarball - tarball-offline - build-gp + - build-docker-image - build-gpgui steps: @@ -277,3 +335,33 @@ jobs: RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && 'snapshot' || github.ref_name }} run: | cd gh-release/gp/scripts && ./gh-release.sh "$RELEASE_TAG" + + publish-docker-image: + needs: + - build-docker-image + if: ${{ github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/') }} + runs-on: ubuntu-latest + steps: + - name: Download digests + uses: actions/download-artifact@v8 + with: + path: /tmp/digests + pattern: digests-* + merge-multiple: true + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + - name: Login to Docker Hub + uses: docker/login-action@v4 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + - name: Publish Docker manifest + working-directory: /tmp/digests + env: + IMAGE: yuezk/globalprotect-openconnect + RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && 'snapshot' || github.ref_name }} + run: | + docker buildx imagetools create -t "$IMAGE:$RELEASE_TAG" \ + $(printf "$IMAGE@sha256:%s " *) + + docker buildx imagetools inspect "$IMAGE:$RELEASE_TAG" diff --git a/.github/workflows/publish-ppa.yaml b/.github/workflows/publish-ppa.yaml index dfa16f9..d682a3d 100644 --- a/.github/workflows/publish-ppa.yaml +++ b/.github/workflows/publish-ppa.yaml @@ -79,13 +79,24 @@ jobs: needs: [check, resolve-series] name: publish-ppa (${{ matrix.series }}) runs-on: ubuntu-latest + container: + image: ubuntu:${{ matrix.series }} strategy: fail-fast: false matrix: ${{ fromJSON(needs.resolve-series.outputs.matrix) }} steps: - - uses: pnpm/action-setup@v5 - with: - version: 9 + - name: Install container tools + run: | + apt-get update + apt-get install -y ca-certificates curl gpg sudo + mkdir -p /etc/apt/keyrings + curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \ + | gpg --dearmor -o /etc/apt/keyrings/githubcli-archive-keyring.gpg + chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \ + > /etc/apt/sources.list.d/github-cli.list + apt-get update + apt-get install -y gh - name: Prepare workspace run: rm -rf publish-ppa && mkdir publish-ppa - name: Download ${{ inputs.tag }} offline source code diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 13054b9..c40f78d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -40,6 +40,11 @@ on: description: 'Build binary package' required: true default: true + release-docker: + type: boolean + description: 'Publish Docker image' + required: true + default: true gh-release: type: boolean description: 'Update GitHub release' @@ -84,7 +89,7 @@ jobs: } const package = Object.entries(inputs) - .filter(([key, value]) => key.startsWith('release-') && value) + .filter(([key, value]) => key.startsWith('release-') && key !== 'release-docker' && value) .map(([key, value]) => key.replace('release-', '')) return JSON.stringify({ @@ -139,6 +144,109 @@ jobs: path: | build-${{ matrix.package }}/artifacts/* + build-docker-image: + needs: + - check + if: ${{ inputs.release-docker }} + strategy: + fail-fast: false + matrix: + include: + - runner: ubuntu-latest + platform: linux/amd64 + - runner: ubuntu-24.04-arm + platform: linux/arm64 + runs-on: ${{ matrix.runner }} + steps: + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> "$GITHUB_ENV" + - name: Prepare workspace + run: rm -rf docker-image && mkdir -p docker-image/source + + - name: Download ${{ inputs.tag }} source code + env: + GH_TOKEN: ${{ secrets.GH_PAT }} + run: | + gh -R yuezk/GlobalProtect-openconnect \ + release download ${{ inputs.tag }} \ + --pattern '*[^offline].tar.gz' \ + --dir docker-image + tar -xzf docker-image/*.tar.gz -C docker-image/source --strip-components=1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + - name: Login to Docker Hub + uses: docker/login-action@v4 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + - name: Build and push by digest + id: build + uses: docker/build-push-action@v7 + with: + context: docker-image/source + file: docker-image/source/packaging/docker/alpine/Dockerfile + platforms: ${{ matrix.platform }} + outputs: type=image,name=yuezk/globalprotect-openconnect,push-by-digest=true,name-canonical=true,push=true + - name: Verify CLI tools + env: + IMAGE: yuezk/globalprotect-openconnect + DIGEST: ${{ steps.build.outputs.digest }} + run: | + docker run --rm "$IMAGE@$DIGEST" --help + docker run --rm --entrypoint gpauth "$IMAGE@$DIGEST" --help + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + - name: Upload digest + uses: actions/upload-artifact@v7 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + publish-docker-image: + needs: + - build-docker-image + if: ${{ inputs.release-docker }} + runs-on: ubuntu-latest + steps: + - name: Download digests + uses: actions/download-artifact@v8 + with: + path: /tmp/digests + pattern: digests-* + merge-multiple: true + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + - name: Login to Docker Hub + uses: docker/login-action@v4 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + - name: Publish Docker manifest + working-directory: /tmp/digests + env: + IMAGE: yuezk/globalprotect-openconnect + TAG: ${{ inputs.tag }} + run: | + VERSION="${TAG#v}" + tags=(-t "$IMAGE:$TAG") + + if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + tags+=(-t "$IMAGE:$VERSION" -t "$IMAGE:latest") + fi + + docker buildx imagetools create "${tags[@]}" \ + $(printf "$IMAGE@sha256:%s " *) + + docker buildx imagetools inspect "$IMAGE:$TAG" + gh-release: needs: - build