-
Notifications
You must be signed in to change notification settings - Fork 82
feat: publish a polycli container image to GHCR on tag #963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| name: Publish Docker image | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| # Release tags only, so `latest` is never moved by an ad-hoc tag. | ||
| - "v*" | ||
|
|
||
| env: | ||
| REGISTRY: ghcr.io | ||
| IMAGE_NAME: 0xPolygon/polygon-cli | ||
|
|
||
| jobs: | ||
| build-and-push-image: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| attestations: write | ||
| id-token: write | ||
|
|
||
| steps: | ||
| # No QEMU needed: the Dockerfile cross-compiles on the native build | ||
| # platform and the final stage only COPYs the static binary. | ||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
Check failure on line 27 in .github/workflows/build_and_publish.yaml
|
||
|
minhd-vu marked this conversation as resolved.
Dismissed
|
||
|
|
||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| # Full history + tags so the Makefile's `git describe --tags` can stamp | ||
| # the version into the binary. | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Log in to the Container registry | ||
| uses: docker/login-action@v3 | ||
|
Check failure on line 37 in .github/workflows/build_and_publish.yaml
|
||
|
minhd-vu marked this conversation as resolved.
Dismissed
|
||
| with: | ||
| registry: ${{ env.REGISTRY }} | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Extract metadata (tags, labels) for Docker | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
|
Check failure on line 45 in .github/workflows/build_and_publish.yaml
|
||
|
minhd-vu marked this conversation as resolved.
Dismissed
|
||
| with: | ||
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
| tags: | | ||
| type=ref,event=tag | ||
| type=semver,pattern={{version}} | ||
| type=raw,value=latest,enable=${{ !contains(github.ref_name, '-') }} | ||
|
|
||
| - name: Build and push Docker image | ||
| id: push | ||
| uses: docker/build-push-action@v6 | ||
|
Check failure on line 55 in .github/workflows/build_and_publish.yaml
|
||
|
minhd-vu marked this conversation as resolved.
Dismissed
|
||
| with: | ||
| context: . | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
| platforms: linux/amd64,linux/arm64 | ||
|
|
||
| - name: Generate artifact attestation | ||
| uses: actions/attest-build-provenance@v2 | ||
| with: | ||
| subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
| subject-digest: ${{ steps.push.outputs.digest }} | ||
| push-to-registry: true | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Container image for polycli. Primarily to run `polycli p2p sensor` on | ||
| # Container-Optimized OS (no on-host Go toolchain), but usable for any polycli | ||
| # subcommand. | ||
| # | ||
| # The build stage always runs on the native BUILDPLATFORM and cross-compiles to | ||
| # the target arch. CGO is required (vectorized-poseidon-gold has no pure-Go | ||
| # path), so cross-compiling with a real C toolchain avoids the very slow QEMU | ||
| # emulation a per-platform native build would need. | ||
| FROM --platform=$BUILDPLATFORM golang:1.26 AS build | ||
|
|
||
| # TARGETARCH is provided automatically by buildx (amd64, arm64, ...). | ||
| ARG TARGETARCH | ||
|
|
||
| WORKDIR /src | ||
|
|
||
| # make reuses the Makefile's version stamping; gcc-aarch64-linux-gnu is the same | ||
| # cross compiler the release workflow (make cross) uses for arm64. amd64 uses the | ||
| # native gcc already in the golang image. NOTE: because vectorized-poseidon-gold | ||
| # compiles the amd64 path with -march=native, the amd64 image must be built on an | ||
| # amd64 host (true on the ubuntu-latest CI runner); arm64 cross-compiles cleanly. | ||
| RUN apt-get update \ | ||
| && apt-get install -y --no-install-recommends make gcc-aarch64-linux-gnu \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Cache modules first (same cache mount as the build step so they aren't | ||
| # downloaded twice on a cold build). | ||
| COPY go.mod go.sum ./ | ||
| RUN --mount=type=cache,target=/go/pkg/mod go mod download | ||
|
|
||
| COPY . . | ||
|
|
||
| # Cross-compile a static, version-stamped binary. git describe reads the tags | ||
| # from the build context — the publish workflow checks out with fetch-depth: 0. | ||
| # Build cache mounts keep re-tag builds fast. | ||
| RUN --mount=type=cache,target=/root/.cache/go-build \ | ||
| --mount=type=cache,target=/go/pkg/mod \ | ||
| GOARCH="$TARGETARCH" \ | ||
| CC="$([ "$TARGETARCH" = arm64 ] && echo aarch64-linux-gnu-gcc || echo gcc)" \ | ||
| make docker-build | ||
|
|
||
| # Staged empty dir so the final image's working directory is owned by the | ||
| # nonroot user (distroless has no shell to chown it there). | ||
| RUN mkdir -p /data | ||
|
|
||
| # The binary is fully static, so distroless/static (no glibc) is enough. | ||
| FROM gcr.io/distroless/static-debian12:nonroot | ||
|
Check warning on line 46 in Dockerfile
|
||
|
|
||
| # The sensor writes a nodes.json discovery cache to its working directory, so it | ||
| # must be owned by the nonroot runtime user (uid 65532). | ||
| COPY --from=build --chown=65532:65532 /data /data | ||
| WORKDIR /data | ||
|
|
||
| COPY --from=build /src/out/polycli /usr/local/bin/polycli | ||
|
|
||
| ENTRYPOINT ["/usr/local/bin/polycli"] | ||
Uh oh!
There was an error while loading. Please reload this page.