From 9ac4da9a5c04af27737cf6aa9f2f4d4621635bca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 9 Oct 2023 11:45:25 +0200 Subject: [PATCH 1/4] add /bootstrap to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 771617f..c06ef95 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /.phpunit.cache /.vscode /node_modules +/bootstrap /public/build /public/cache /public/hot From 4e57bfdb15c59d27de00dc5d1c0bc4bbaeee63ef Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Mon, 11 Dec 2023 12:15:57 +0100 Subject: [PATCH 2/4] Update Dockerfile --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f26f30d..0c9015f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ FROM registry.s-web.fr/ldc-web/projets/ldc-web-images-docker/ldcweb-production-8.2:latest COPY --chown=www-data:www-data . /app/srcs -COPY --chown=www-data:www-data ./public /app/srcs/public -COPY --chown=www-data:www-data ./vendor /app/srcs/vendor USER root RUN chmod -R 755 /app/srcs/storage USER www-data From 75e65e7ebeaf87081d66c79f37e70fa80c68bba9 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Mon, 11 Dec 2023 12:16:21 +0100 Subject: [PATCH 3/4] Update Manifest Cron ImagePolicy --- manifest.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.yaml b/manifest.yaml index 713bba4..1c9beda 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -144,7 +144,7 @@ spec: containers: - name: ${CI_PROJECT_PATH_SLUG}-scheduled image: $IMAGE_TAG - imagePullPolicy: Always + imagePullPolicy: IfNotPresent command: - "php" args: From dcf222e1a2645329d9c5ce719163e86c040d0510 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Mon, 11 Dec 2023 15:57:36 +0100 Subject: [PATCH 4/4] Add K8S config for queues --- k8s-queues.sh | 30 ++++++++++++++++++++++++++++++ manifest.yaml | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 k8s-queues.sh diff --git a/k8s-queues.sh b/k8s-queues.sh new file mode 100644 index 0000000..c1bd473 --- /dev/null +++ b/k8s-queues.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# From https://stackoverflow.com/a/76488746/17320077 + +work=true + +function stopQueues() { + echo "Stopping queues..." + work=false + php artisan queue:restart + sleep 300 + exit 0 +} + +# handle graceful shutdown +trap "" SIGPIPE +trap stopQueues SIGTERM SIGINT SIGHUP + +echo "Starting PHP queue workers..." + +while $work; do + php artisan queue:work --queue=default,stats --sleep=3 --tries=3 --max-time=3600 --no-interaction + sleep 1 +done + +# Si besoin de plusieurs threads puis terminer par un done sans & +#(while $work; do +# php artisan queue:work --queue="$(grep -oP 'SQS_QUEUE=\K.*' .env)" --no-interaction +# sleep 1 +#done &) \ No newline at end of file diff --git a/manifest.yaml b/manifest.yaml index 1c9beda..cfafea4 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -168,3 +168,41 @@ spec: fsGroup: 33 fsGroupChangePolicy: "OnRootMismatch" restartPolicy: OnFailure + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ${CI_PROJECT_PATH_SLUG}-queue-worker-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: ${CI_PROJECT_PATH_SLUG}-app + template: + metadata: + labels: + app: ${CI_PROJECT_PATH_SLUG}-app + spec: + containers: + - name: ${CI_PROJECT_PATH_SLUG}-container + image: $IMAGE_TAG + command: + - "bash k8s-queues.sh" + envFrom: + - configMapRef: + name: ${CI_PROJECT_PATH_SLUG}-config-map + volumeMounts: + - name: storage + mountPath: /app/srcs/storage + imagePullSecrets: + - name: docker-registry-credentials + securityContext: + runAsUser: 33 + runAsGroup: 33 + fsGroup: 33 + fsGroupChangePolicy: "OnRootMismatch" + volumes: + - name: storage + persistentVolumeClaim: + claimName: ${CI_PROJECT_PATH_SLUG}-pvc-storage \ No newline at end of file