4b27c6a11d
- Creato workflow Gitea Actions (.gitea/workflows/docker-build.yml) - Documentazione completa setup e configurazione - Aggiornati README.md e copilot-instructions.md - Supporto registry Gitea Container Registry (gitea.com) - Stessa strategia di tagging di GitHub Actions - Build multi-platform (Linux + Windows)
189 lines
6.5 KiB
YAML
189 lines
6.5 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
|
|
REGISTRY: gitea.com
|
|
# Repository path (format: owner/repo)
|
|
IMAGE_NAME: alessiodalsanto/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: Log in to Gitea Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ gitea.actor }}
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- 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=${{ gitea.ref == 'refs/heads/main' }}
|
|
type=raw,value=latest,enable=${{ gitea.ref == 'refs/heads/development' }}
|
|
type=raw,value=development-latest,enable=${{ gitea.ref == 'refs/heads/development' }}
|
|
type=raw,value=dev-latest,enable=${{ gitea.ref == 'refs/heads/dev' }}
|
|
type=raw,value=staging-latest,enable=${{ gitea.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-2022
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ gitea.actor }}
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: Extract metadata for Docker
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
# Tag based on branch with windows suffix
|
|
type=raw,value=latest-windows,enable=${{ gitea.ref == 'refs/heads/main' }}
|
|
type=raw,value=latest-windows,enable=${{ gitea.ref == 'refs/heads/development' }}
|
|
type=raw,value=development-latest-windows,enable=${{ gitea.ref == 'refs/heads/development' }}
|
|
type=raw,value=dev-latest-windows,enable=${{ gitea.ref == 'refs/heads/dev' }}
|
|
type=raw,value=staging-latest-windows,enable=${{ gitea.ref == 'refs/heads/staging' }}
|
|
# Tag with commit sha
|
|
type=sha,prefix={{branch}}-windows-,format=short
|
|
# Tag with date
|
|
type=raw,value={{branch}}-windows-{{date 'YYYYMMDD-HHmmss'}}
|
|
flavor: |
|
|
latest=false
|
|
|
|
- name: Build and push Windows Docker image
|
|
run: |
|
|
# Convert repository name to lowercase
|
|
$imageName = "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}".ToLower()
|
|
|
|
# Build with temporary tag
|
|
docker build -t "${imageName}:temp-windows" -f Dockerfile.windows .
|
|
|
|
# Parse and push all tags
|
|
$tags = "${{ steps.meta.outputs.tags }}" -split "`n"
|
|
foreach ($tag in $tags) {
|
|
$tag = $tag.Trim()
|
|
if ($tag) {
|
|
# Ensure tag is lowercase
|
|
$tag = $tag.ToLower()
|
|
Write-Host "Tagging and pushing: $tag"
|
|
docker tag "${imageName}:temp-windows" $tag
|
|
docker push $tag
|
|
}
|
|
}
|
|
|
|
# Remove temporary tag
|
|
docker rmi "${imageName}:temp-windows"
|
|
shell: pwsh
|
|
|
|
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: ${{ gitea.actor }}
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: Create and push manifest for main branch
|
|
if: gitea.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: gitea.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: gitea.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: gitea.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
|