deployment config

This commit is contained in:
2025-10-14 11:02:19 +02:00
parent 8035969290
commit 74c5157439
5 changed files with 134 additions and 1805 deletions

11
.dockerignore Normal file
View File

@@ -0,0 +1,11 @@
# Ignora file non necessari per l'immagine
.git
.gitignore
.github
node_modules
npm-debug.log
.DS_Store
*.md
*.pdf
README.md
DEPLOY.md

73
.github/workflows/docker-publish.yml vendored Normal file
View File

@@ -0,0 +1,73 @@
name: Build and Publish Docker image
on:
push:
branches: [ main ]
workflow_dispatch: {}
permissions:
contents: read
packages: write
id-token: write
jobs:
build-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/home:latest
ghcr.io/${{ github.repository_owner }}/home:${{ github.sha }}
file: Dockerfile
- name: Output image
run: |
echo "Image pushed: ghcr.io/${{ github.repository_owner }}/home:latest"
echo "Image pushed: ghcr.io/${{ github.repository_owner }}/home:${{ github.sha }}"
redeploy:
name: Redeploy target
needs: build-publish
runs-on: ubuntu-latest
steps:
- name: Check redeploy inputs
if: ${{ secrets.REDEPLOY_URL != '' && secrets.REDEPLOY_TOKEN != '' }}
run: |
echo "Redeploy inputs present"
- name: Call redeploy endpoint
if: ${{ secrets.REDEPLOY_URL != '' && secrets.REDEPLOY_TOKEN != '' }}
run: |
echo "Calling redeploy endpoint..."
# curl --fail ritorna exit code != 0 se lo status HTTP non è 2xx
curl --fail -s -X POST \
-H "Authorization: Bearer ${{ secrets.REDEPLOY_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"image\":\"ghcr.io/${{ github.repository_owner }}/home:${{ github.sha }}\"}" \
"${{ secrets.REDEPLOY_URL }}"
- name: Skip redeploy warning
if: ${{ secrets.REDEPLOY_URL == '' || secrets.REDEPLOY_TOKEN == '' }}
run: |
echo "REDEPLOY_URL or REDEPLOY_TOKEN not set; skipping redeploy step."

36
DEPLOY.md Normal file
View File

@@ -0,0 +1,36 @@
# Deploy del sito su Kubernetes usando l'immagine GHCR
1) Build e push automatico
- La GitHub Action `.github/workflows/docker-publish.yml` builda e pusha l'immagine su `ghcr.io/<OWNER>/home:latest` quando fai push su `main`.
2) Aggiornare i manifest
- Modifica `k8s/deployment.yaml` e sostituisci `OWNER` con il tuo GitHub username (o l'organization) se l'immagine è privata.
3) Secrets per cluster privato
- Se l'immagine è privata, crea un secret per il pull:
kubectl create secret docker-registry ghcr-secret --docker-server=ghcr.io --docker-username=<USERNAME> --docker-password=<PERSONAL_ACCESS_TOKEN> --docker-email=<EMAIL>
- Poi aggiungi nello `spec.template.spec` del deployment:
imagePullSecrets:
- name: ghcr-secret
4) Deploy sul cluster
- Assicurati di essere connesso al cluster (kubectl config use-context ...)
- Applica i manifest:
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
5) Nota su permissions GHCR
- Se usi `GITHUB_TOKEN` per pushare pacchetti, assicurati di abilitare il `permissions: packages: write` nelle settings del workflow e che il repository abbia Packages abilitati.
Se il push fallisce
- Usa un Personal Access Token (PAT) con scope `write:packages` come secret `GHCR_PAT` e modifica lo step di login nella action per usare `password: ${{ secrets.GHCR_PAT }}` al posto di `GITHUB_TOKEN`.
I permessi del workflow
- Lo YAML di esempio include:
permissions:
contents: read
packages: write
id-token: write
Questo è sufficiente per pushare immagini private su GHCR se il repository appartiene all'utente. Per organizzazioni, potresti dover configurare permessi aggiuntivi.

14
Dockerfile Normal file
View File

@@ -0,0 +1,14 @@
# Dockerfile per servire il sito statico con nginx
# Usa una immagine nginx leggera e aggiornata
## Uso un tag specifico (major.minor) per maggiore riproducibilità e per limitare warning di vulnerabilità
FROM nginx:1.25-alpine
# Rimuove il contenuto di default e copia i file del sito
RUN rm -rf /usr/share/nginx/html/*
COPY . /usr/share/nginx/html
# Espone porta 80
EXPOSE 80
# Comando di default
CMD ["nginx", "-g", "daemon off;"]

File diff suppressed because it is too large Load Diff