Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 123 additions & 57 deletions .github/workflows/deploy-dev-unified.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ env:
GKE_ZONE: ${{ secrets.GKE_ZONE }}
GCP_REGION: ${{ secrets.GCP_REGION }}
IMAGE_NAME: tasks-app
INSTANCE_NAME: tasks-mysql

jobs:
# ===== PHASE 1: TERRAFORM =====
Expand Down Expand Up @@ -277,59 +276,126 @@ jobs:
echo "✅ Images poussées avec succès vers $REGISTRY"

# ===== PHASE 4: KUBERNETES DEPLOYMENT =====
#deploy-dev:
# name: Deploy to GKE
# runs-on: ubuntu-latest
# needs: [build-and-push]
# if: github.event_name == 'push'
# environment:
# name: development
# url: https://tasks-app-dev.example.com
# steps:
# - name: Checkout
# uses: actions/checkout@v4
#
# - name: Auth to Google Cloud (WIF)
# uses: google-github-actions/auth@v2
# with:
# workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
# service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
#
# - name: Set up Cloud SDK
# uses: google-github-actions/setup-gcloud@v1
#
# - name: Get Artifact Registry URL
# run: |
# ARTIFACT_REGISTRY_URL=$(gcloud artifacts repositories list --format="value(name)" --filter="format=DOCKER" --project=$PROJECT_ID | head -1)
# echo "REGISTRY=$ARTIFACT_REGISTRY_URL" >> $GITHUB_ENV
#
# - name: Configure kubectl
# run: |
# gcloud container clusters get-credentials $GKE_CLUSTER --zone $GKE_ZONE --project $PROJECT_ID
#
# - name: Install Helm
# uses: azure/setup-helm@v3
# with:
# version: '3.12.0'
#
# - name: Get database password from Secret Manager
# run: |
# DB_PASSWORD=$(gcloud secrets versions access latest --secret="${INSTANCE_NAME}-app-db-password" --project=$PROJECT_ID)
# echo "DB_PASSWORD=$DB_PASSWORD" >> $GITHUB_ENV
#
# - name: Deploy to GKE with Helm
# run: |
# helm upgrade --install tasks-app-dev ./helm/tasks-app \
# --namespace tasks-dev \
# --create-namespace \
# --values ./helm/tasks-app/values-dev.yaml \
# --set image.repository=$REGISTRY/$PROJECT_ID/$IMAGE_NAME \
# --set image.tag=dev-latest \
# --set secrets.dbPassword=$DB_PASSWORD \
# --wait --timeout=5m
#
# - name: Verify deployment
# run: |
# kubectl get pods -n tasks-dev
# kubectl get services -n tasks-dev
# kubectl get ingress -n tasks-dev
deploy-dev:
name: Deploy to GKE
runs-on: ubuntu-latest
needs: [build-and-push]
if: github.event_name == 'push'
environment:
name: Develop
url: https://tasks-app-dev.example.com
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Auth to Google Cloud (WIF)
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1

- name: Install gke-gcloud-auth-plugin
run: |
echo "🔧 Installation du plugin gke-gcloud-auth-plugin..."
gcloud components install gke-gcloud-auth-plugin --quiet
echo "✅ Plugin gke-gcloud-auth-plugin installé"

- name: Get Artifact Registry URL
run: |
echo "🔍 Récupération de l'URL Artifact Registry..."
REPO_NAME=$(gcloud artifacts repositories list --format="value(name)" --filter="format=DOCKER" --project=$PROJECT_ID | head -1)
if [ -n "$REPO_NAME" ]; then
DOCKER_REGISTRY_URL="${GCP_REGION}-docker.pkg.dev/${PROJECT_ID}/${REPO_NAME}"
echo "REGISTRY=$DOCKER_REGISTRY_URL" >> $GITHUB_ENV
echo "✅ Artifact Registry URL: $DOCKER_REGISTRY_URL"
else
echo "❌ Aucun Artifact Registry trouvé !"
exit 1
fi

- name: Configure kubectl
run: |
echo "🔧 Configuration de kubectl..."

# Récupérer la location du cluster depuis GCP
CLUSTER_LOCATION=$(gcloud container clusters list \
--project=$PROJECT_ID \
--filter="name=$GKE_CLUSTER" \
--format="value(location)")

echo "📍 Emplacement du cluster: $CLUSTER_LOCATION"

# Vérifier si c'est une région ou une zone
if [[ $CLUSTER_LOCATION == *-*-[a-z] ]]; then
# Format comme europe-west9-c → cluster zoné
echo "🔸 Cluster zoné détecté"
gcloud container clusters get-credentials $GKE_CLUSTER \
--zone $CLUSTER_LOCATION \
--project $PROJECT_ID
else
# Format comme europe-west1 → cluster régional
echo "🔹 Cluster régional détecté"
gcloud container clusters get-credentials $GKE_CLUSTER \
--region $CLUSTER_LOCATION \
--project $PROJECT_ID
fi

echo "✅ kubectl configuré pour le cluster $GKE_CLUSTER en $CLUSTER_LOCATION"

- name: Install Helm
uses: azure/setup-helm@v3
with:
version: '3.12.0'

- name: Get database password from Secret Manager
run: |
echo "🔐 Récupération des informations de connexion à la base de données..."

# Récupérer le nom de l'instance Cloud SQL dynamiquement
DB_INSTANCE_NAME=$(gcloud sql instances list --project=$PROJECT_ID --format="value(name)" | head -1)
echo "Instance Cloud SQL trouvée: $DB_INSTANCE_NAME"

# Récupérer l'IP privée de l'instance Cloud SQL
DB_HOST=$(gcloud sql instances describe $DB_INSTANCE_NAME --project=$PROJECT_ID --format="value(ipAddresses[0].ipAddress)")
echo "DB_HOST=$DB_HOST" >> $GITHUB_ENV
echo "✅ IP de la base de données: $DB_HOST"

# Récupérer le nom de la base de données
echo "DB_NAME=tasksdb" >> $GITHUB_ENV

# Récupérer le mot de passe depuis Secret Manager
DB_PASSWORD=$(gcloud secrets versions access latest --secret="${DB_INSTANCE_NAME}-app-db-password" --project=$PROJECT_ID)
echo "DB_PASSWORD=$DB_PASSWORD" >> $GITHUB_ENV
echo "✅ Mot de passe récupéré depuis Secret Manager pour l'instance $DB_INSTANCE_NAME"

- name: Deploy to GKE with Helm
run: |
echo "🚀 Déploiement sur GKE avec Helm..."
echo " 📦 Image: $REGISTRY/$IMAGE_NAME:dev-latest"
echo " 🗄️ DB Host: $DB_HOST"
echo " 📊 DB Name: $DB_NAME"

helm upgrade --install tasks-app-dev ./helm/tasks-app \
--namespace tasks-dev \
--create-namespace \
--values ./helm/tasks-app/values-dev.yaml \
--set image.repository="$REGISTRY/$IMAGE_NAME" \
--set-string image.tag=dev-latest \
--set-string env.DB_HOST=$DB_HOST \
--set-string env.DB_NAME=$DB_NAME \
--set-string env.DB_USER=tasks_app \
--set-string secrets.dbPassword="$DB_PASSWORD" \
--wait --timeout=10m \
--debug --atomic
echo "✅ Déploiement terminé"

- name: Verify deployment
run: |
echo "🔍 Vérification du déploiement..."
kubectl get pods -n tasks-dev
kubectl get services -n tasks-dev
kubectl get ingress -n tasks-dev
echo "✅ Vérification terminée"
Loading