[damned-lies] chore: merge production and staging a bit more



commit 2182fe9686a22e19a68a4bb584c935213c0bb0e7
Author: Guillaume Bernard <associations guillaume-bernard fr>
Date:   Mon May 9 15:06:22 2022 +0200

    chore: merge production and staging a bit more

 ...h_production.sh => build_buildah_deployment.sh} | 20 ++++++++--
 ...uild_buildah_replace_staging_with_production.sh | 44 ++++++++++++++++++++++
 .../{ => configuration}/entrypoint.sh.jinja2       |  0
 .../{ => configuration}/httpd.conf.jinja2          |  5 ++-
 .../{ => configuration}/local_settings.py.jinja2   |  7 +++-
 .../production/{ => configuration}/production.json |  7 +++-
 .../production/{ => configuration}/staging.json    |  9 ++++-
 .../production/{ => configuration}/test.json       |  6 ++-
 .../production/render_configuration_templates.sh   |  8 +++-
 9 files changed, 95 insertions(+), 11 deletions(-)
---
diff --git a/containers/production/build_buildah_production.sh 
b/containers/production/build_buildah_deployment.sh
similarity index 86%
rename from containers/production/build_buildah_production.sh
rename to containers/production/build_buildah_deployment.sh
index 90fd1b3a..68ed253c 100755
--- a/containers/production/build_buildah_production.sh
+++ b/containers/production/build_buildah_deployment.sh
@@ -65,8 +65,17 @@ buildah add \
 buildah config --workingdir "${DAMNED_LIES_CONTAINER_CODE_DIRECTORY}"/damnedlies "${container}"
 
 # Copy project settings files
-buildah add --chown "${PROCESS_USER}:${PROCESS_USER}" --chmod 660 "${container}" 
"${THIS_SCRIPT_DIRECTORY}/${KIND_OF_DEPLOYMENT}/local_settings.py" 
"${DAMNED_LIES_CONTAINER_CODE_DIRECTORY}"/damnedlies/damnedlies/local_settings.py
-buildah add --chmod 644 "${container}" "${THIS_SCRIPT_DIRECTORY}/${KIND_OF_DEPLOYMENT}/httpd.conf" 
/etc/httpd/conf.d/l10n.gnome.org.conf
+buildah add \
+    --chown "${PROCESS_USER}:${PROCESS_USER}" \
+    --chmod 660 \
+    "${container}" \
+    "${THIS_SCRIPT_DIRECTORY}/${KIND_OF_DEPLOYMENT}/local_settings.py" \
+    "${DAMNED_LIES_CONTAINER_CODE_DIRECTORY}"/damnedlies/damnedlies/local_settings.py
+buildah add \
+    --chmod 644 \
+    "${container}" \
+    "${THIS_SCRIPT_DIRECTORY}/${KIND_OF_DEPLOYMENT}/httpd.conf" \
+    /etc/httpd/conf.d/l10n.gnome.org.conf
 
 # Install dependencies in the virtual environment
 buildah run "${container}" -- python3 -m venv --system-site-packages 
"${DAMNED_LIES_CONTAINER_CODE_DIRECTORY}"/venv
@@ -74,7 +83,12 @@ buildah run "${container}" -- "${DAMNED_LIES_CONTAINER_CODE_DIRECTORY}"/venv/bin
 buildah run "${container}" -- "${DAMNED_LIES_CONTAINER_CODE_DIRECTORY}"/venv/bin/pip install -r 
requirements.txt
 
 # Set the image entrypoint
-buildah add --chown "${PROCESS_USER}:${PROCESS_USER}" --chmod 770 "${container}" 
"${THIS_SCRIPT_DIRECTORY}/${KIND_OF_DEPLOYMENT}/entrypoint.sh" 
"${DAMNED_LIES_CONTAINER_CODE_DIRECTORY}/entrypoint.sh"
+buildah add \
+    --chown "${PROCESS_USER}:${PROCESS_USER}" \
+    --chmod 770 \
+    "${container}" \
+    "${THIS_SCRIPT_DIRECTORY}/${KIND_OF_DEPLOYMENT}/entrypoint.sh" \
+    "${DAMNED_LIES_CONTAINER_CODE_DIRECTORY}/entrypoint.sh"
 buildah config --entrypoint "${DAMNED_LIES_CONTAINER_CODE_DIRECTORY}/entrypoint.sh" "${container}"
 
 # Change ownership of HTTPd server and project to the user in the container
