Fix errore Docker build quando secrets non configurati
Build Docker Image for Raspberry Pi / build-and-push (push) Failing after 26s

- Aggiunto step 'Prepare image name' per gestire nome immagine dinamico
- Se secrets configurati: usa username/ha-voltronic-mqtt
- Se secrets mancanti: usa local/ha-voltronic-mqtt (build locale)
- Corretto flag SHOULD_PUSH basato su presenza secrets
- Risolto errore 'invalid tag' quando DOCKER_USERNAME è vuoto

Ora il workflow esegue build anche senza secrets configurati
This commit is contained in:
Pi Developer
2026-01-31 16:23:25 +01:00
parent c5645c0f2b
commit 6b574f6775
+14 -3
View File
@@ -29,12 +29,23 @@ jobs:
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2 uses: docker/setup-buildx-action@v2
- name: Prepare image name
id: image-name
run: |
if [ -n "${{ secrets.DOCKER_USERNAME }}" ]; then
echo "IMAGE_NAME=${{ secrets.DOCKER_USERNAME }}/ha-voltronic-mqtt" >> $GITHUB_OUTPUT
echo "SHOULD_PUSH=true" >> $GITHUB_OUTPUT
else
echo "IMAGE_NAME=local/ha-voltronic-mqtt" >> $GITHUB_OUTPUT
echo "SHOULD_PUSH=false" >> $GITHUB_OUTPUT
fi
- name: Docker meta - name: Docker meta
id: meta id: meta
uses: docker/metadata-action@v4 uses: docker/metadata-action@v4
with: with:
images: | images: |
${{ secrets.DOCKER_USERNAME }}/ha-voltronic-mqtt ${{ steps.image-name.outputs.IMAGE_NAME }}
tags: | tags: |
type=ref,event=branch type=ref,event=branch
type=ref,event=pr type=ref,event=pr
@@ -43,7 +54,7 @@ jobs:
type=raw,value=latest,enable={{is_default_branch}} type=raw,value=latest,enable={{is_default_branch}}
- name: Login to Docker Hub - name: Login to Docker Hub
if: github.event_name != 'pull_request' && secrets.DOCKER_USERNAME != '' if: github.event_name != 'pull_request' && steps.image-name.outputs.SHOULD_PUSH == 'true'
uses: docker/login-action@v2 uses: docker/login-action@v2
with: with:
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
@@ -55,7 +66,7 @@ jobs:
context: . context: .
file: ./Dockerfile.multiarch file: ./Dockerfile.multiarch
platforms: linux/arm/v6,linux/arm/v7,linux/arm64 platforms: linux/arm/v6,linux/arm/v7,linux/arm64
push: ${{ github.event_name != 'pull_request' && secrets.DOCKER_USERNAME != '' }} push: ${{ steps.image-name.outputs.SHOULD_PUSH == 'true' && github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
build-args: | build-args: |