From cd29ce3efa9b40d26dce879457b745ac1225cbe6 Mon Sep 17 00:00:00 2001
From: Dominik Hebeler <dominik@suma-ev.de>
Date: Wed, 11 May 2022 14:33:46 +0200
Subject: [PATCH] added integrationtest

---
 .gitlab-ci.yml                                |  4 +++-
 .gitlab/ci/build_docker_images.yml            | 11 +---------
 .gitlab/ci/deploy.yml                         |  3 +++
 .gitlab/ci/integrationtest.yml                | 22 +++++++++++++++++++
 .../deployment_scripts/update_deployment.sh   |  1 +
 chart/templates/deployment.yaml               |  2 ++
 metager/config/browserstack.php               |  2 +-
 7 files changed, 33 insertions(+), 12 deletions(-)
 create mode 100644 .gitlab/ci/integrationtest.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b4173d24d..9c6ea258d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -17,10 +17,12 @@ stages:
   - build_dependencies
   - build_docker_images
   - deploy
+  - integrationtest
   - stop_review
 
 include:
   - local: /.gitlab/ci/build_composer.yml
   - local: /.gitlab/ci/build_dependencies.yml
   - local: /.gitlab/ci/build_docker_images.yml
-  - local: /.gitlab/ci/deploy.yml
\ No newline at end of file
+  - local: /.gitlab/ci/deploy.yml
+  - local: /.gitlab/ci/integrationtest.yml
\ No newline at end of file
diff --git a/.gitlab/ci/build_docker_images.yml b/.gitlab/ci/build_docker_images.yml
index 329ff3ff0..3ad35f90d 100644
--- a/.gitlab/ci/build_docker_images.yml
+++ b/.gitlab/ci/build_docker_images.yml
@@ -1,9 +1,6 @@
-.fpm:
+fpm:
   stage: build_docker_images
   image: $BUILD_DOCKER_IMAGE
-  variables:
-    BRANCH_NAME: $CI_COMMIT_REF_NAME
-    COMMIT_NAME: $CI_COMMIT_REF_SLUG
   before_script:
     - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
     # We need the vendor files in our final image. Make sure to not ignore the folder
@@ -17,12 +14,6 @@
   after_script:
     - docker logout $CI_REGISTRY
 
-fpm_review:
-  extends:
-    - .fpm
-  variables:
-    APP_URL: "https://${CI_COMMIT_REF_SLUG}.review.metager.de"
-
 nginx:
   stage: build_docker_images
   image: $BUILD_DOCKER_IMAGE
diff --git a/.gitlab/ci/deploy.yml b/.gitlab/ci/deploy.yml
index 327f5205c..d595c210a 100644
--- a/.gitlab/ci/deploy.yml
+++ b/.gitlab/ci/deploy.yml
@@ -3,6 +3,8 @@
   image: $DEPLOY_KUBERNETES_IMAGE
   variables:
     DEPLOYMENT_CHART_NAME: ${CI_COMMIT_REF_SLUG}
+    BRANCH_NAME: $CI_COMMIT_REF_NAME
+    COMMIT_NAME: $CI_COMMIT_REF_SLUG
   script:
     - .gitlab/deployment_scripts/update_secret.sh
     - .gitlab/deployment_scripts/update_deployment.sh
@@ -20,6 +22,7 @@ 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/ci/integrationtest.yml b/.gitlab/ci/integrationtest.yml
new file mode 100644
index 000000000..62db8b26a
--- /dev/null
+++ b/.gitlab/ci/integrationtest.yml
@@ -0,0 +1,22 @@
+.integrationtest:
+  stage: integrationtest
+  image: 
+    name: ${CI_REGISTRY_IMAGE}/$DOCKER_FPM_IMAGE_NAME:$DOCKER_COMPOSER_IMAGE_TAG
+    entrypoint: ["/bin/bash"]
+  variables:
+    BRANCH_NAME: $CI_COMMIT_REF_NAME
+    COMMIT_NAME: $CI_COMMIT_REF_SLUG
+  script:
+    # Install Dev Dependencies
+    - cp $ENV_PRODUCTION /metager/metager_app.env
+    - php artisan optimize
+    - composer install
+    - php artisan test --parallel --processes=5
+  except:
+    refs: 
+      - master
+
+integrationtest_review:
+  extends: .integrationtest
+  variables:
+    APP_URL: "https://${CI_COMMIT_REF_SLUG}.review.metager.de"
\ No newline at end of file
diff --git a/.gitlab/deployment_scripts/update_deployment.sh b/.gitlab/deployment_scripts/update_deployment.sh
index 81c5120ac..901529663 100755
--- a/.gitlab/deployment_scripts/update_deployment.sh
+++ b/.gitlab/deployment_scripts/update_deployment.sh
@@ -7,4 +7,5 @@ helm -n $KUBE_NAMESPACE upgrade --install \
     --set ingress.hosts[0].host=$DEPLOYMENT_URL \
     --set image.fpm.tag=$DOCKER_FPM_IMAGE_TAG \
     --set image.nginx.tag=$DOCKER_NGINX_IMAGE_TAG \
+    --set app_url=$APP_URL
     --wait
\ No newline at end of file
diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml
index 0bd02d54e..d29364112 100644
--- a/chart/templates/deployment.yaml
+++ b/chart/templates/deployment.yaml
@@ -43,6 +43,8 @@ spec:
           env:
           - name: APP_ENV
             value: {{ .Values.environment }}
+          - name: APP_URL
+            value: {{ .Values.app_url }}
           volumeMounts:
           - name: secrets
             mountPath: /metager/metager_app/.env
diff --git a/metager/config/browserstack.php b/metager/config/browserstack.php
index 45847b791..9b38f1aec 100644
--- a/metager/config/browserstack.php
+++ b/metager/config/browserstack.php
@@ -56,7 +56,7 @@ return [
 
             'console' => env('BROWSERSTACK_CONSOLE', 'verbose'),
 
-            'local' => env('BROWSERSTACK_LOCAL_TUNNEL', true),
+            'local' => env('BROWSERSTACK_LOCAL_TUNNEL', false),
 
             'timezone' => env('BROWSERSTACK_TIMEZONE', config('app.timezone')),
             "timezone" => "Europe/Berlin",
-- 
GitLab