|
| 1 | +on: |
| 2 | + workflow_call: |
| 3 | + inputs: |
| 4 | + publish: |
| 5 | + type: boolean |
| 6 | + description: If true, pushes image to container registry |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + # Need this to get version number from last tag |
| 17 | + fetch-depth: 0 |
| 18 | + |
| 19 | + - name: Set up Docker Buildx |
| 20 | + id: buildx |
| 21 | + uses: docker/setup-buildx-action@v3 |
| 22 | + |
| 23 | + - name: Log in to GitHub Docker Registry |
| 24 | + if: github.event_name != 'pull_request' |
| 25 | + uses: docker/login-action@v3 |
| 26 | + with: |
| 27 | + registry: ghcr.io |
| 28 | + username: ${{ github.actor }} |
| 29 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + |
| 31 | + - name: Build and export to Docker local cache |
| 32 | + uses: docker/build-push-action@v6 |
| 33 | + env: |
| 34 | + DOCKER_BUILD_RECORD_UPLOAD: false |
| 35 | + with: |
| 36 | + context: . |
| 37 | + # Need load and tags so we can test it below |
| 38 | + load: true |
| 39 | + tags: tag_for_testing |
| 40 | + |
| 41 | + - name: Test cli works in cached runtime image |
| 42 | + run: docker run --rm tag_for_testing --version |
| 43 | + |
| 44 | + - name: Create tags for publishing image |
| 45 | + id: meta |
| 46 | + uses: docker/metadata-action@v5 |
| 47 | + with: |
| 48 | + images: ghcr.io/${{ github.repository }} |
| 49 | + tags: | |
| 50 | + type=ref,event=tag |
| 51 | + type=raw,value=latest |
| 52 | +
|
| 53 | + - name: Push cached image to container registry |
| 54 | + if: inputs.publish && github.ref_type == 'tag' |
| 55 | + uses: docker/build-push-action@v6 |
| 56 | + env: |
| 57 | + DOCKER_BUILD_RECORD_UPLOAD: false |
| 58 | + # This does not build the image again, it will find the image in the |
| 59 | + # Docker cache and publish it |
| 60 | + with: |
| 61 | + context: . |
| 62 | + push: true |
| 63 | + tags: ${{ steps.meta.outputs.tags }} |
| 64 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments