|
| 1 | +name: Create and publish a Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + |
| 6 | +# Defines two custom environment variables for the workflow. |
| 7 | +# These are used for the Container registry domain, and a name for the Docker image that this workflow builds. |
| 8 | +env: |
| 9 | + REGISTRY: ghcr.io |
| 10 | + IMAGE_NAME: ${{ github.repository }} |
| 11 | + |
| 12 | +# There is a single job in this workflow. |
| 13 | +# It's configured to run on the latest available version of Ubuntu. |
| 14 | +jobs: |
| 15 | + build-and-push-image: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + packages: write |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout repository |
| 25 | + uses: actions/checkout@v3 |
| 26 | + |
| 27 | + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and |
| 28 | + # password that will publish the packages. Once published, the packages are scoped to the account defined here. |
| 29 | + - name: Log in to the Container registry |
| 30 | + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 |
| 31 | + with: |
| 32 | + registry: ${{ env.REGISTRY }} |
| 33 | + username: ${{ github.actor }} |
| 34 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + |
| 36 | + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and |
| 37 | + # labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be |
| 38 | + # referenced in a subsequent step. The `images` value provides the base name for the tags and labels. |
| 39 | + - name: Extract metadata (tags, labels) for Docker |
| 40 | + id: meta |
| 41 | + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 |
| 42 | + with: |
| 43 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 44 | + |
| 45 | + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. |
| 46 | + # If the build succeeds, it pushes the image to GitHub Packages. |
| 47 | + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. |
| 48 | + # For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the |
| 49 | + # `docker/build-push-action` repository. |
| 50 | + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. |
| 51 | + - name: Build and push Docker image |
| 52 | + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 |
| 53 | + with: |
| 54 | + context: . |
| 55 | + push: true |
| 56 | + tags: ${{ steps.meta.outputs.tags }} |
| 57 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments