Build and Push Docker Images (Development) #261
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push Docker Images (Development) | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_run: | |
| workflows: ["Update Vulnerability Feeds"] | |
| types: | |
| - completed | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| # Skip release commits (release.yml handles Docker) and failed workflow_run | |
| if: >- | |
| github.event_name == 'workflow_dispatch' || | |
| (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || | |
| (github.event_name == 'push' && !contains(github.event.head_commit.message, 'chore(release):')) | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| attestations: write | |
| strategy: | |
| matrix: | |
| include: | |
| - dockerfile: Dockerfile | |
| suffix: "" | |
| feed_ecosystems: "npm" | |
| description: "Full version with npm GHSA and OSV vulnerability feeds (~43MB)" | |
| - dockerfile: Dockerfile | |
| suffix: "-all" | |
| feed_ecosystems: "all" | |
| description: "Full version with GHSA and OSV feeds for all supported ecosystems" | |
| - dockerfile: Dockerfile.lite | |
| suffix: "-lite" | |
| feed_ecosystems: "npm" | |
| description: "Lightweight version without vulnerability data (~27MB)" | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}${{ matrix.suffix }} | |
| tags: | | |
| type=ref,event=branch | |
| type=raw,value=dev,enable={{is_default_branch}} | |
| type=sha,prefix= | |
| labels: | | |
| org.opencontainers.image.title=package-checker.sh${{ matrix.suffix }} | |
| org.opencontainers.image.description=${{ matrix.description }} | |
| org.opencontainers.image.vendor=${{ github.repository_owner }} | |
| - name: Build and push Docker image | |
| id: push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ${{ matrix.dockerfile }} | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| platforms: linux/amd64,linux/arm64 | |
| build-args: | | |
| VERSION=dev | |
| FEED_ECOSYSTEMS=${{ matrix.feed_ecosystems }} | |
| - name: Generate artifact attestation | |
| uses: actions/attest-build-provenance@v1 | |
| with: | |
| subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}${{ matrix.suffix }} | |
| subject-digest: ${{ steps.push.outputs.digest }} | |
| push-to-registry: true |