name: Publish Docker image on: push: branches: [main] tags: - 'v*' workflow_dispatch: permissions: contents: read packages: write env: IMAGE_NAME: pichost jobs: build-and-push: if: ${{ !contains(github.event.head_commit.message, '[skip docker]') }} runs-on: ubuntu-latest env: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} steps: - name: Checkout uses: actions/checkout@v7 - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Log in to Docker Hub if: env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' uses: docker/login-action@v3 with: username: ${{ env.DOCKERHUB_USERNAME }} password: ${{ env.DOCKERHUB_TOKEN }} - name: Resolve image names id: images run: | names="ghcr.io/${OWNER}/${IMAGE_NAME}" if [ -n "${DOCKERHUB_USERNAME}" ]; then names="${names} ${DOCKERHUB_USERNAME}/${IMAGE_NAME}" fi { echo "list<> "$GITHUB_OUTPUT" env: OWNER: ${{ github.repository_owner }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ steps.images.outputs.list }} tags: | type=raw,value=latest,enable={{is_default_branch}} type=semver,pattern={{version}} type=semver,pattern=v{{version}} - name: Build and push uses: docker/build-push-action@v6 with: context: . push: true platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max