diff --git a/containers/production/build_buildah_replace_staging_with_production.sh 
b/containers/production/build_buildah_replace_staging_with_production.sh
new file mode 100755
index 00000000..fae8d3a3
--- /dev/null
+++ b/containers/production/build_buildah_replace_staging_with_production.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+
+# PROCESS_USER: the user that will run the httpd server and be authorised to access application files
+declare -r PROCESS_USER="l10n"
+
+# DAMNED_LIES_CONTAINER_CODE_DIRECTORY: where is located project code
+declare -r DAMNED_LIES_CONTAINER_CODE_DIRECTORY="/${PROCESS_USER}"
+
+# THIS_SCRIPT_DIRECTORY: the current script directory name
+THIS_SCRIPT_DIRECTORY="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
+declare -r THIS_SCRIPT_DIRECTORY
+
+# DAMNED_LIES_IMAGE_NAME: the target image name (without any tag)
+if [[ -z ${DAMNED_LIES_IMAGE_NAME+x} ]]; then
+    declare -r DAMNED_LIES_IMAGE_NAME="damned-lies-production"
+fi
+
+# CURRENT_VCS_REF_NAME: the name of the current branch, that is used to name the created image
+if [[ -z ${CURRENT_VCS_REF_NAME+x} ]]; then
+    CURRENT_VCS_REF_NAME="$(git branch --show-current)"
+fi
+declare -r CURRENT_VCS_REF_NAME
+
+#######################################################################################################################
+
+# Stop the shell script if at least one command fails
+set -e
+
+container=$(buildah from "${DAMNED_LIES_IMAGE_NAME}:${CURRENT_VCS_REF_NAME}-staging")
+
+# Copy project settings files
+buildah add \
+    --chown "${PROCESS_USER}:${PROCESS_USER}" \
+    --chmod 660 "${container}" \
+    "${THIS_SCRIPT_DIRECTORY}/production/local_settings.py" \
+    "${DAMNED_LIES_CONTAINER_CODE_DIRECTORY}"/damnedlies/damnedlies/local_settings.py
+
+buildah add \
+    --chmod 644 "${container}" \
+    "${THIS_SCRIPT_DIRECTORY}/production/httpd.conf" \
+    /etc/httpd/conf.d/l10n.gnome.org.conf
+
+# Commit container to image
+buildah commit "${container}" "${DAMNED_LIES_IMAGE_NAME}:${CURRENT_VCS_REF_NAME}-production"
diff --git a/containers/production/entrypoint.sh.jinja2 
b/containers/production/configuration/entrypoint.sh.jinja2
similarity index 100%
rename from containers/production/entrypoint.sh.jinja2
rename to containers/production/configuration/entrypoint.sh.jinja2
diff --git a/containers/production/httpd.conf.jinja2 b/containers/production/configuration/httpd.conf.jinja2
similarity index 96%
rename from containers/production/httpd.conf.jinja2
rename to containers/production/configuration/httpd.conf.jinja2
index e041c85c..68f3bb6f 100644
--- a/containers/production/httpd.conf.jinja2
+++ b/containers/production/configuration/httpd.conf.jinja2
@@ -1,7 +1,8 @@
 <VirtualHost *:8080>
     ServerName {{ server.name }}
-    ServerAlias localhost
-    ServerAlias 127.0.0.1
+    {% for alias in server.aliases %}
+    ServerAlias {{ alias }}
+    {% endfor %}
 
     Alias /HTML {{ damned_lies_data_directory }}/scratchdir/HTML
     Alias /POT {{ damned_lies_data_directory }}/scratchdir/POT
diff --git a/containers/production/local_settings.py.jinja2 
b/containers/production/configuration/local_settings.py.jinja2
similarity index 92%
rename from containers/production/local_settings.py.jinja2
rename to containers/production/configuration/local_settings.py.jinja2
index 36770e5b..c75de696 100644
--- a/containers/production/local_settings.py.jinja2
+++ b/containers/production/configuration/local_settings.py.jinja2
@@ -38,7 +38,12 @@ DEBUG = False
 SECRET_KEY = """$SECRET_KEY"""
 
 SITE_DOMAIN = "{{ server.name }}"
