1
0
mirror of synced 2026-01-06 06:02:35 -05:00
Files
docs/data/reusables/package_registry/publish-docker-image.md

1.5 KiB

{% data reusables.actions.actions-not-certified-by-github-comment %}

name: Create and publish a Docker image

on:
  push:
    branches: ['release']

env:
  REGISTRY: {% data reusables.package_registry.container-registry-hostname %}
  IMAGE_NAME: {% raw %}${{ github.repository }}{% endraw %}

jobs:
  build-and-push-image:
    runs-on: {% ifversion ghes %}[self-hosted]{% else %}ubuntu-latest{% endif %}
    permissions:
      contents: read
      packages: write

    steps:
      - name: Checkout repository
        uses: {% data reusables.actions.action-checkout %}

      - name: Log in to the Container registry
        uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
        with:
          registry: {% raw %}${{ env.REGISTRY }}{% endraw %}
          username: {% raw %}${{ github.actor }}{% endraw %}
          password: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %}

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
        with:
          images: {% raw %}${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}{% endraw %}

      - name: Build and push Docker image
        uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
        with:
          context: .
          push: true
          tags: {% raw %}${{ steps.meta.outputs.tags }}{% endraw %}
          labels: {% raw %}${{ steps.meta.outputs.labels }}{% endraw %}