Skip to content

Commit

Permalink
feat: add scripts for minikube checks and project directory validation
Browse files Browse the repository at this point in the history
  • Loading branch information
gm112 committed Jan 15, 2025
1 parent 8fcb907 commit 6a054a1
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 38 deletions.
13 changes: 13 additions & 0 deletions iac/scripts/common/check-minikube.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

check_minikube() {
# Check if minikube is running
MINIKUBE_STATUS=$(minikube status --format '{{.Host}}' || echo "")
if [ "$MINIKUBE_STATUS" != "Running" ]; then
echo "Minikube is not running. Starting minikube..."
minikube start --driver=docker
eval $(minikube docker-env)
kubectl config use-context minikube
docker compose build
fi
}
17 changes: 17 additions & 0 deletions iac/scripts/common/check-project-dir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

check_project_dir() {
PROJECT_DIR=$1
PROJECT_ENVIRONMENT=$2
if [ ! -d "$PROJECT_DIR" ]; then
echo "Error: Project directory not found."
exit 1
fi

# Check if environment directory exists
ENVIRONMENT_DIR="$PROJECT_DIR/environments/$PROJECT_ENVIRONMENT"
if [ ! -d "$ENVIRONMENT_DIR" ]; then
echo "Error: Environment directory not found."
exit 1
fi
}
92 changes: 92 additions & 0 deletions iac/scripts/development/apply.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash
set -e

PROJECT_DIR=$1
PROJECT_ENVIRONMENT=$2

SCRIPT_DIR=$(dirname "$0")
source "$SCRIPT_DIR/../common/check-minikube.sh"
source "$SCRIPT_DIR/../common/check-project-dir.sh"

check_project_dir "$PROJECT_DIR" "$PROJECT_ENVIRONMENT"
check_minikube

cd "$PROJECT_DIR/environments/$PROJECT_ENVIRONMENT"

kubectl kustomize . -v 9
echo ""
echo "Press any key to continue..."
read -n 1 -s
clear

#kustomize edit fix

echo "
█████████████████████████████████████████████████████ █████████
█████████████████████████████████████████████████████ █████████
████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█████████████▓▓▓▓████
████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█████████████▓▓▓▓████
████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█████████████▓▓▓▓████
████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████
████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████
█████▓▓▓▓▓▓▓▓▓▓▓▓████░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████
█████▓▓▓▓▓▓▓▓▓▓▓▓████░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████
█████▓▓▓▓▓▓▓▓████░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████
█████▓▓▓▓▓▓▓▓████░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████
████▓▓▓▓████░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████
████▓▓▓▓████░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████
████▓▓▓▓████░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████
█████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████
█████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████
█████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▒▓▓▓▓▓▓▓▓▓▓▓▓████
█████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▒▓▓▓▓▓▓▓▓▓▓▓▓████
████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ████▓▓▓▓▒ ████
████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ████▓▓▓▓▒ ████
█████████████████████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ████▓▓▓▓▒ ████
█████████████████████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ████▓▓▓▓▒ ████
████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ████░ ▒████████████
████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ████░ ▒████████████
████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ████░ ▒████████████
█████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ ░░░░░░░░░░░░░████
█████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░ ░░░░░░░░░░░░░████
█████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████
█████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████
█████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒████
█████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒████
████░░░░█████████████████████████████████
████░░░░█████████████████████████████████
████░░░░█████████████████████████████████
████░░░░████████▓▓▓▓░░░░░░░░░░░░█████████████████
████░░░░████████▓▓▓▓░░░░░░░░░░░░█████████████████
████░░░░████ ████░░░░░░░░░░░░████░ ████
████░░░░████ ████░░░░░░░░░░░░████░ ████
████████ ████░░░░░░░░████░ ████
████████ ████░░░░░░░░████░ ████
████ ████████░░░░████░ ▒████
████ ████████░░░░████░ ▒████
████ ████████▓▓▓▓█████████████████
████ ████████▓▓▓▓█████████████████
████ ████████▓▓▓▓█████████████████
████████▓▓▓▓████████████
████████▓▓▓▓████████████
████████▓▓▓▓████▓▓▓▓▓▓▓▓█████████
████████▓▓▓▓████▓▓▓▓▓▓▓▓█████████
████████▓▓▓▓▓▓▓▓████████▓▓▓▓▓▓▓▓░ ▒████████
████████▓▓▓▓▓▓▓▓████████▓▓▓▓▓▓▓▓░ ▒████████
████▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓████████▓▓▓▓▓▓▓▓▓▓▓▓▓████
████▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓████████▓▓▓▓▓▓▓▓▓▓▓▓▓████
████▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓████████▓▓▓▓▓▓▓▓▓▓▓▓▓████
████▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█████▓▓▓▓▓▓▓▓▓▓▓▓████
████▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█████▓▓▓▓▓▓▓▓▓▓▓▓████
█████████████████████████████████████████████████████
█████████████████████████████████████████████████████
"