-ALLOWED_HOSTS = ["{{ server.name }}", "8.43.85.13", "8.43.85.14", "8.43.85.29", "localhost", "127.0.0.1"]
+ALLOWED_HOSTS = [
+    "{{ server.name }}",
+{% for server_alias in server.aliases %}
+    "{{ server_alias }}",
+{% endfor %}
+]
 SESSION_COOKIE_SECURE = True
 CSRF_COOKIE_SECURE = True
 SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
diff --git a/containers/production/production.json b/containers/production/configuration/production.json
similarity index 82%
rename from containers/production/production.json
rename to containers/production/configuration/production.json
index d889d6d5..a081bbe2 100644
--- a/containers/production/production.json
+++ b/containers/production/configuration/production.json
@@ -1,6 +1,11 @@
 {
     "server": {
-        "name": "l10n.gnome.org"
+        "name": "l10n.gnome.org",
+        "aliases": [
+            "8.43.85.13",
+            "8.43.85.14",
+            "8.43.85.29"
+        ]
     },
     "kind": "production",
     "damned_lies_project_directory": "/l10n/damnedlies",
diff --git a/containers/production/staging.json b/containers/production/configuration/staging.json
similarity index 78%
rename from containers/production/staging.json
rename to containers/production/configuration/staging.json
index 3f5c511d..b5c633bf 100644
--- a/containers/production/staging.json
+++ b/containers/production/configuration/staging.json
@@ -1,6 +1,13 @@
 {
     "server": {
-        "name": "l10n-staging.openshift.gnome.org"
+        "name": "l10n-staging.openshift.gnome.org",
+        "aliases": [
+            "8.43.85.13",
+            "8.43.85.14",
+            "8.43.85.29",
+            "127.0.0.1",
+            "localhost"
+        ]
     },
     "kind": "production",
     "damned_lies_project_directory": "/l10n/damnedlies",
diff --git a/containers/production/test.json b/containers/production/configuration/test.json
similarity index 83%
rename from containers/production/test.json
rename to containers/production/configuration/test.json
index a7e71786..d27af9e5 100644
--- a/containers/production/test.json
+++ b/containers/production/configuration/test.json
@@ -1,6 +1,10 @@
 {
     "server": {
-        "name": "l10n-testing.openshift.gnome.org"
+        "name": "l10n-testing.openshift.gnome.org",
+        "aliases": [
+            "127.0.0.1",
+            "localhost"
+        ]
     },
     "kind": "test",
     "damned_lies_project_directory": "/l10n/damnedlies",
diff --git a/containers/production/render_configuration_templates.sh 
b/containers/production/render_configuration_templates.sh
index c604173f..5742aa80 100755
--- a/containers/production/render_configuration_templates.sh
+++ b/containers/production/render_configuration_templates.sh
@@ -13,6 +13,10 @@ THIS_SCRIPT_DIRECTORY="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
 declare -r THIS_SCRIPT_DIRECTORY
 
 mkdir -p "${THIS_SCRIPT_DIRECTORY}/${KIND_OF_DEPLOYMENT}"
-for template in "${THIS_SCRIPT_DIRECTORY}"/*.jinja2; do
-    jinja2 --strict "${template}" "${THIS_SCRIPT_DIRECTORY}/${KIND_OF_DEPLOYMENT}.json" > 
"${THIS_SCRIPT_DIRECTORY}/${KIND_OF_DEPLOYMENT}/$(basename "${template}" .jinja2)"
+for template in "${THIS_SCRIPT_DIRECTORY}"/configuration/*.jinja2; do
+    jinja2 \
+        --strict \
+        "${template}" \
+        "${THIS_SCRIPT_DIRECTORY}/configuration/${KIND_OF_DEPLOYMENT}.json" \
+        > "${THIS_SCRIPT_DIRECTORY}/${KIND_OF_DEPLOYMENT}/$(basename "${template}" .jinja2)"
 done


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]