Skip to content

Commit

Permalink
Add Alembic migration script and update Kubernetes deployment scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
fvergaracl committed Feb 8, 2024
1 parent 7a76d89 commit 41671f6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
13 changes: 13 additions & 0 deletions app/alembic_migration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Wait for PostgreSQL to become available
echo "Waiting for PostgreSQL to become available..."
while ! pg_isready -h $DB_HOST -p $DB_PORT -U $DB_USER; do
sleep 1
done

echo "PostgreSQL is up - executing Alembic migrations"
# Navigate to your project directory (where pyproject.toml is located)
cd /app/app
# Use poetry to run Alembic migrations
poetry run alembic upgrade head
50 changes: 44 additions & 6 deletions deploy-kubernetes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Function to display help message
show_help() {
echo "Usage: $0 [OPTION]"
echo "Apply Kubernetes YAML files for specific components."
echo ""
echo "Options:"
echo " --postgres Apply only the PostgreSQL deployment and its dependencies."
echo " --api Apply only the API deployment and its dependencies."
echo " --verbose Display verbose output."
echo " --help Display this help message."
echo ""
echo "Examples:"
echo " $0 --postgres # Apply only the PostgreSQL deployment."
echo " $0 --api # Apply only the API deployment."
echo " $0 --api --verbose # Apply only the API deployment with verbose output."
}

# Function to apply a YAML file and display colored messages
apply_yaml() {
FILE=$1
Expand All @@ -45,20 +62,41 @@ apply_yaml() {
rm $TEMP_FILE
}

# List of YAML files to apply
FILES=(
"kubernetes/configmaps/env-prod-configmap.yaml"
# Check if help is requested
for arg in "$@"; do
if [ "$arg" = "--help" ]; then
show_help
exit 0
fi
done

# List of YAML files for each deployment
POSTGRES_FILES=(
"kubernetes/volumen/postgres-data-persistentvolumeclaim.yaml"
"kubernetes/services/gamificationengine-service.yaml"
"kubernetes/services/postgres-service.yaml"
"kubernetes/deployments/gamificationengine-deployment.yaml"
"kubernetes/deployments/postgres-deployment.yaml"
)

API_FILES=(
"kubernetes/configmaps/env-prod-configmap.yaml"
"kubernetes/services/gamificationengine-service.yaml"
"kubernetes/deployments/gamificationengine-deployment.yaml"
"kubernetes/ingresses/ingress.yaml"
)

# Determine which deployment to apply based on command-line argument
if [ "$1" = "--postgres" ]; then
FILES=("${POSTGRES_FILES[@]}")
elif [ "$1" = "--api" ]; then
FILES=("${API_FILES[@]}")
else
echo "Invalid option or no option provided. Use --help for usage information."
exit 1
fi

# Apply each YAML file
for FILE in "${FILES[@]}"; do
apply_yaml $FILE $1
apply_yaml $FILE $2 # $2 can be --verbose
done

echo -e "${BLUE}[*] Info: Process completed.${NC}"
2 changes: 2 additions & 0 deletions kubernetes/deployments/postgres-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ spec:
limits:
memory: 2Gi
env:
- name: PGDATA
value: "/var/lib/postgresql/data/pgdata"
- name: DATABASE_URL
valueFrom:
configMapKeyRef:
Expand Down

0 comments on commit 41671f6

Please sign in to comment.