From e8422180c4b4984c16c93ab1f37b695231629102 Mon Sep 17 00:00:00 2001 From: Glenn Date: Mon, 8 Jul 2024 22:09:58 +0200 Subject: [PATCH 1/5] ci: improve caching in docker --- .drone.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 22d4b22..0ac15a2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -41,7 +41,9 @@ steps: from_secret: DOCKERHUB_USERNAME password: from_secret: DOCKERHUB_PASSWORD - cache_from: "glenux/service-nextcloud:latest_${DRONE_BRANCH/\\//-}" + cache_from: + - "glenux/service-nextcloud:${DRONE_COMMIT_SHA:0:8}" + - "glenux/service-nextcloud:latest_${DRONE_BRANCH/\\//-}" repo: glenux/service-nextcloud tags: "latest_${DRONE_BRANCH/\\//-}" purge: false @@ -60,7 +62,9 @@ steps: from_secret: DOCKERHUB_USERNAME password: from_secret: DOCKERHUB_PASSWORD - cache_from: "glenux/service-nextcloud:latest_${DRONE_BRANCH/\\//-}" + cache_from: + - "glenux/service-nextcloud:${DRONE_COMMIT_SHA:0:8}" + - "glenux/service-nextcloud:latest_${DRONE_BRANCH/\\//-}" repo: glenux/service-nextcloud tags: latest purge: false -- 2.43.4 From b981d256965bd55736218697b8466fb10d92b1cb Mon Sep 17 00:00:00 2001 From: Glenn Date: Sat, 20 Jul 2024 11:45:04 +0200 Subject: [PATCH 2/5] fix: add logs --- postdeploy_hook.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/postdeploy_hook.sh b/postdeploy_hook.sh index 226408b..dcf5d85 100755 --- a/postdeploy_hook.sh +++ b/postdeploy_hook.sh @@ -1,4 +1,5 @@ #!/bin/sh +echo "Running postdeploy hooks as www-data" su -l -s /bin/sh www-data -c /app/postdeploy.sh -- 2.43.4 From 8c88f074e0ed2cb20ca5b96bbfdf7d84548f3b3c Mon Sep 17 00:00:00 2001 From: Glenn Date: Sat, 20 Jul 2024 16:47:28 +0200 Subject: [PATCH 3/5] fix: reorganize hook actions --- Dockerfile | 7 +++-- hooks/gx.before-starting.root.sh | 7 +++++ .../gx.before-starting.www.sh | 19 +++++++----- hooks/gx.post-installation.root.sh | 8 +++++ hooks/gx.post-installation.www.sh | 31 +++++++++++++++++++ postdeploy_hook.sh | 5 --- 6 files changed, 62 insertions(+), 15 deletions(-) create mode 100755 hooks/gx.before-starting.root.sh rename postdeploy.sh => hooks/gx.before-starting.www.sh (57%) create mode 100755 hooks/gx.post-installation.root.sh create mode 100755 hooks/gx.post-installation.www.sh delete mode 100755 postdeploy_hook.sh diff --git a/Dockerfile b/Dockerfile index 0b1c552..20c5d74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -100,8 +100,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && mkdir /var/log/supervisord /var/run/supervisord COPY supervisord.conf /etc/supervisord.conf -COPY --chmod=755 ./postdeploy.sh /app/postdeploy.sh -COPY --chmod=755 ./postdeploy_hook.sh /docker-entrypoint-hooks.d/post-installation/postdeploy_hook.sh +COPY --chmod=755 ./hooks/gx.post-installation.www.sh /app/gx.post-installation.www.sh +COPY --chmod=755 ./hooks/gx.post-installation.root.sh /docker-entrypoint-hooks.d/post-installation/gx.post-installation.root.sh + +COPY --chmod=755 ./hooks/gx.before-starting.www.sh /app/gx.before-starting.www.sh +COPY --chmod=755 ./hooks/gx.before-starting.root.sh /docker-entrypoint-hooks.d/before-starting/gx.before-starting.root.sh ENV NEXTCLOUD_UPDATE=1 diff --git a/hooks/gx.before-starting.root.sh b/hooks/gx.before-starting.root.sh new file mode 100755 index 0000000..fc8fc9f --- /dev/null +++ b/hooks/gx.before-starting.root.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -u +set -e + +echo "== Running post-installation hooks as root user ==" +su -l -s /bin/sh www-data -c /app/gx.before-starting.www.sh diff --git a/postdeploy.sh b/hooks/gx.before-starting.www.sh similarity index 57% rename from postdeploy.sh rename to hooks/gx.before-starting.www.sh index 145f7b1..5a856a9 100755 --- a/postdeploy.sh +++ b/hooks/gx.before-starting.www.sh @@ -3,26 +3,29 @@ set -u set -e +echo "== Running post-installation hooks as www user ==" + +# wait for nextcloud to be initialized WORKDIR=/var/www/html counter=0 while [ ! -d "$WORKDIR" ] && [ "$counter" -lt 120 ]; do - echo "GYR:POSTDEPLOY:WAITING" + echo "GX:BEFORE-STARTING:WAITING" counter=$((counter+1)) sleep 1 done cd "$WORKDIR" || exit 1 -echo "GYR:POSTDEPLOY:START ($(pwd))" -find . -maxdepth 1 -echo "GYR:POSTDEPLOY:UPGRADE" +echo "GX:BEFORE-STARTING:START ($(pwd))" +# find . -maxdepth 1 +echo "GX:BEFORE-STARTING:UPGRADE" php -d memory_limit=-1 occ upgrade -echo "GYR:POSTDEPLOY:DB" +echo "GX:BEFORE-STARTING:DB" php -d memory_limit=-1 occ db:convert-filecache-bigint php -d memory_limit=-1 occ db:add-missing-indices -echo "GYR:POSTDEPLOY:HTACCESS" +echo "GX:BEFORE-STARTING:HTACCESS" php -d memory_limit=-1 occ maintenance:update:htaccess -echo "GYR:POSTDEPLOY:MAINTENANCE:OFF" +echo "GX:BEFORE-STARTING:MAINTENANCE:OFF" php -d memory_limit=-1 occ maintenance:mode --off php -d memory_limit=-1 occ maintenance:mode --off || true -echo "GYR:POSTDEPLOY:END" +echo "GX:BEFORE-STARTING:END" diff --git a/hooks/gx.post-installation.root.sh b/hooks/gx.post-installation.root.sh new file mode 100755 index 0000000..509bc77 --- /dev/null +++ b/hooks/gx.post-installation.root.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +set -u +set -e + +echo "== Running post-installation hooks as root user ==" +su -l -s /bin/sh www-data -c /app/gx.post-installation.www.sh + diff --git a/hooks/gx.post-installation.www.sh b/hooks/gx.post-installation.www.sh new file mode 100755 index 0000000..b659773 --- /dev/null +++ b/hooks/gx.post-installation.www.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +set -u +set -e + +echo "== Running post-installation hooks as www user ==" + +# wait for nextcloud to be initialized +WORKDIR=/var/www/html +counter=0 +while [ ! -d "$WORKDIR" ] && [ "$counter" -lt 120 ]; do + echo "GX:POST-INSTALLATION:WAITING" + counter=$((counter+1)) + sleep 1 +done +cd "$WORKDIR" || exit 1 + +echo "GX:POST-INSTALLATION:START ($(pwd))" +# # find . -maxdepth 1 +# echo "GX:POST-INSTALLATION:UPGRADE" +# php -d memory_limit=-1 occ upgrade +# echo "GX:POST-INSTALLATION:DB" +# php -d memory_limit=-1 occ db:convert-filecache-bigint +# php -d memory_limit=-1 occ db:add-missing-indices +# echo "GX:POST-INSTALLATION:HTACCESS" +# php -d memory_limit=-1 occ maintenance:update:htaccess +# echo "GX:POST-INSTALLATION:MAINTENANCE:OFF" +# php -d memory_limit=-1 occ maintenance:mode --off +# php -d memory_limit=-1 occ maintenance:mode --off || true +echo "GX:POST-INSTALLATION:END" + diff --git a/postdeploy_hook.sh b/postdeploy_hook.sh deleted file mode 100755 index dcf5d85..0000000 --- a/postdeploy_hook.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -echo "Running postdeploy hooks as www-data" -su -l -s /bin/sh www-data -c /app/postdeploy.sh - -- 2.43.4 From 9774108d7942785cc8a8c95fbd1b1b56d28f7b95 Mon Sep 17 00:00:00 2001 From: Glenn Date: Sat, 20 Jul 2024 16:47:39 +0200 Subject: [PATCH 4/5] feat: add makefile --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a4de9c0 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ + +all: + +build: + docker-compose build + +run: + docker-compose up -d -- 2.43.4 From 55c1b4217016ad97251ef21316a248fd936bffdb Mon Sep 17 00:00:00 2001 From: Glenn Date: Sat, 20 Jul 2024 16:54:11 +0200 Subject: [PATCH 5/5] fix: change permissions for hooks --- Dockerfile | 7 +++---- Makefile | 4 ++-- hooks/gx.before-starting.root.sh | 2 +- hooks/gx.before-starting.www.sh | 2 +- hooks/gx.post-installation.root.sh | 2 +- hooks/gx.post-installation.www.sh | 2 +- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 20c5d74..59908e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -100,11 +100,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && mkdir /var/log/supervisord /var/run/supervisord COPY supervisord.conf /etc/supervisord.conf -COPY --chmod=755 ./hooks/gx.post-installation.www.sh /app/gx.post-installation.www.sh -COPY --chmod=755 ./hooks/gx.post-installation.root.sh /docker-entrypoint-hooks.d/post-installation/gx.post-installation.root.sh +# COPY --chmod=755 ./hooks/gx.post-installation.www.sh /app/gx.post-installation.www.sh +# COPY --chmod=755 ./hooks/gx.post-installation.root.sh /docker-entrypoint-hooks.d/post-installation/gx.post-installation.root.sh -COPY --chmod=755 ./hooks/gx.before-starting.www.sh /app/gx.before-starting.www.sh -COPY --chmod=755 ./hooks/gx.before-starting.root.sh /docker-entrypoint-hooks.d/before-starting/gx.before-starting.root.sh +COPY --chmod=755 ./hooks/gx.before-starting.www.sh /docker-entrypoint-hooks.d/before-starting/gx.before-starting.www.sh ENV NEXTCLOUD_UPDATE=1 diff --git a/Makefile b/Makefile index a4de9c0..350737a 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ all: build: - docker-compose build + docker compose build run: - docker-compose up -d + docker compose up -d diff --git a/hooks/gx.before-starting.root.sh b/hooks/gx.before-starting.root.sh index fc8fc9f..4e0a64d 100755 --- a/hooks/gx.before-starting.root.sh +++ b/hooks/gx.before-starting.root.sh @@ -3,5 +3,5 @@ set -u set -e -echo "== Running post-installation hooks as root user ==" +echo "== Running before-starting hooks as $(id -un) user ==" su -l -s /bin/sh www-data -c /app/gx.before-starting.www.sh diff --git a/hooks/gx.before-starting.www.sh b/hooks/gx.before-starting.www.sh index 5a856a9..a1cc0da 100755 --- a/hooks/gx.before-starting.www.sh +++ b/hooks/gx.before-starting.www.sh @@ -3,7 +3,7 @@ set -u set -e -echo "== Running post-installation hooks as www user ==" +echo "== Running before-starting hooks as $(id -un) user ==" # wait for nextcloud to be initialized WORKDIR=/var/www/html diff --git a/hooks/gx.post-installation.root.sh b/hooks/gx.post-installation.root.sh index 509bc77..22d6b90 100755 --- a/hooks/gx.post-installation.root.sh +++ b/hooks/gx.post-installation.root.sh @@ -3,6 +3,6 @@ set -u set -e -echo "== Running post-installation hooks as root user ==" +echo "== Running post-installation hooks as $(id -un) user ==" su -l -s /bin/sh www-data -c /app/gx.post-installation.www.sh diff --git a/hooks/gx.post-installation.www.sh b/hooks/gx.post-installation.www.sh index b659773..eac88a5 100755 --- a/hooks/gx.post-installation.www.sh +++ b/hooks/gx.post-installation.www.sh @@ -3,7 +3,7 @@ set -u set -e -echo "== Running post-installation hooks as www user ==" +echo "== Running post-installation hooks as $(id -un) user ==" # wait for nextcloud to be initialized WORKDIR=/var/www/html -- 2.43.4