|
| 1 | +name: Build and push container image |
| 2 | + |
| 3 | +# Configures this workflow to run every time a tag is created |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + - docker-ci |
| 9 | + paths: |
| 10 | + - agent/** |
| 11 | + - .github/workflows/build_agent_container.yaml |
| 12 | + |
| 13 | +# NOTE: we may want to switch to matrix build for multi-platform support if this is taking too long |
| 14 | +# https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners |
| 15 | + |
| 16 | + |
| 17 | +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. |
| 18 | +env: |
| 19 | + REGISTRY: ghcr.io |
| 20 | + IMAGE_NAME: ${{ github.repository }} |
| 21 | + |
| 22 | +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. |
| 23 | +jobs: |
| 24 | + build-and-push-image: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. |
| 27 | + permissions: |
| 28 | + contents: read |
| 29 | + packages: write |
| 30 | + attestations: write |
| 31 | + id-token: write |
| 32 | + # |
| 33 | + steps: |
| 34 | + - name: Checkout repository |
| 35 | + uses: actions/checkout@v4 |
| 36 | + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. |
| 37 | + - name: Log in to the Container registry |
| 38 | + uses: docker/login-action@v3 |
| 39 | + with: |
| 40 | + registry: ${{ env.REGISTRY }} |
| 41 | + username: ${{ github.actor }} |
| 42 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + |
| 44 | + # Setup for multi-platform |
| 45 | + - name: Set up QEMU |
| 46 | + uses: docker/setup-qemu-action@v3 |
| 47 | + |
| 48 | + - name: Set up Docker Buildx |
| 49 | + uses: docker/setup-buildx-action@v3 |
| 50 | + |
| 51 | + - name: Check outputs |
| 52 | + run: cd agent && make docker-build-only |
| 53 | + env: |
| 54 | + AGENT_IMAGE: ${{env.IMAGE_NAME}}/agent |
| 55 | + TAGS: ${{ env.REGISTRY }}/${{env.IMAGE_NAME}}/agent:${{ env.GITHUB_SHA }} |
| 56 | + |
| 57 | + # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds). |
| 58 | + - name: Generate artifact attestation |
| 59 | + uses: actions/attest-build-provenance@v2 |
| 60 | + with: |
| 61 | + subject-name: ${{ env.REGISTRY }}/${{env.IMAGE_NAME}}/agent |
| 62 | + subject-digest: ${{ steps.push.outputs.digest }} |
| 63 | + push-to-registry: true |
| 64 | + |
0 commit comments