From f2185869aec96362a2158835b2bbb526abe51a57 Mon Sep 17 00:00:00 2001
From: Dominik Hebeler <dominik@suma-ev.de>
Date: Wed, 11 May 2022 17:02:47 +0200
Subject: [PATCH] added deployment for development/production

---
 .gitlab-ci.yml           | 13 ++++++++++++
 .gitlab/ci/deploy.yml    | 34 ++++++++++++++++++++++++++++++-
 .gitlab/development.yaml | 20 ++++++++++++++++++
 .gitlab/production.yaml  | 44 ++++++++++++++++++++++++++++++++++++++++
 .gitlab/review.yaml      |  7 +++++++
 5 files changed, 117 insertions(+), 1 deletion(-)
 create mode 100644 .gitlab/development.yaml
 create mode 100644 .gitlab/production.yaml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index dd10f4e12..fae956719 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -13,6 +13,19 @@ workflow:
       DOCKER_FPM_IMAGE_TAG: $CI_COMMIT_REF_SLUG-$CI_COMMIT_SHA
       DOCKER_NGINX_IMAGE_TAG: $CI_COMMIT_REF_SLUG-$CI_COMMIT_SHA
       APP_ENV: development
+      APP_URL: "https://${CI_COMMIT_REF_SLUG}.review.metager.de"
+  - if: $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "development"
+      variables:
+        DOCKER_COMPOSER_IMAGE_TAG: $CI_COMMIT_BRANCH-composer-$CI_COMMIT_SHA
+        DOCKER_FPM_IMAGE_TAG: $CI_COMMIT_BRANCH-$CI_COMMIT_SHA
+        DOCKER_NGINX_IMAGE_TAG: $CI_COMMIT_BRANCH-$CI_COMMIT_SHA
+  - if: $CI_COMMIT_BRANCH == "master"
+      variables:
+        APP_URL: https://metager.de
+  - if: $CI_COMMIT_BRANCH == "development"
+      variables:
+        APP_URL: https://metager3.de
+
 stages:
   - build_composer
   - build_dependencies
diff --git a/.gitlab/ci/deploy.yml b/.gitlab/ci/deploy.yml
index d595c210a..da60e0b07 100644
--- a/.gitlab/ci/deploy.yml
+++ b/.gitlab/ci/deploy.yml
@@ -9,6 +9,39 @@
     - .gitlab/deployment_scripts/update_secret.sh
     - .gitlab/deployment_scripts/update_deployment.sh
 
+deploy_development:
+  extends:
+    - .deploy
+  environment:
+    name: development
+    url: https://metager3.de
+    action: start
+  variables:
+    variables:
+    DEPLOYMENT_URL: "metager3.de"
+    DEPLOYMENT_HELM_VALUES: .gitlab/development.yaml
+    DEPLOYMENT_CHART_NAME: $CI_COMMIT_BRANCH
+  rules:
+    - if: '$CI_COMMIT_BRANCH != "development"'
+      when: never
+
+  deploy_production:
+  extends:
+    - .deploy
+  environment:
+    name: production
+    url: https://metager.de
+    action: start
+  variables:
+    variables:
+    DEPLOYMENT_URL: "metager.de"
+    DEPLOYMENT_HELM_VALUES: .gitlab/production.yaml
+    DEPLOYMENT_CHART_NAME: $CI_COMMIT_BRANCH
+  rules:
+    - if: '$CI_COMMIT_BRANCH != "development"'
+      when: never
+
+
 deploy_review:
   extends:
     - .deploy
@@ -22,7 +55,6 @@ deploy_review:
     DEPLOYMENT_URL: "${CI_COMMIT_REF_SLUG}.review.metager.de"
     DEPLOYMENT_HELM_VALUES: .gitlab/review.yaml
     DEPLOYMENT_CHART_NAME: review-${CI_COMMIT_REF_SLUG}
-    APP_URL: "https://${CI_COMMIT_REF_SLUG}.review.metager.de"
   rules:
     - if: '$CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "development"'
       when: never
diff --git a/.gitlab/development.yaml b/.gitlab/development.yaml
new file mode 100644
index 000000000..efd78eab5
--- /dev/null
+++ b/.gitlab/development.yaml
@@ -0,0 +1,20 @@
+ingress:
+  annotations:
+    kubernetes.io/tls-acme: "true"
+    cert-manager.io/cluster-issuer: letsencrypt-prod
+  hosts:
+    - host: metager3.de
+      paths:
+        - path: /
+          pathType: ImplementationSpecific
+        - path: /wsb
+            pathType: Prefix
+            backend:
+              service:
+                name: wsb
+                port:
+                  number: 80
+  tls:
+    - hosts:
+        - metager3.de
+      secretName: metager-tls
\ No newline at end of file
diff --git a/.gitlab/production.yaml b/.gitlab/production.yaml
new file mode 100644
index 000000000..476e79c76
--- /dev/null
+++ b/.gitlab/production.yaml
@@ -0,0 +1,44 @@
+ingress:
+  annotations:
+    kubernetes.io/tls-acme: "true"
+    cert-manager.io/cluster-issuer: letsencrypt-prod
+  hosts:
+    - host: metager.de
+      paths:
+        - path: /
+          pathType: ImplementationSpecific
+        - path: /wsb
+            pathType: Prefix
+            backend:
+              service:
+                name: wsb
+                port:
+                  number: 80
+    - host: metager.org
+      paths:
+        - path: /
+          pathType: ImplementationSpecific
+        - path: /wsb
+            pathType: Prefix
+            backend:
+              service:
+                name: wsb
+                port:
+                  number: 80
+    - host: metager.es
+      paths:
+        - path: /
+          pathType: ImplementationSpecific
+        - path: /wsb
+            pathType: Prefix
+            backend:
+              service:
+                name: wsb
+                port:
+                  number: 80
+  tls:
+    - hosts:
+        - metager.de
+        - metager.org
+        - metager.es
+      secretName: metager-tls
\ No newline at end of file
diff --git a/.gitlab/review.yaml b/.gitlab/review.yaml
index 870ff0015..de4a768f5 100644
--- a/.gitlab/review.yaml
+++ b/.gitlab/review.yaml
@@ -6,6 +6,13 @@ ingress:
     - paths:
         - path: /
           pathType: ImplementationSpecific
+        - path: /wsb
+            pathType: Prefix
+            backend:
+              service:
+                name: wsb
+                port:
+                  number: 80
   tls:
     - hosts:
         - "*.review.metager.de"
-- 
GitLab