-Aggiunta configurazione tramite dockerfile per windows e linux
-Aggiunte github actions per la compilazione dei container e l'esposizione
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
name: Build and Push Docker Images
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- dev
|
||||
- staging
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
force_build:
|
||||
description: 'Force build even without code changes'
|
||||
required: false
|
||||
default: false
|
||||
type: boolean
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
|
||||
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 GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_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=${{ github.ref == 'refs/heads/main' }}
|
||||
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'}}
|
||||
|
||||
- name: Build and push Linux Docker image
|
||||
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
|
||||
|
||||
- name: Generate artifact attestation
|
||||
uses: actions/attest-build-provenance@v1
|
||||
with:
|
||||
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
subject-digest: ${{ steps.build.outputs.digest }}
|
||||
push-to-registry: true
|
||||
|
||||
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 GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_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=${{ github.ref == 'refs/heads/main' }}
|
||||
type=raw,value=dev-latest-windows,enable=${{ github.ref == 'refs/heads/dev' }}
|
||||
type=raw,value=staging-latest-windows,enable=${{ github.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'}}
|
||||
|
||||
- name: Build and push Windows Docker image
|
||||
run: |
|
||||
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}-windows -f Dockerfile.windows .
|
||||
$tags = "${{ steps.meta.outputs.tags }}" -split "`n"
|
||||
foreach ($tag in $tags) {
|
||||
$tag = $tag.Trim()
|
||||
if ($tag) {
|
||||
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}-windows $tag
|
||||
docker push $tag
|
||||
}
|
||||
}
|
||||
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 GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Create and push manifest for main branch
|
||||
if: github.ref == 'refs/heads/main'
|
||||
run: |
|
||||
docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-windows
|
||||
|
||||
- name: Create and push manifest for dev branch
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
run: |
|
||||
docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:dev-latest \
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:dev-latest \
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:dev-latest-windows
|
||||
|
||||
- name: Create and push manifest for staging branch
|
||||
if: github.ref == 'refs/heads/staging'
|
||||
run: |
|
||||
docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:staging-latest \
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:staging-latest \
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:staging-latest-windows
|
||||
Reference in New Issue
Block a user