From 6a92bd87cf722e38d6cb185b83dd366267a0649f Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Sat, 23 Jan 2021 11:03:21 +0100
Subject: [PATCH] gitlab-ci-cd/drupal#2 Add new task to also get the
 production-ready build

---
 test-and-deploy.yml | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/test-and-deploy.yml b/test-and-deploy.yml
index 29e800c..c4c4843 100644
--- a/test-and-deploy.yml
+++ b/test-and-deploy.yml
@@ -1,5 +1,6 @@
 stages:
   - validation
+  - buildprod
   - build
   - prepare
   - test
@@ -28,6 +29,15 @@ stages:
     - .env
     - docker-compose.yml
 
+.artifact_paths_prod: &artifact_paths_prod
+  paths:
+    - config/
+    - drush/
+    - vendor/
+    - web/
+    - .ahoy.yml
+    - .env
+
 .artifact_paths: &artifact_paths
   paths:
     - .docker-init/
@@ -87,6 +97,41 @@ stages:
     reports:
       dotenv: validation.env
 
+.build-prod:
+  stage: buildprod
+  tags:
+    - default
+  cache:
+    <<: *cache_default
+    policy: pull-push
+  script: |
+    if [[ -n $SSH_PRIVATE_KEY ]]; then
+      eval $(ssh-agent -s)
+      echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
+      mkdir -p ~/.ssh
+      chmod 700 ~/.ssh
+      ssh-keyscan gitlab.lakedrops.com >> ~/.ssh/known_hosts
+      chmod 644 ~/.ssh/known_hosts
+      ssh git@gitlab.lakedrops.com
+    fi
+    if [[ -n $DOWNGRADE_COMPOSER ]]; then
+      composer self-update --$DOWNGRADE_COMPOSER;
+    fi
+    if [[ -n $GITLAB_ACCESS_TOKEN ]]; then
+      composer config -g gitlab-token.gitlab.lakedrops.com $GITLAB_ACCESS_TOKEN;
+    fi
+    composer install --no-interaction --no-progress --no-dev
+  artifacts:
+    name: build-prod
+    when: always
+    <<: *artifact_paths_prod
+  except:
+    refs:
+      - tags
+    variables:
+      - $CI_COMMIT_MESSAGE =~ /^Merge tag /i
+      - $CAE
+
 .build:
   stage: build
   tags:
-- 
GitLab