diff --git a/.github/workflows/container_latest.yml b/.github/workflows/container_latest.yml index 27e131a52..05a1b4f89 100644 --- a/.github/workflows/container_latest.yml +++ b/.github/workflows/container_latest.yml @@ -23,15 +23,22 @@ on: - all - standard - large_disk + publish: + description: 'Publish images and manifests' + required: true + type: boolean + default: false permissions: contents: read + security-events: write jobs: setup: runs-on: ubuntu-latest outputs: variants: ${{ steps.set-variants.outputs.variants }} + publish: ${{ steps.set-publish.outputs.publish }} steps: - name: Select variants for this run id: set-variants @@ -42,6 +49,14 @@ jobs: variants='["standard","large_disk"]' fi echo "variants=$variants" >> "$GITHUB_OUTPUT" + - name: Select publish mode + id: set-publish + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "publish=${{ github.event.inputs.publish }}" >> "$GITHUB_OUTPUT" + else + echo "publish=true" >> "$GITHUB_OUTPUT" + fi build: needs: [setup] @@ -111,13 +126,13 @@ jobs: buildkitd-flags: "--debug" buildkitd-config: /tmp/buildkitd.toml - name: Login to Docker Hub - if: github.event_name != 'pull_request' + if: needs.setup.outputs.publish == 'true' uses: docker/login-action@v4 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to GHCR - if: github.event_name != 'pull_request' + if: needs.setup.outputs.publish == 'true' uses: docker/login-action@v4 with: registry: ghcr.io @@ -129,7 +144,7 @@ jobs: DOCKER_BUILDKIT: 1 with: context: ./docker - push: ${{ github.event_name != 'pull_request' }} + push: ${{ needs.setup.outputs.publish == 'true' }} file: ./docker/Dockerfile.go_build platforms: linux/${{ matrix.platform }} # Push to GHCR only during build to avoid Docker Hub rate limits @@ -149,10 +164,128 @@ jobs: # Remove Go build cache sudo rm -rf /tmp/go-build* - create-manifest: + trivy-scan: runs-on: ubuntu-latest needs: [setup, build] - if: github.event_name != 'pull_request' + strategy: + matrix: + variant: ${{ fromJSON(needs.setup.outputs.variants) }} + steps: + - name: Configure variant + id: config + run: | + if [ "${{ matrix.variant }}" == "large_disk" ]; then + echo "tag_suffix=_large_disk" >> $GITHUB_OUTPUT + else + echo "tag_suffix=" >> $GITHUB_OUTPUT + fi + - name: Login to GHCR + if: needs.setup.outputs.publish == 'true' + uses: docker/login-action@v4 + with: + registry: ghcr.io + username: ${{ secrets.GHCR_USERNAME }} + password: ${{ secrets.GHCR_TOKEN }} + - name: Checkout for local scan build + if: needs.setup.outputs.publish != 'true' + uses: actions/checkout@v6 + with: + ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.source_ref || github.ref }} + - name: Create BuildKit config for local scan build + if: needs.setup.outputs.publish != 'true' + run: | + cat > /tmp/buildkitd.toml <