|
1 | 1 | # |
2 | 2 | name: Create and publish a Docker image |
3 | 3 |
|
4 | | -# Configures this workflow to run every time a change is pushed to the branch called `release`. |
| 4 | +# Runs on GitHub release creation (type: created) and manual dispatch. |
5 | 5 | on: |
6 | 6 | release: |
7 | 7 | types: [created] |
|
16 | 16 | jobs: |
17 | 17 | build-and-push-image: |
18 | 18 | runs-on: ubuntu-latest |
| 19 | + # Add timeout to prevent hanging builds |
| 20 | + timeout-minutes: 60 |
19 | 21 | # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. |
20 | 22 | permissions: |
21 | 23 | contents: read |
22 | 24 | packages: write |
23 | 25 | attestations: write |
24 | 26 | id-token: write |
25 | | - # |
26 | 27 | steps: |
27 | 28 | - name: Checkout repository |
28 | 29 | uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Free up disk space |
| 32 | + run: | |
| 33 | + echo "=== Before cleanup ===" |
| 34 | + df -h |
| 35 | + echo "=== Cleaning up disk space ===" |
| 36 | + sudo rm -rf /usr/share/dotnet |
| 37 | + sudo rm -rf /usr/local/lib/android |
| 38 | + sudo rm -rf /opt/ghc |
| 39 | + sudo rm -rf /opt/hostedtoolcache/CodeQL |
| 40 | + sudo docker image prune -a -f |
| 41 | + echo "=== After cleanup ===" |
| 42 | + df -h |
29 | 43 | # Uses the `docker/login-action` action to log in to the Container registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. |
30 | 44 | - name: Log in to the Container registry |
31 | 45 | uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 |
|
39 | 53 | uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 |
40 | 54 | with: |
41 | 55 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
42 | | - # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. |
43 | | - # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. |
44 | | - # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. |
| 56 | + # Set up Buildx (BuildKit) with log limits and constrained parallelism to avoid resource exhaustion. |
| 57 | + - name: Set up Docker Buildx |
| 58 | + id: buildx |
| 59 | + uses: docker/setup-buildx-action@v3 |
| 60 | + with: |
| 61 | + driver-opts: | |
| 62 | + env.BUILDKIT_STEP_LOG_MAX_SIZE=10485760 |
| 63 | + env.BUILDKIT_STEP_LOG_MAX_SPEED=10485760 |
| 64 | + config-inline: | |
| 65 | + [worker.oci] |
| 66 | + max-parallelism = 2 |
| 67 | + [worker.containerd] |
| 68 | + max-parallelism = 2 |
| 69 | +
|
| 70 | + # Build the image using the repository Dockerfile and push it to GHCR. |
| 71 | + # Uses `context` for build context; applies tags and labels from the metadata step (`meta`). |
| 72 | + # See usage docs: https://github.com/docker/build-push-action#usage |
45 | 73 | - name: Build and push Docker image |
46 | 74 | id: push |
47 | 75 | uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 |
|
50 | 78 | push: true |
51 | 79 | tags: ${{ steps.meta.outputs.tags }} |
52 | 80 | labels: ${{ steps.meta.outputs.labels }} |
| 81 | + # Increase build resources and add caching |
| 82 | + builder: ${{ steps.buildx.outputs.name }} |
| 83 | + cache-from: type=gha |
| 84 | + cache-to: type=gha,mode=max |
| 85 | + # Target platform (single-arch) |
| 86 | + platforms: linux/amd64 |
53 | 87 |
|
54 | | - # 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)." |
| 88 | + # Generate a build provenance attestation (supply chain security) and upload it with the image. |
55 | 89 | - name: Generate artifact attestation |
56 | 90 | uses: actions/attest-build-provenance@v1 |
57 | 91 | with: |
|
0 commit comments