Rinomina il workflow in GKE Auto-Deploy e migliora la gestione delle variabili per il deployment dell'applicazione
Some checks failed
GKE Auto-Deploy / build-and-deploy (push) Failing after 36s

This commit is contained in:
2026-01-28 18:21:49 +01:00
parent a33d8d8e63
commit c3f8023b6c
3 changed files with 41 additions and 21 deletions

View File

@@ -1,13 +1,16 @@
name: GKE Deploy name: GKE Auto-Deploy
on: [push] on: [push]
env: env:
PROJECT_ID: deployments-485614 PROJECT_ID: deployments-485614
REGION: europe-west1 REGION: europe-west1
REPO_NAME: gitea-repo # Assicurati di aver creato questo repo su Artifact Registry! REPO_NAME: gitea-repo
IMAGE_NAME: demo-app
CLUSTER_NAME: gitea-cluster CLUSTER_NAME: gitea-cluster
CLUSTER_ZONE: europe-west1-b CLUSTER_ZONE: europe-west1-b
# --- CONFIGURAZIONE PROGETTO ---
APP_NAME: varco # Nome dell'applicazione
# -------------------------------
jobs: jobs:
build-and-deploy: build-and-deploy:
@@ -16,35 +19,50 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
# 1. Login su Google Cloud
- name: Google Auth - name: Google Auth
uses: google-github-actions/auth@v1 uses: google-github-actions/auth@v1
with: with:
credentials_json: ${{ secrets.GCP_SA_KEY }} credentials_json: ${{ secrets.GCP_SA_KEY }}
# 2. Setup Strumenti Google
- name: Set up Cloud SDK - name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1 uses: google-github-actions/setup-gcloud@v1
with: with:
# Installiamo anche 'gettext-base' che contiene il comando envsubst (se manca)
install_components: 'gke-gcloud-auth-plugin,kubectl' install_components: 'gke-gcloud-auth-plugin,kubectl'
# 3. Configura Docker per Google
- name: Docker Auth - name: Docker Auth
run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
# 4. Build e Push dell'immagine
- name: Build and Push - name: Build and Push
run: | run: |
# Costruiamo il tag completo dell'immagine # Costruiamo il nome completo dell'immagine
IMAGE_TAG=${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }} # Lo esportiamo in GITHUB_ENV così diventa disponibile agli step successivi
echo "FULL_IMAGE_NAME=${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.APP_NAME }}:${{ gitea.sha }}" >> $GITHUB_ENV
# Nota: uso la variabile appena creata leggendola dall'ambiente corrente
IMAGE_TAG=${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.APP_NAME }}:${{ gitea.sha }}
# Costruiamo e carichiamo
docker build -t $IMAGE_TAG . docker build -t $IMAGE_TAG .
docker push $IMAGE_TAG docker push $IMAGE_TAG
# 5. Aggiorna Kubernetes # --- PARTE NUOVA: TEMPLATING E APPLY ---
- name: Deploy to GKE - name: Deploy to GKE
run: | run: |
gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone ${{ env.CLUSTER_ZONE }} gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone ${{ env.CLUSTER_ZONE }}
# Aggiorna l'immagine nel deployment esistente # 1. Installiamo envsubst (se non c'è già nell'immagine, di solito c'è ma per sicurezza)
kubectl set image deployment/demo-app demo-container=${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }} sudo apt-get update && sudo apt-get install -y gettext-base
# 2. Sostituzione variabili
# Legge k8s/deployment.yaml, sostituisce ${APP_NAME} e ${FULL_IMAGE_NAME}
# Scrive il risultato in un file temporaneo 'final-deploy.yaml'
envsubst < k8s/deployment.yaml > final-deploy.yaml
# (Opzionale) Stampiamo il file per debug
echo "--- FILE YAML GENERATO ---"
cat final-deploy.yaml
echo "--------------------------"
# 3. Applica a Kubernetes
# Se il deployment non esiste, lo crea. Se esiste, lo aggiorna.
kubectl apply -f final-deploy.yaml

View File

@@ -1,31 +1,33 @@
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: demo-app name: ${APP_NAME}
labels:
app: ${APP_NAME}
spec: spec:
replicas: 1 replicas: 1
selector: selector:
matchLabels: matchLabels:
app: demo-app app: ${APP_NAME}
template: template:
metadata: metadata:
labels: labels:
app: demo-app app: ${APP_NAME}
spec: spec:
containers: containers:
- name: demo-container - name: app-container
image: nginx:alpine # Verrà sostituita dalla pipeline image: ${FULL_IMAGE_NAME}
ports: ports:
- containerPort: 80 - containerPort: 80
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: demo-service name: ${APP_NAME}-service
spec: spec:
type: LoadBalancer type: LoadBalancer
selector: selector:
app: demo-app app: ${APP_NAME}
ports: ports:
- port: 80 - port: 80
targetPort: 80 targetPort: 80

View File

@@ -20,7 +20,7 @@ http {
location / { location / {
root /app; root /app;
index index.html; index index.html;
try_files $uri $uri/ /index.html; # <--- LA MAGIA PER VUE.JS try_files $uri $uri/ /index.html; # Riga per VueJS SPA
} }
error_page 500 502 503 504 /50x.html; error_page 500 502 503 504 /50x.html;
location = /50x.html { location = /50x.html {