SECRET_KEY now uses a kubernetes secret with a fallback value for local testing
All checks were successful
Build containers when image tags change / build-if-image-changed (., web, containers, main container, git.baumann.gr/adebaumann/labhelper) (push) Successful in 3m9s
Build containers when image tags change / build-if-image-changed (data-loader, loader, initContainers, init-container, git.baumann.gr/adebaumann/labhelper-data-loader) (push) Successful in 6s
All checks were successful
Build containers when image tags change / build-if-image-changed (., web, containers, main container, git.baumann.gr/adebaumann/labhelper) (push) Successful in 3m9s
Build containers when image tags change / build-if-image-changed (data-loader, loader, initContainers, init-container, git.baumann.gr/adebaumann/labhelper-data-loader) (push) Successful in 6s
This commit is contained in:
@@ -27,10 +27,16 @@ spec:
|
||||
mountPath: /data
|
||||
containers:
|
||||
- name: web
|
||||
image: git.baumann.gr/adebaumann/labhelper:0.039
|
||||
image: git.baumann.gr/adebaumann/labhelper:0.040
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
env:
|
||||
- name: DJANGO_SECRET_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: django-secret
|
||||
key: secret-key
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /app/data
|
||||
|
||||
8
argocd/secret.yaml
Normal file
8
argocd/secret.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: django-secret
|
||||
namespace: labhelper
|
||||
type: Opaque
|
||||
stringData:
|
||||
secret-key: "CHANGE_ME_TO_RANDOM_STRING"
|
||||
@@ -10,6 +10,7 @@ For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/5.2/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
@@ -20,7 +21,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'f0arjg8q3ut4iuqrguqfjaruf0eripIZZN3t1kymy8ugqnj$li2knhha0@gc5v8f3bge=$+gbybj2$jt28uqm'
|
||||
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'f0arjg8q3ut4iuqrguqfjaruf0eripIZZN3t1kymy8ugqnj$li2knhha0@gc5v8f3bge=$+gbybj2$jt28uqm')
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
45
scripts/deploy_secret.sh
Executable file
45
scripts/deploy_secret.sh
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
# Generate and deploy Django secret key to Kubernetes
|
||||
|
||||
NAMESPACE="labhelper"
|
||||
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"
|
||||
Reference in New Issue
Block a user