Files
Data-Coupler/.gitea/workflows/docker-build.yml
T
Alessio 31c53eff33
Build and Push Docker Images / Build Windows Container (push) Failing after 7s
Build and Push Docker Images / Create Multi-Platform Manifest (push) Has been cancelled
Build and Push Docker Images / Build Linux Container (push) Has been cancelled
[Fix] Rimosso checkout manuale Windows
- Gitea Actions clona automaticamente il repository
- Non serve checkout manuale con git
- Il codice è già presente nella working directory
- Fix: git non riconosciuto su runner Windows
2026-01-24 13:43:22 +01:00

185 lines
6.6 KiB
YAML

name: Build and Push Docker Images
on:
push:
branches:
- main
- development
- staging
workflow_dispatch:
inputs:
force_build:
description: 'Force build even without code changes'
required: false
default: false
type: boolean
env:
# Gitea Container Registry (self-hosted instance)
REGISTRY: gitea.home-nas-ds.org
# Repository path (format: owner/repo)
IMAGE_NAME: alessio/data-coupler
jobs:
build-linux:
name: Build Linux Container
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Debug - Check registry access
run: |
echo "Testing registry access..."
curl -v https://gitea.home-nas-ds.org/v2/ || echo "Registry not accessible"
echo "Registry: ${{ env.REGISTRY }}"
echo "Image: ${{ env.IMAGE_NAME }}"
continue-on-error: true
- name: Debug - Verify secret is configured
run: |
if [ -z "${{ secrets.REGISTRY_TOKEN }}" ]; then
echo "::error::REGISTRY_TOKEN secret is not configured or is empty!"
exit 1
else
echo "REGISTRY_TOKEN secret is configured (length: ${#REGISTRY_TOKEN})"
fi
env:
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
- name: Log in to Gitea Container Registry
run: |
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ env.REGISTRY }} -u alessio --password-stdin
shell: bash
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# Tag based on branch
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/development' }}
type=raw,value=development-latest,enable=${{ github.ref == 'refs/heads/development' }}
type=raw,value=dev-latest,enable=${{ github.ref == 'refs/heads/dev' }}
type=raw,value=staging-latest,enable=${{ github.ref == 'refs/heads/staging' }}
# Tag with commit sha
type=sha,prefix={{branch}}-,format=short
# Tag with date
type=raw,value={{branch}}-{{date 'YYYYMMDD-HHmmss'}}
flavor: |
latest=false
- name: Build and push Linux Docker image
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
build-windows:
name: Build Windows Container
runs-on: windows
permissions:
contents: read
packages: write
steps:
- name: Log in to Gitea Container Registry
run: echo ${{ secrets.REGISTRY_TOKEN }} | docker login ${{ env.REGISTRY }} -u alessio --password-stdin
shell: cmd
- name: Build and push Windows Docker image
run: |
set BRANCH=${{ github.ref_name }}
set SHA=${{ github.sha }}
set SHORT_SHA=%SHA:~0,7%
REM Build image
docker build -t temp-image -f Dockerfile.windows .
REM Tag and push based on branch
if "%BRANCH%"=="main" (
docker tag temp-image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-windows
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-windows
)
if "%BRANCH%"=="development" (
docker tag temp-image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-windows
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-windows
docker tag temp-image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:development-latest-windows
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:development-latest-windows
)
if "%BRANCH%"=="staging" (
docker tag temp-image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:staging-latest-windows
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:staging-latest-windows
)
REM Clean up
docker rmi temp-image
shell: cmd
create-manifest:
name: Create Multi-Platform Manifest
runs-on: ubuntu-latest
needs: [build-linux, build-windows]
permissions:
contents: read
packages: write
steps:
- name: Log in to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: alessio
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Create and push manifest for main branch
if: github.ref == 'refs/heads/main'
run: |
IMAGE_LOWER=$(echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
docker buildx imagetools create -t ${IMAGE_LOWER}:latest \
${IMAGE_LOWER}:latest \
${IMAGE_LOWER}:latest-windows
- name: Create and push manifest for development branch
if: github.ref == 'refs/heads/development'
run: |
IMAGE_LOWER=$(echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
docker buildx imagetools create -t ${IMAGE_LOWER}:latest \
${IMAGE_LOWER}:latest \
${IMAGE_LOWER}:latest-windows
docker buildx imagetools create -t ${IMAGE_LOWER}:development-latest \
${IMAGE_LOWER}:development-latest \
${IMAGE_LOWER}:development-latest-windows
- name: Create and push manifest for dev branch
if: github.ref == 'refs/heads/dev'
run: |
IMAGE_LOWER=$(echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
docker buildx imagetools create -t ${IMAGE_LOWER}:dev-latest \
${IMAGE_LOWER}:dev-latest \
${IMAGE_LOWER}:dev-latest-windows
- name: Create and push manifest for staging branch
if: github.ref == 'refs/heads/staging'
run: |
IMAGE_LOWER=$(echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
docker buildx imagetools create -t ${IMAGE_LOWER}:staging-latest \
${IMAGE_LOWER}:staging-latest \
${IMAGE_LOWER}:staging-latest-windows