From 074966ca8934450d402475020b608277d60a4063 Mon Sep 17 00:00:00 2001 From: tuutti Date: Wed, 12 Feb 2025 09:42:29 +0200 Subject: [PATCH 1/6] Add cron and deploy entrypoints to Drupal image --- openshift/drupal/Dockerfile | 3 +- .../files/usr/local/bin/cron-entrypoint | 42 +++++++++++++++++++ .../usr/local/bin/drush-deploy-entrypoint | 22 ++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 openshift/drupal/files/usr/local/bin/cron-entrypoint create mode 100644 openshift/drupal/files/usr/local/bin/drush-deploy-entrypoint diff --git a/openshift/drupal/Dockerfile b/openshift/drupal/Dockerfile index 56a22f0..a41c125 100644 --- a/openshift/drupal/Dockerfile +++ b/openshift/drupal/Dockerfile @@ -49,7 +49,8 @@ COPY files/ / COPY files/etc/profile.d/ /etc/bash RUN chmod +x /entrypoints/* && \ - chmod +x /usr/local/bin/entrypoint + chmod +x /usr/local/bin/entrypoint && \ + ENV PATH=${PATH}:/app/vendor/bin:/var/www/html/vendor/bin ENV COMPOSER_HOME=/.composer diff --git a/openshift/drupal/files/usr/local/bin/cron-entrypoint b/openshift/drupal/files/usr/local/bin/cron-entrypoint new file mode 100644 index 0000000..b9f5523 --- /dev/null +++ b/openshift/drupal/files/usr/local/bin/cron-entrypoint @@ -0,0 +1,42 @@ +#!/bin/bash + +source /init.sh + +echo "Starting cron: $(date)" + +# You can add any additional cron "daemons" to docker/openshift/crons/ folder. +# +# Example: +# @code +# #!/bin/bash +# while true +# do +# drush some-command +# sleep 600 +# done +# @endcode + +for cron in /crons/*.sh; do + # Skip legacy base.sh script if it exists. + # Skip Kubernetes hooks that are stored in crons directory. + if [[ "${cron##*/}" == "base.sh" ]] || [[ "${cron##*/}" == *-hook.sh ]]; then + continue + elif [[ -r "$cron" ]]; then + echo "Starting $cron" + exec "$cron" & + fi +done + +while true +do + # Rudimentary process supervisor: + # Waits for the next process to terminate. The parent + # process is killed if any subprocess exists with failure. + # OpenShift should then restart the cron pod. + wait -n + exit_code=$? + if [[ "$exit_code" -ne 0 ]]; then + output_error_message "Cron subprocess failed with exit code $exit_code" + exit 1 + fi +done diff --git a/openshift/drupal/files/usr/local/bin/drush-deploy-entrypoint b/openshift/drupal/files/usr/local/bin/drush-deploy-entrypoint new file mode 100644 index 0000000..b7af038 --- /dev/null +++ b/openshift/drupal/files/usr/local/bin/drush-deploy-entrypoint @@ -0,0 +1,22 @@ +#!/bin/sh + +source /init.sh +# Run preflight checks manually. +source /entrypoints/10-preflight.sh + +# This script will be the default ENTRYPOINT for deployment job pod. +# It just sources all files within /deploy/* in an alphabetical order and then runs `exec` on the given parameter. +if [ -d /deploy ]; then + for i in /deploy/*; do + if [ -r $i ]; then + echo "# Source $i" + . $i + else + echo "! $i not sourced" + fi + done + unset i +fi + +echo "Exec: $@" +exec "$@" From db366c0c617140a1cc3de9710ec81527a33f1f8d Mon Sep 17 00:00:00 2001 From: tuutti Date: Wed, 12 Feb 2025 09:43:00 +0200 Subject: [PATCH 2/6] Removed newline --- openshift/drupal/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openshift/drupal/Dockerfile b/openshift/drupal/Dockerfile index a41c125..56a22f0 100644 --- a/openshift/drupal/Dockerfile +++ b/openshift/drupal/Dockerfile @@ -49,8 +49,7 @@ COPY files/ / COPY files/etc/profile.d/ /etc/bash RUN chmod +x /entrypoints/* && \ - chmod +x /usr/local/bin/entrypoint && \ - + chmod +x /usr/local/bin/entrypoint ENV PATH=${PATH}:/app/vendor/bin:/var/www/html/vendor/bin ENV COMPOSER_HOME=/.composer From a73a58c6232455d2caec6f7b247b4786b94cbd18 Mon Sep 17 00:00:00 2001 From: tuutti Date: Wed, 12 Feb 2025 09:45:56 +0200 Subject: [PATCH 3/6] Removed preflight check --- openshift/drupal/files/usr/local/bin/drush-deploy-entrypoint | 2 -- 1 file changed, 2 deletions(-) diff --git a/openshift/drupal/files/usr/local/bin/drush-deploy-entrypoint b/openshift/drupal/files/usr/local/bin/drush-deploy-entrypoint index b7af038..217702b 100644 --- a/openshift/drupal/files/usr/local/bin/drush-deploy-entrypoint +++ b/openshift/drupal/files/usr/local/bin/drush-deploy-entrypoint @@ -1,8 +1,6 @@ #!/bin/sh source /init.sh -# Run preflight checks manually. -source /entrypoints/10-preflight.sh # This script will be the default ENTRYPOINT for deployment job pod. # It just sources all files within /deploy/* in an alphabetical order and then runs `exec` on the given parameter. From 9c214efe8fade6e5eec22eb98dcb2b37482bad40 Mon Sep 17 00:00:00 2001 From: tuutti Date: Fri, 14 Feb 2025 07:00:14 +0200 Subject: [PATCH 4/6] Added dummy init.sh --- local/drupal/files/init.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 local/drupal/files/init.sh diff --git a/local/drupal/files/init.sh b/local/drupal/files/init.sh new file mode 100644 index 0000000..d1ad31c --- /dev/null +++ b/local/drupal/files/init.sh @@ -0,0 +1,2 @@ +#!/bin/bash +# This file will be overridden by project's Dockerfile. From 79b9eda99127242fa061b0be3b1a7059a5ff9171 Mon Sep 17 00:00:00 2001 From: tuutti Date: Fri, 14 Feb 2025 07:04:17 +0200 Subject: [PATCH 5/6] Comments --- openshift/drupal/files/usr/local/bin/cron-entrypoint | 2 +- openshift/drupal/files/usr/local/bin/drush-deploy-entrypoint | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/openshift/drupal/files/usr/local/bin/cron-entrypoint b/openshift/drupal/files/usr/local/bin/cron-entrypoint index b9f5523..3ff3fc9 100644 --- a/openshift/drupal/files/usr/local/bin/cron-entrypoint +++ b/openshift/drupal/files/usr/local/bin/cron-entrypoint @@ -4,7 +4,7 @@ source /init.sh echo "Starting cron: $(date)" -# You can add any additional cron "daemons" to docker/openshift/crons/ folder. +# You can add any additional cron "daemons" to project's docker/openshift/crons/ folder. # # Example: # @code diff --git a/openshift/drupal/files/usr/local/bin/drush-deploy-entrypoint b/openshift/drupal/files/usr/local/bin/drush-deploy-entrypoint index 217702b..bf04a24 100644 --- a/openshift/drupal/files/usr/local/bin/drush-deploy-entrypoint +++ b/openshift/drupal/files/usr/local/bin/drush-deploy-entrypoint @@ -4,6 +4,7 @@ source /init.sh # This script will be the default ENTRYPOINT for deployment job pod. # It just sources all files within /deploy/* in an alphabetical order and then runs `exec` on the given parameter. +# You can add additional deploy scripts to project's docker/openshift/deploy folder. if [ -d /deploy ]; then for i in /deploy/*; do if [ -r $i ]; then From b56f5659c10dbadc867e352b0c93818f70de77bd Mon Sep 17 00:00:00 2001 From: tuutti Date: Fri, 14 Feb 2025 08:03:34 +0200 Subject: [PATCH 6/6] chmod all files in usr/local/bin --- openshift/drupal/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openshift/drupal/Dockerfile b/openshift/drupal/Dockerfile index 56a22f0..e87b8b8 100644 --- a/openshift/drupal/Dockerfile +++ b/openshift/drupal/Dockerfile @@ -49,7 +49,7 @@ COPY files/ / COPY files/etc/profile.d/ /etc/bash RUN chmod +x /entrypoints/* && \ - chmod +x /usr/local/bin/entrypoint + chmod +x /usr/local/bin/* ENV PATH=${PATH}:/app/vendor/bin:/var/www/html/vendor/bin ENV COMPOSER_HOME=/.composer