From d3d0298ad13c66fde73f97c0908ea4b3ce5194a6 Mon Sep 17 00:00:00 2001 From: "Adrian A. Baumann" Date: Wed, 7 Jan 2026 14:31:54 +0100 Subject: [PATCH] scripts added and Dockerfile adjusted to remove them from production --- Dockerfile | 1 + scripts/deploy_secret.sh | 45 +++++++++++++++++++++++++++++++++++++++ scripts/full_deploy.sh | 45 +++++++++++++++++++++++++++++++++++++++ scripts/partial_deploy.sh | 27 +++++++++++++++++++++++ test | 0 5 files changed, 118 insertions(+) create mode 100755 scripts/deploy_secret.sh create mode 100755 scripts/full_deploy.sh create mode 100755 scripts/partial_deploy.sh create mode 100644 test diff --git a/Dockerfile b/Dockerfile index 399ed3d..7aa87c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,6 +30,7 @@ RUN rm -rvf /app/Dockerfile* \ /app/requirements.txt \ /app/node_modules \ /app/*.json \ + /app/scripts /app/test_*.py && \ python3 /app/manage.py collectstatic --noinput CMD ["gunicorn","--bind","0.0.0.0:8000","--workers","3","VorgabenUI.wsgi:application"] diff --git a/scripts/deploy_secret.sh b/scripts/deploy_secret.sh new file mode 100755 index 0000000..4af545f --- /dev/null +++ b/scripts/deploy_secret.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# Generate and deploy Django secret key to Kubernetes + +NAMESPACE="vorgabenui" +SECRET_NAME="django-secret" +SECRET_FILE="argocd/secret.yaml" + +# Check if secret file exists +if [ ! -f "$SECRET_FILE" ]; then + echo "Error: $SECRET_FILE not found" + exit 1 +fi + +# Generate random secret key +SECRET_KEY=$(python3 -c "import secrets; print(secrets.token_urlsafe(50))") + +# Create temporary secret file with generated key +TEMP_SECRET_FILE=$(mktemp) +cat "$SECRET_FILE" | sed "s/CHANGE_ME_TO_RANDOM_STRING/$SECRET_KEY/g" > "$TEMP_SECRET_FILE" + +# Check if secret already exists +if kubectl get secret "$SECRET_NAME" -n "$NAMESPACE" &>/dev/null; then + echo "Secret $SECRET_NAME already exists in namespace $NAMESPACE" + read -p "Do you want to replace it? (y/N): " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "Aborted" + rm "$TEMP_SECRET_FILE" + exit 0 + fi + kubectl apply -f "$TEMP_SECRET_FILE" + echo "Secret updated successfully" +else + kubectl apply -f "$TEMP_SECRET_FILE" + echo "Secret created successfully" +fi + +# Clean up +rm "$TEMP_SECRET_FILE" + +echo "" +echo "Secret deployed:" +echo " Name: $SECRET_NAME" +echo " Namespace: $NAMESPACE" +echo " Key: secret-key" diff --git a/scripts/full_deploy.sh b/scripts/full_deploy.sh new file mode 100755 index 0000000..8177802 --- /dev/null +++ b/scripts/full_deploy.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# Full deployment script - bumps both container versions by 0.001 and copies database + +DEPLOYMENT_FILE="argocd/deployment.yaml" +DB_SOURCE="data/db.sqlite3" +DB_DEST="data-loader/preload.sqlite3" + +# Check if deployment file exists +if [ ! -f "$DEPLOYMENT_FILE" ]; then + echo "Error: $DEPLOYMENT_FILE not found" + exit 1 +fi + +# Check if source database exists +if [ ! -f "$DB_SOURCE" ]; then + echo "Error: $DB_SOURCE not found" + exit 1 +fi + +# Extract current version of data-loader +LOADER_VERSION=$(grep -E "image: git.baumann.gr/adebaumann/vgui-data-loader:[0-9]" "$DEPLOYMENT_FILE" | sed -E 's/.*:([0-9.]+)/\1/') + +# Extract current version of main container +MAIN_VERSION=$(grep -E "image: git.baumann.gr/adebaumann/vgui:[0-9]" "$DEPLOYMENT_FILE" | grep -v "data-loader" | sed -E 's/.*:([0-9.]+)/\1/') + +if [ -z "$LOADER_VERSION" ] || [ -z "$MAIN_VERSION" ]; then + echo "Error: Could not find current versions" + exit 1 +fi + +# Calculate new versions (add 0.001), preserve leading zero +NEW_LOADER_VERSION=$(echo "$LOADER_VERSION + 0.001" | bc | sed 's/^\./0./') +NEW_MAIN_VERSION=$(echo "$MAIN_VERSION + 0.001" | bc | sed 's/^\./0./') + +# Update the deployment file +sed -i "s|image: git.baumann.gr/adebaumann/labhelper-data-loader:$LOADER_VERSION|image: git.baumann.gr/adebaumann/labhelper-data-loader:$NEW_LOADER_VERSION|" "$DEPLOYMENT_FILE" +sed -i "s|image: git.baumann.gr/adebaumann/labhelper:$MAIN_VERSION|image: git.baumann.gr/adebaumann/labhelper:$NEW_MAIN_VERSION|" "$DEPLOYMENT_FILE" + +# Copy database +cp "$DB_SOURCE" "$DB_DEST" + +echo "Full deployment prepared:" +echo " Data loader: $LOADER_VERSION -> $NEW_LOADER_VERSION" +echo " Main container: $MAIN_VERSION -> $NEW_MAIN_VERSION" +echo " Database copied to $DB_DEST" diff --git a/scripts/partial_deploy.sh b/scripts/partial_deploy.sh new file mode 100755 index 0000000..fbb79ee --- /dev/null +++ b/scripts/partial_deploy.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Partial deployment script - bumps main container version by 0.001 + +DEPLOYMENT_FILE="argocd/deployment.yaml" + +# Check if file exists +if [ ! -f "$DEPLOYMENT_FILE" ]; then + echo "Error: $DEPLOYMENT_FILE not found" + exit 1 +fi + +# Extract current version of main container (labhelper, not labhelper-data-loader) +CURRENT_VERSION=$(grep -E "image: git.baumann.gr/adebaumann/vui:[0-9]" "$DEPLOYMENT_FILE" | grep -v "data-loader" | sed -E 's/.*:([0-9.]+)/\1/') + +if [ -z "$CURRENT_VERSION" ]; then + echo "Error: Could not find current version" + exit 1 +fi + +# Calculate new version (add 0.001), preserve leading zero +NEW_VERSION=$(echo "$CURRENT_VERSION + 0.001" | bc | sed 's/^\./0./') + +# Update the deployment file (only the main container, not the data-loader) +sed -i "s|image: git.baumann.gr/adebaumann/vui:$CURRENT_VERSION|image: git.baumann.gr/adebaumann/vui:$NEW_VERSION|" "$DEPLOYMENT_FILE" + +echo "Partial deployment prepared:" +echo " Main container: $CURRENT_VERSION -> $NEW_VERSION" diff --git a/test b/test new file mode 100644 index 0000000..e69de29