|
| 1 | +name: Build and push Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + workflow_dispatch: |
| 8 | + pull_request: |
| 9 | + |
| 10 | +jobs: |
| 11 | + # Build and push ALL events. We'll make sure to give the images |
| 12 | + # sensible tags, so there's no confusion around what's 'dev' builds |
| 13 | + # through PRs, and what's proper 'master' builds. |
| 14 | + # |
| 15 | + # Official GitHub docs on this: https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-docker-images |
| 16 | + build-push-docker: |
| 17 | + runs-on: ubuntu-latest-large |
| 18 | + # needed to push to GHCR |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + packages: write |
| 22 | + attestations: write |
| 23 | + id-token: write |
| 24 | + steps: |
| 25 | + - name: Docker meta |
| 26 | + id: meta |
| 27 | + # https://github.com/docker/metadata-action |
| 28 | + uses: docker/metadata-action@v5 |
| 29 | + with: |
| 30 | + images: | |
| 31 | + ghcr.io/${{ github.repository_owner }}/cpuminer |
| 32 | + # generate Docker tags based on the following events/attributes |
| 33 | + tags: | |
| 34 | + # creates a tag for each push |
| 35 | + type=sha,event=push |
| 36 | +
|
| 37 | + # creates a tag for each pr |
| 38 | + type=ref,event=pr |
| 39 | +
|
| 40 | + # set latest tag for default branch |
| 41 | + type=raw,value=latest,enable={{is_default_branch}} |
| 42 | +
|
| 43 | + - name: Set up Docker Buildx |
| 44 | + uses: docker/setup-buildx-action@v3 |
| 45 | + |
| 46 | + - name: Login to GHCR |
| 47 | + uses: docker/login-action@v3 |
| 48 | + with: |
| 49 | + registry: ghcr.io |
| 50 | + username: ${{ github.repository_owner }} |
| 51 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + |
| 53 | + - uses: actions/checkout@v4 |
| 54 | + with: |
| 55 | + submodules: "recursive" |
| 56 | + |
| 57 | + - name: Build (and maybe push) Docker image |
| 58 | + uses: docker/build-push-action@v6 |
| 59 | + with: |
| 60 | + # Only push if this is not a PR from a fork |
| 61 | + # prettier-ignore |
| 62 | + push: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }} |
| 63 | + tags: ${{ steps.meta.outputs.tags }} |
| 64 | + # Caching Docker builds on CI is an eternally |
| 65 | + # difficult task. From the official docs: |
| 66 | + # "In most cases you want to use the inline cache exporter" |
| 67 | + # |
| 68 | + # https://docs.docker.com/build/ci/github-actions/cache/#inline-cache |
| 69 | + # prettier-ignore |
| 70 | + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/bip300301_enforcer:latest |
| 71 | + cache-to: type=inline |
0 commit comments