zkt26/z2/prepare-app.sh

54 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# =============================================================================
# prepare-app.sh — Build Docker images and create host-path directories
#
# This script:
# 1. Builds the custom Docker images (api, frontend) from source.
# 2. Creates the host directories used by PersistentVolumes.
#
# Prerequisites: Docker installed and running, kubectl configured.
# =============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "============================================="
echo " Preparing Task Manager for Kubernetes..."
echo "============================================="
echo ""
# ---- Step 1: Build Docker images ----------------------------------------
echo "[1/2] Building Docker images..."
echo " Building taskmanager-api..."
docker build -t taskmanager-api:latest "$SCRIPT_DIR/api"
echo " ✓ taskmanager-api:latest built"
echo " Building taskmanager-frontend..."
docker build -t taskmanager-frontend:latest "$SCRIPT_DIR/frontend"
echo " ✓ taskmanager-frontend:latest built"
# If Minikube is running, load the images into its registry
if command -v minikube &> /dev/null && minikube status &> /dev/null; then
echo ""
echo " Detected Minikube. Loading images into Minikube registry..."
minikube image load taskmanager-api:latest
minikube image load taskmanager-frontend:latest
echo " ✓ Images loaded into Minikube"
fi
# ---- Step 2: Create host directories for PersistentVolumes ---------------
echo ""
echo "[2/2] Creating host directories for PersistentVolumes..."
sudo mkdir -p /mnt/taskmanager/postgres
sudo mkdir -p /mnt/taskmanager/redis
sudo chmod -R 777 /mnt/taskmanager
echo " ✓ /mnt/taskmanager/postgres created"
echo " ✓ /mnt/taskmanager/redis created"
echo ""
echo "============================================="
echo " ✓ Preparation complete!"
echo " Run ./start-app.sh to deploy to Kubernetes"
echo "============================================="