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
Some checks failed
GKE Auto-Deploy / build-and-deploy (push) Failing after 36s
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
name: GKE Deploy
|
||||
name: GKE Auto-Deploy
|
||||
on: [push]
|
||||
|
||||
env:
|
||||
PROJECT_ID: deployments-485614
|
||||
REGION: europe-west1
|
||||
REPO_NAME: gitea-repo # Assicurati di aver creato questo repo su Artifact Registry!
|
||||
IMAGE_NAME: demo-app
|
||||
REPO_NAME: gitea-repo
|
||||
CLUSTER_NAME: gitea-cluster
|
||||
CLUSTER_ZONE: europe-west1-b
|
||||
|
||||
# --- CONFIGURAZIONE PROGETTO ---
|
||||
APP_NAME: varco # Nome dell'applicazione
|
||||
# -------------------------------
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
@@ -16,35 +19,50 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# 1. Login su Google Cloud
|
||||
- name: Google Auth
|
||||
uses: google-github-actions/auth@v1
|
||||
with:
|
||||
credentials_json: ${{ secrets.GCP_SA_KEY }}
|
||||
|
||||
# 2. Setup Strumenti Google
|
||||
- name: Set up Cloud SDK
|
||||
uses: google-github-actions/setup-gcloud@v1
|
||||
with:
|
||||
# Installiamo anche 'gettext-base' che contiene il comando envsubst (se manca)
|
||||
install_components: 'gke-gcloud-auth-plugin,kubectl'
|
||||
# 3. Configura Docker per Google
|
||||
|
||||
- name: Docker Auth
|
||||
run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
|
||||
|
||||
# 4. Build e Push dell'immagine
|
||||
- name: Build and Push
|
||||
run: |
|
||||
# Costruiamo il tag completo dell'immagine
|
||||
IMAGE_TAG=${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }}
|
||||
# Costruiamo il nome completo dell'immagine
|
||||
# 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 push $IMAGE_TAG
|
||||
|
||||
# 5. Aggiorna Kubernetes
|
||||
# --- PARTE NUOVA: TEMPLATING E APPLY ---
|
||||
- name: Deploy to GKE
|
||||
run: |
|
||||
gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone ${{ env.CLUSTER_ZONE }}
|
||||
|
||||
# Aggiorna l'immagine nel deployment esistente
|
||||
kubectl set image deployment/demo-app demo-container=${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }}
|
||||
# 1. Installiamo envsubst (se non c'è già nell'immagine, di solito c'è ma per sicurezza)
|
||||
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
|
||||
@@ -1,31 +1,33 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: demo-app
|
||||
name: ${APP_NAME}
|
||||
labels:
|
||||
app: ${APP_NAME}
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: demo-app
|
||||
app: ${APP_NAME}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: demo-app
|
||||
app: ${APP_NAME}
|
||||
spec:
|
||||
containers:
|
||||
- name: demo-container
|
||||
image: nginx:alpine # Verrà sostituita dalla pipeline
|
||||
- name: app-container
|
||||
image: ${FULL_IMAGE_NAME}
|
||||
ports:
|
||||
- containerPort: 80
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: demo-service
|
||||
name: ${APP_NAME}-service
|
||||
spec:
|
||||
type: LoadBalancer
|
||||
selector:
|
||||
app: demo-app
|
||||
app: ${APP_NAME}
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
@@ -20,7 +20,7 @@ http {
|
||||
location / {
|
||||
root /app;
|
||||
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;
|
||||
location = /50x.html {
|
||||
|
||||
Reference in New Issue
Block a user