|
| 1 | +# copied this from https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages |
| 2 | +# made some tweaks for the version numbers on actions to be simpler |
| 3 | +name: Create and publish a Docker image |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: ['release'] |
| 8 | + |
| 9 | +env: |
| 10 | + REGISTRY: ghcr.io |
| 11 | + IMAGE_NAME: ${{ github.repository }} |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-push-image: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + contents: read |
| 18 | + packages: write |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + # 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. |
| 23 | + - name: Log in to the Container registry |
| 24 | + uses: docker/login-action@v3 |
| 25 | + with: |
| 26 | + registry: ${{ env.REGISTRY }} |
| 27 | + username: ${{ github.actor }} |
| 28 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. |
| 30 | + - name: Extract metadata (tags, labels) for Docker |
| 31 | + id: meta |
| 32 | + uses: docker/metadata-action@v5 |
| 33 | + with: |
| 34 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 35 | + # 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. |
| 36 | + # 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. |
| 37 | + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. |
| 38 | + - name: Build and push Docker image |
| 39 | + uses: docker/build-push-action@v5 |
| 40 | + with: |
| 41 | + context: . |
| 42 | + push: true |
| 43 | + tags: ${{ steps.meta.outputs.tags }} |
| 44 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments