From 4cbd3e2f877408d7cfa14153ee67af0d7cfb29ba Mon Sep 17 00:00:00 2001 From: "Adrian A. Baumann" Date: Fri, 16 Jan 2026 12:22:50 +0100 Subject: [PATCH] Gunicorn options in config map; Image tag displays on page --- Dockerfile | 2 +- argocd/configmap.yaml | 4 +++- argocd/deployment.yaml | 12 +++++++++++- labhelper/context_processors.py | 8 ++++++++ labhelper/settings.py | 1 + labhelper/templates/base.html | 1 + scripts/full_deploy.sh | 4 ++++ scripts/partial_deploy.sh | 4 ++++ 8 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 labhelper/context_processors.py diff --git a/Dockerfile b/Dockerfile index 3a4d338..86fe039 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,5 +47,5 @@ RUN rm -rvf /app/Dockerfile* \ /app/*.json \ /app/test_*.py && \ python3 /app/manage.py collectstatic --noinput -CMD ["sh", "-c", "python manage.py thumbnail clear && gunicorn --bind 0.0.0.0:8000 --workers 3 labhelper.wsgi:application"] +CMD ["sh", "-c", "python manage.py thumbnail clear && gunicorn --bind 0.0.0.0:8000 --workers 3 $GUNICORN_OPTS labhelper.wsgi:application"] diff --git a/argocd/configmap.yaml b/argocd/configmap.yaml index c2ac3d2..2a6c28a 100644 --- a/argocd/configmap.yaml +++ b/argocd/configmap.yaml @@ -16,4 +16,6 @@ data: CSRF_TRUSTED_ORIGINS: "https://labhelper.adebaumann.com" LOGIN_URL: "login" LOGIN_REDIRECT_URL: "index" - LOGOUT_REDIRECT_URL: "login" \ No newline at end of file + LOGOUT_REDIRECT_URL: "login" + GUNICORN_OPTS: "--access-logfile -" + IMAGE_TAG: "0.061" \ No newline at end of file diff --git a/argocd/deployment.yaml b/argocd/deployment.yaml index 67a4a42..2263224 100644 --- a/argocd/deployment.yaml +++ b/argocd/deployment.yaml @@ -27,7 +27,7 @@ spec: mountPath: /data containers: - name: web - image: git.baumann.gr/adebaumann/labhelper:0.059 + image: git.baumann.gr/adebaumann/labhelper:0.061 imagePullPolicy: Always ports: - containerPort: 8000 @@ -102,6 +102,16 @@ spec: configMapKeyRef: name: django-config key: LOGOUT_REDIRECT_URL + - name: GUNICORN_OPTS + valueFrom: + configMapKeyRef: + name: django-config + key: GUNICORN_OPTS + - name: IMAGE_TAG + valueFrom: + configMapKeyRef: + name: django-config + key: IMAGE_TAG volumeMounts: - name: data mountPath: /app/data diff --git a/labhelper/context_processors.py b/labhelper/context_processors.py new file mode 100644 index 0000000..df2443a --- /dev/null +++ b/labhelper/context_processors.py @@ -0,0 +1,8 @@ +import os + + +def image_tag(request): + """Add the image tag to all template contexts.""" + return { + 'image_tag': os.environ.get('IMAGE_TAG', 'dev') + } \ No newline at end of file diff --git a/labhelper/settings.py b/labhelper/settings.py index f01a773..7297dc8 100644 --- a/labhelper/settings.py +++ b/labhelper/settings.py @@ -67,6 +67,7 @@ TEMPLATES = [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'labhelper.context_processors.image_tag', ], }, }, diff --git a/labhelper/templates/base.html b/labhelper/templates/base.html index a773594..e39b330 100644 --- a/labhelper/templates/base.html +++ b/labhelper/templates/base.html @@ -435,6 +435,7 @@ {% block extra_js %}{% endblock %} diff --git a/scripts/full_deploy.sh b/scripts/full_deploy.sh index 9b2885e..5901818 100755 --- a/scripts/full_deploy.sh +++ b/scripts/full_deploy.sh @@ -36,10 +36,14 @@ NEW_MAIN_VERSION=$(echo "$MAIN_VERSION + 0.001" | bc | sed 's/^\./0./') 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" +# Update ConfigMap with new main container version +sed -i "s| IMAGE_TAG: \"$MAIN_VERSION\"| IMAGE_TAG: \"$NEW_MAIN_VERSION\"|" "argocd/configmap.yaml" + # 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 " ConfigMap IMAGE_TAG: $MAIN_VERSION -> $NEW_MAIN_VERSION" echo " Database copied to $DB_DEST" diff --git a/scripts/partial_deploy.sh b/scripts/partial_deploy.sh index 27966fe..172e6c9 100755 --- a/scripts/partial_deploy.sh +++ b/scripts/partial_deploy.sh @@ -23,5 +23,9 @@ 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/labhelper:$CURRENT_VERSION|image: git.baumann.gr/adebaumann/labhelper:$NEW_VERSION|" "$DEPLOYMENT_FILE" +# Update ConfigMap with new main container version +sed -i "s| IMAGE_TAG: \"$CURRENT_VERSION\"| IMAGE_TAG: \"$NEW_VERSION\"|" "argocd/configmap.yaml" + echo "Partial deployment prepared:" echo " Main container: $CURRENT_VERSION -> $NEW_VERSION" +echo " ConfigMap IMAGE_TAG: $CURRENT_VERSION -> $NEW_VERSION"