diff --git a/.env.example b/.env.example index c256d44..1470415 100644 --- a/.env.example +++ b/.env.example @@ -6,6 +6,7 @@ APP_URL=http://localhost APP_URL_FRONT= LOG_CHANNEL=stack +LOG_LEVEL=debug DB_HOST=127.0.0.1 DB_DATABASE=laravel diff --git a/k8s-queues.sh b/k8s-queues.sh new file mode 100644 index 0000000..76dd2eb --- /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 45s + exit 0 +} + +# handle graceful shutdown +trap "" SIGPIPE +trap stopQueues EXIT + +echo "Starting PHP queue workers..." + +while $work; do + php artisan queue:work database --queue=default,database --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 &) diff --git a/manifest.yaml b/manifest.yaml index b2cbcae..28e0f89 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -10,6 +10,7 @@ data: APP_URL: "https://${APP_DOMAIN}" APP_URL_FRONT: "${APP_APP_URL_FRONT}" LOG_CHANNEL: "k8s" + LOG_LEVEL: "${APP_LOG_LEVEL}" DB_HOST: "mariadb.common-services" DB_DATABASE: "${APP_DB_DATABASE}" DB_USERNAME: "${APP_DB_USERNAME}" @@ -23,6 +24,7 @@ data: MAIL_FROM_NAME: "${APP_APP_NAME}" LDC_WEB_API_KEY: "${APP_LDC_WEB_API_KEY}" SENTRY_LARAVEL_DSN: "${APP_SENTRY_LARAVEL_DSN}" + QUEUE_CONNECTION: "${APP_QUEUE_CONNECTION}" --- apiVersion: v1 @@ -32,7 +34,7 @@ metadata: spec: storageClassName: "csi-cinder-classic" accessModes: - - ReadWriteOnce + - ReadWriteOnce resources: requests: storage: $APP_PVC_SIZE @@ -53,28 +55,47 @@ spec: app: ${CI_PROJECT_PATH_SLUG}-app spec: containers: - - name: ${CI_PROJECT_PATH_SLUG}-container - image: $IMAGE_TAG - imagePullPolicy: Always - envFrom: - - configMapRef: - name: ${CI_PROJECT_PATH_SLUG}-config-map - volumeMounts: - - name: storage - mountPath: /app/srcs/storage/app/public + - name: ${CI_PROJECT_PATH_SLUG}-container + image: $IMAGE_TAG + envFrom: + - configMapRef: + name: ${CI_PROJECT_PATH_SLUG}-config-map + volumeMounts: + - name: storage + mountPath: /app/srcs/storage/app/public + - name: ${CI_PROJECT_PATH_SLUG}-queue-worker + image: $IMAGE_TAG + lifecycle: + preStop: + exec: + command: + [ + "/bin/sh", + "-c", + "kill -s TERM 1; while test $(ps ax | grep -v grep | grep bash | wc -l) -gt 0; do sleep 2s; done", + ] + command: + - "bash" + args: + - "k8s-queues.sh" + envFrom: + - configMapRef: + name: ${CI_PROJECT_PATH_SLUG}-config-map + volumeMounts: + - name: storage + mountPath: /app/srcs/storage imagePullSecrets: - - name: docker-registry-credentials + - name: docker-registry-credentials volumes: - - name: storage - persistentVolumeClaim: - claimName: ${CI_PROJECT_PATH_SLUG}-pvc-storage + - name: storage + persistentVolumeClaim: + claimName: ${CI_PROJECT_PATH_SLUG}-pvc-storage securityContext: runAsUser: 33 runAsGroup: 33 fsGroup: 33 fsGroupChangePolicy: "OnRootMismatch" - --- apiVersion: v1 kind: Service @@ -84,8 +105,8 @@ spec: selector: app: ${CI_PROJECT_PATH_SLUG}-app ports: - - port: 80 - targetPort: 443 + - port: 80 + targetPort: 443 --- apiVersion: traefik.io/v1alpha1 @@ -94,14 +115,14 @@ metadata: name: ${CI_PROJECT_PATH_SLUG}-ingress-route spec: entryPoints: - - web - - websecure + - web + - websecure routes: - - match: Host(`$APP_DOMAIN`) - kind: Rule - services: - - name: ${CI_PROJECT_PATH_SLUG}-service - port: 80 + - match: Host(`$APP_DOMAIN`) + kind: Rule + services: + - name: ${CI_PROJECT_PATH_SLUG}-service + port: 80 tls: secretName: ${CRT_TLS_NAME} @@ -120,35 +141,35 @@ spec: affinity: podAffinity: requiredDuringSchedulingIgnoredDuringExecution: - - labelSelector: - matchExpressions: - - key: app - operator: In - values: - - ${CI_PROJECT_PATH_SLUG}-app - topologyKey: "kubernetes.io/hostname" - namespaces: [$KUBE_NAMESPACE] + - labelSelector: + matchExpressions: + - key: app + operator: In + values: + - ${CI_PROJECT_PATH_SLUG}-app + topologyKey: "kubernetes.io/hostname" + namespaces: [$KUBE_NAMESPACE] containers: - - name: ${CI_PROJECT_PATH_SLUG}-scheduled - image: $IMAGE_TAG - imagePullPolicy: Always - command: - - "php" - args: - - "artisan" - - "schedule:run" - envFrom: - - configMapRef: - name: ${CI_PROJECT_PATH_SLUG}-config-map - volumeMounts: - - name: storage - mountPath: /app/srcs/storage/app/public + - name: ${CI_PROJECT_PATH_SLUG}-scheduled + image: $IMAGE_TAG + imagePullPolicy: IfNotPresent + command: + - "php" + args: + - "artisan" + - "schedule:run" + envFrom: + - configMapRef: + name: ${CI_PROJECT_PATH_SLUG}-config-map + volumeMounts: + - name: storage + mountPath: /app/srcs/storage/app/public imagePullSecrets: - - name: docker-registry-credentials + - name: docker-registry-credentials volumes: - - name: storage - persistentVolumeClaim: - claimName: ${CI_PROJECT_PATH_SLUG}-pvc-storage + - name: storage + persistentVolumeClaim: + claimName: ${CI_PROJECT_PATH_SLUG}-pvc-storage securityContext: runAsUser: 33 runAsGroup: 33