From af5dea4e0df319194e86d2a01ea7dd3eff8b1fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Fri, 13 Oct 2023 11:57:18 +0200 Subject: [PATCH] Add CD Files --- .dockerignore | 2 + .gitlab-ci.yml | 41 ++++++------ Dockerfile | 5 ++ manifest.yaml | 169 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 196 insertions(+), 21 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 manifest.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7476aa0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.git +*.md \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 219a6c1..6c3e4af 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,24 +1,23 @@ include: - - project: 'ldc-web/shared-ci' - ref: 'main' - file: 'lint/lint.yml' - - project: 'ldc-web/shared-ci' - ref: 'main' - file: 'security/security.yml' - - project: 'ldc-web/shared-ci' - ref: 'main' - file: 'build/build.yml' - - project: 'ldc-web/shared-ci' - ref: 'main' - file: 'test/test.yml' - - project: 'ldc-web/shared-ci' - ref: 'main' - file: 'deploy/deploy.yml' - + - project: "ldc-web/shared-ci" + ref: "main" + file: "lint/lint.yml" + - project: "ldc-web/shared-ci" + ref: "main" + file: "security/security.yml" + - project: "ldc-web/shared-ci" + ref: "main" + file: "build/build.yml" + - project: "ldc-web/shared-ci" + ref: "main" + file: "test/test.yml" + - project: "ldc-web/shared-ci" + ref: "main" + file: "deploy/deploy.yml" stages: - - lint - - security - - build - - test - - deploy + - lint + - security + - build + - test + - deploy diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a836b6e --- /dev/null +++ b/Dockerfile @@ -0,0 +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 +USER root +RUN chmod -R 755 /app/srcs/storage +USER www-data \ No newline at end of file diff --git a/manifest.yaml b/manifest.yaml new file mode 100644 index 0000000..4a63ffe --- /dev/null +++ b/manifest.yaml @@ -0,0 +1,169 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: ${CI_PROJECT_PATH_SLUG}-config-map +data: + APP_NAME: "${APP_APP_NAME}" + APP_ENV: "${APP_APP_ENV}" + APP_KEY: "${APP_APP_KEY}" + APP_DEBUG: "${APP_APP_DEBUG}" + APP_URL: "https://${APP_DOMAIN}" + LOG_CHANNEL: "k8s" + DB_HOST: "mariadb-service.common-services" + DB_DATABASE: "${APP_DB_DATABASE}" + DB_USERNAME: "${APP_DB_USERNAME}" + DB_PASSWORD: "${APP_DB_PASSWORD}" + MAIL_HOST: "${APP_MAIL_HOST}" + MAIL_PORT: "${APP_MAIL_PORT}" + MAIL_USERNAME: "${APP_MAIL_USERNAME}" + MAIL_PASSWORD: "${APP_MAIL_PASSWORD}" + MAIL_ENCRYPTION: "${APP_MAIL_ENCRYPTION}" + MAIL_FROM_ADDRESS: "${APP_MAIL_FROM_ADDRESS}" + MAIL_FROM_NAME: "${APP_APP_NAME}" + LDC_WEB_API_KEY: "${APP_LDC_WEB_API_KEY}" + SENTRY_LARAVEL_DSN: "${APP_SENTRY_LARAVEL_DSN}" + GITLAB_URL: "https://${CI_SERVER_HOST}" + GITLAB_TOKEN: "${APP_GITLAB_TOKEN}" + +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: ${CI_PROJECT_PATH_SLUG}-pvc-storage +spec: + storageClassName: "csi-cinder-classic" + accessModes: + - ReadWriteOnce + resources: + requests: + storage: $APP_PVC_SIZE + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ${CI_PROJECT_PATH_SLUG}-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 + 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 + +--- +apiVersion: v1 +kind: Service +metadata: + name: ${CI_PROJECT_PATH_SLUG}-service +spec: + selector: + app: ${CI_PROJECT_PATH_SLUG}-app + ports: + - port: 80 + targetPort: 443 + +--- +apiVersion: traefik.containo.us/v1alpha1 +kind: IngressRoute +metadata: + name: ${CI_PROJECT_PATH_SLUG}-ingress-route +spec: + entryPoints: + - web + - websecure + routes: + - match: Host(`${APP_DOMAIN}`) + kind: Rule + services: + - name: ${CI_PROJECT_PATH_SLUG}-service + port: 80 + tls: + secretName: $APP_DOMAIN + +--- +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: $APP_DOMAIN +spec: + dnsNames: + - $APP_DOMAIN + secretName: $APP_DOMAIN + issuerRef: + name: $APP_CERT_ISSUER + kind: ClusterIssuer + +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: ${CI_PROJECT_PATH_SLUG}-cronjob +spec: + schedule: "* * * * *" + jobTemplate: + spec: + template: + spec: + affinity: + podAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - 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 + imagePullSecrets: + - name: docker-registry-credentials + volumes: + - name: storage + persistentVolumeClaim: + claimName: ${CI_PROJECT_PATH_SLUG}-pvc-storage + securityContext: + runAsUser: 33 + runAsGroup: 33 + fsGroup: 33 + fsGroupChangePolicy: "OnRootMismatch" + restartPolicy: OnFailure