|
| 1 | +name: Docker |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + |
| 9 | +permissions: {} |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: Build and push dev image |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: read # required to read the repository contents |
| 21 | + packages: write # required to push the built image to the package registry |
| 22 | + attestations: write # required to create attestations for the built image |
| 23 | + id-token: write # required to create attestations for the built image |
| 24 | + pull-requests: write # required to comment on the pull request |
| 25 | + steps: |
| 26 | + - name: Create image tag |
| 27 | + id: image_tag |
| 28 | + shell: bash |
| 29 | + env: |
| 30 | + REPOSITORY: ${{ github.repository }} |
| 31 | + REF_NAME: ${{ github.ref_name }} |
| 32 | + COMMIT: ${{ github.sha }} |
| 33 | + run: | |
| 34 | + set -euo pipefail |
| 35 | + TAG="$(echo -n "dev-$REF_NAME-$COMMIT" | tr '[:upper:]' '[:lower:]' | tr -d '[:blank:]' | tr -c '[:alnum:]' '-')" |
| 36 | + echo "image tag: $TAG" |
| 37 | + echo "tag=ghcr.io/$REPOSITORY:$TAG" >> "$GITHUB_OUTPUT" |
| 38 | + - uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3 |
| 39 | + with: |
| 40 | + driver-opts: env.BUILDKIT_STEP_LOG_MAX_SIZE=-1,env.BUILDKIT_STEP_LOG_MAX_SPEED=-1 |
| 41 | + - name: Log into GHCR |
| 42 | + env: |
| 43 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + ACTOR: ${{ github.actor }} |
| 45 | + run: echo "$GITHUB_TOKEN" | docker login ghcr.io -u "$ACTOR" --password-stdin |
| 46 | + - name: docker build & push |
| 47 | + uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6 |
| 48 | + with: |
| 49 | + push: true |
| 50 | + tags: ${{ steps.image_tag.outputs.tag }} |
| 51 | + provenance: mode=max |
| 52 | + sbom: true |
| 53 | + - name: Comment on PR |
| 54 | + if: github.event_name == 'pull_request' |
| 55 | + uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2 |
| 56 | + continue-on-error: true # just check the actions log if ratelimits or whatever |
| 57 | + with: |
| 58 | + message: | |
| 59 | + :whale: Docker image built and pushed to GitHub Container Registry. |
| 60 | +
|
| 61 | + You can pull it using: |
| 62 | +
|
| 63 | + ```bash |
| 64 | + docker pull ${{ steps.image_tag.outputs.tag }} |
| 65 | + ``` |
| 66 | +
|
| 67 | + > [!WARNING] |
| 68 | + > This is a development image and should not be used in production. |
| 69 | + > It will be automatically removed after 2 weeks. |
0 commit comments