Files
docker-voltronic-homeassistant/.gitea/workflows/docker-build.yml
T
Pi Developer 6b574f6775
Build Docker Image for Raspberry Pi / build-and-push (push) Failing after 26s
Fix errore Docker build quando secrets non configurati
- 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
2026-01-31 16:23:25 +01:00

81 lines
2.4 KiB
YAML

name: Build Docker Image for Raspberry Pi
on:
push:
branches:
- main
- master
- develop
tags:
- 'v*'
pull_request:
branches:
- main
- master
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: linux/arm/v6,linux/arm/v7,linux/arm64
- name: Set up Docker Buildx
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
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ steps.image-name.outputs.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Login to Docker Hub
if: github.event_name != 'pull_request' && steps.image-name.outputs.SHOULD_PUSH == 'true'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile.multiarch
platforms: linux/arm/v6,linux/arm/v7,linux/arm64
push: ${{ steps.image-name.outputs.SHOULD_PUSH == 'true' && github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILD_DATE=${{ github.event.repository.updated_at }}
VERSION=${{ steps.meta.outputs.version }}
VCS_REF=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Image digest
run: echo ${{ steps.meta.outputs.tags }}