From 3444a94c5fe174a6eba289e623d5dcd1ed03bf11 Mon Sep 17 00:00:00 2001 From: Charles Mendiburu Date: Wed, 29 Apr 2026 01:08:35 +0200 Subject: [PATCH] Modification script files for deployment of the webapp with Kubernetes --- z2/prepare-app.sh | 20 ++++++++++++++++++-- z2/remove-app.sh | 3 --- z2/start-app.sh | 41 ++++++++++++++++++++++++++++++++++++++--- z2/stop-app.sh | 21 ++++++++++++++++++++- 4 files changed, 76 insertions(+), 9 deletions(-) delete mode 100755 z2/remove-app.sh diff --git a/z2/prepare-app.sh b/z2/prepare-app.sh index ec8a30d..8bd6d13 100755 --- a/z2/prepare-app.sh +++ b/z2/prepare-app.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Prepare the app: create the storage directory and build the Docker images +set -e + +echo "╔══════════════════════════════════════════╗" +echo "║ Vigimétéo – Prepare App ║" +echo "╚══════════════════════════════════════════╝" echo "Preparing app..." -docker compose build -echo "App is prepared." + +# 1 - Create the directory used by the PersistentVolume +mkdir -p ~/vigimeteo-db-data + +# 2 - Build Docker images +docker build -t vigimeteo-backend:latest ./Back-end +docker build -t vigimeteo-frontend:latest ./Front-end + +echo "" +echo "════════════════════════════════════════════" +echo " Preparation complete! Run ./start-app.sh" +echo "════════════════════════════════════════════" \ No newline at end of file diff --git a/z2/remove-app.sh b/z2/remove-app.sh deleted file mode 100755 index 8e24589..0000000 --- a/z2/remove-app.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -echo "Removed app." -docker compose down -v --rmi local diff --git a/z2/start-app.sh b/z2/start-app.sh index 63124cc..b2470cc 100755 --- a/z2/start-app.sh +++ b/z2/start-app.sh @@ -1,4 +1,39 @@ #!/bin/bash -echo "Running app ..." -docker compose up -d -echo "The app is available at http://localhost:5000" +# Deploy all Kubernetes objects for Vigimeteo +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +NS="vigimeteo" + +echo "╔══════════════════════════════════════════╗" +echo "║ Vigimétéo – Start App ║" +echo "╚══════════════════════════════════════════╝" +echo "Starting app..." + +# 1. Create the namespace +kubectl apply -f namespace.yaml + +# 2. Create the ConfigMap from the SQL init script, then apply storage and database +kubectl create configmap vigimeteo-db-init \ + --from-file=init.sql=sql/init_db.sql \ + -n vigimeteo \ + --dry-run=client -o yaml | kubectl apply -f - +kubectl apply -f statefulset.yaml + +# 3. Wait for the database to be ready before starting the backend +echo "Waiting for PostgreSQL to be ready..." +kubectl rollout status statefulset/vigimeteo-db -n vigimeteo --timeout=120s + +# 4. Deploy the backend and frontend +kubectl apply -f deployment.yaml +kubectl apply -f service.yaml + +# ── Summary ─────────────────────────────────────────────────────────────────── +echo "" +echo "════════════════════════════════════════════" +echo " All objects deployed in namespace: $NS" +echo "" +kubectl get all -n "$NS" +echo "" + +echo "App deployed! Available at http://localhost:30500" diff --git a/z2/stop-app.sh b/z2/stop-app.sh index 0fdad68..f9d682a 100755 --- a/z2/stop-app.sh +++ b/z2/stop-app.sh @@ -1,3 +1,22 @@ #!/bin/bash +# Remove all Kubernetes objects for Vigimeteo +set -e + +echo "╔══════════════════════════════════════════╗" +echo "║ Vigimétéo – Stop App ║" +echo "╚══════════════════════════════════════════╝" + echo "Stopping app..." -docker compose stop + +# 1- Deleting the namespace removes everything inside it automatically +kubectl delete namespace vigimeteo --ignore-not-found + +# 2 - The PersistentVolume is cluster-scoped so it must be deleted separately +kubectl delete pv vigimeteo-db-pv --ignore-not-found +echo "" +echo "════════════════════════════════════════════" +echo " All Vigimeteo Kubernetes objects removed." +echo " Note: ~/vigimeteo-db-data was NOT deleted." +echo " Run: rm -rf ~/vigimeteo-db-data to clean up." +echo "════════════════════════════════════════════" +echo "App stopped."