echo "Applying kustomize build..."


kustomize build . | kubectl apply -f -
cd -

echo "Deployments have been applied."
27 changes: 27 additions & 0 deletions iac/scripts/development/status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
set -e

ENVIRONMENT_TARGET=$1 || "zfgbb-develop"

SCRIPT_DIR=$(dirname "$0")
source "$SCRIPT_DIR/../common/check-minikube.sh"

check_minikube

kubectl describe deployments -n "$ENVIRONMENT_TARGET"

echo "Press any key to continue..."
read -n 1 -s
clear

kubectl describe services -n "$ENVIRONMENT_TARGET"

echo "Press any key to continue..."
read -n 1 -s
clear

kubectl describe pods -n "$ENVIRONMENT_TARGET"

echo "Press any key to continue..."
read -n 1 -s
clear
File renamed without changes.
2 changes: 1 addition & 1 deletion iac/zfgc.com/base/ingress.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
name: zfgbb-ingress
# namespace: zfgbb
spec:
rules:
Expand Down
19 changes: 0 additions & 19 deletions iac/zfgc.com/scripts/development/apply.sh

This file was deleted.

29 changes: 11 additions & 18 deletions iac/zfgc.com/scripts/development/setup-dev-environment.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
#!/bin/bash

kubectl config use-context minikube
# Check if the project directory is provided as an argument
if [ -z "$1" ]; then
echo "Error: No project directory provided."
echo "Error: No project environment provided."
exit 1
fi

SCRIPT_DIR=$(dirname "$0")

# Set the project base directory
PROJECT_DIR=$(realpath "$1")
PROJECT_DIR=$(realpath "$SCRIPT_DIR/../..")
PROJECT_ENVIRONMENT=$1

# Check if zfgc.com is a directory
if [ ! -d "$PROJECT_DIR/zfgc.com" ]; then
echo "Error: Project directory is not a zfgc.com directory."
exit 1
fi
source "$SCRIPT_DIR/../../../scripts/common/check-minikube.sh"
source "$SCRIPT_DIR/../../../scripts/common/check-project-dir.sh"

# Check if minikube is running
MINIKUBE_STATUS=$(minikube status --format '{{.Host}}')
if [ "$MINIKUBE_STATUS" != "Running" ]; then
minikube start --driver=docker
eval $(minikube docker-env)
docker compose build
fi
check_project_dir "$PROJECT_DIR" "$PROJECT_ENVIRONMENT"
check_minikube

DIST_DIR="$PROJECT_DIR/dist"

Expand All @@ -47,12 +40,12 @@ mkdir -p "$POSTGRES_DIR"

mkdir -p "$APACHE_VHOSTS_DIR"

ENV_FILE="$PROJECT_DIR/zfgc.com/environments/development/.env"
ENV_FILE="$PROJECT_DIR/environments/$PROJECT_ENVIRONMENT/.env"

create_env_file() {
MYSQL_PASSWORD=$1
POSTGRES_PASSWORD=$2
TARGET_ENV_FILE="$PROJECT_DIR/zfgc.com/environments/development/.env"
TARGET_ENV_FILE="$PROJECT_DIR/environments/$PROJECT_ENVIRONMENT/.env"

echo "Generating .env file at $TARGET_ENV_FILE..."
touch "$TARGET_ENV_FILE"
Expand Down
1 change: 1 addition & 0 deletions iac/zfgc.com/services/zfgbb/deployment-zfgbb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ spec:
key: POSTGRES_PASSWORD
- name: zfgbb
image: zfgbb-zfgbb:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080

0 comments on commit 6a054a1

Please sign in to comment.