Improved docker push github action

This commit is contained in:
Esteban Sánchez 2023-11-21 09:24:33 +01:00
parent cb78dd1fb7
commit 723872bc15
No known key found for this signature in database
GPG Key ID: 9342C91BA286AB16

View File

@ -19,16 +19,13 @@ jobs:
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Extract branch name - name: Docker meta
shell: bash id: meta
run: | uses: docker/metadata-action@v5
tag=${GITHUB_REF#refs/tags/} with:
tag=${tag#refs/heads/} flavor: |
if echo $tag | grep -q -E "[0-9]+\.[0-9]+\.[0-9]+"; then latest=auto
tag="v$tag" images: ${{ secrets.REGISTRY_USERNAME }}/prometheus-qbittorrent-exporter
fi
echo "##[set-output name=tag;]$tag"
id: extract_branch
- name: Login to DockerHub - name: Login to DockerHub
uses: docker/login-action@v3 uses: docker/login-action@v3
@ -41,22 +38,26 @@ jobs:
with: with:
push: true push: true
platforms: linux/amd64,linux/arm64,linux/386 platforms: linux/amd64,linux/arm64,linux/386
tags: | tags: ${{ steps.meta.outputs.tags }}
${{ secrets.REGISTRY_USERNAME }}/prometheus-qbittorrent-exporter:latest
${{ secrets.REGISTRY_USERNAME }}/prometheus-qbittorrent-exporter:${{ steps.extract_branch.outputs.tag }} - name: Docker meta
id: metaghcr
uses: docker/metadata-action@v5
with:
flavor: |
latest=auto
images: ${{ secrets.REGISTRY_USERNAME }}/prometheus-qbittorrent-exporter
- name: Login to Github Container Registry - name: Login to Github Container Registry
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ secrets.REGISTRY_USERNAME }} username: ${{ github.actor }}
password: ${{ secrets.GHCR_PERSONAL_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push docker to Github Container Registry - name: Build and push docker to Github Container Registry
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:
push: true push: true
platforms: linux/amd64,linux/arm64,linux/386 platforms: linux/amd64,linux/arm64,linux/386
tags: | tags: ${{ steps.metaghcr.outputs.tags }}
ghcr.io/${{ secrets.REGISTRY_USERNAME }}/prometheus-qbittorrent-exporter:latest
ghcr.io/${{ secrets.REGISTRY_USERNAME }}/prometheus-qbittorrent-exporter:${{ steps.extract_branch.outputs.tag }}