From 86eb1e59c985ed74d6332893a04ffee1ab1f8a38 Mon Sep 17 00:00:00 2001
From: Frank Sauerburger <frank@sauerburger.com>
Date: Tue, 26 Mar 2019 14:26:09 +0100
Subject: [PATCH] Add deployment jobs

---
 .gitlab-ci.yml | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 .gitlab-ci.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..d7a7b56
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,73 @@
+variables:
+  LOCAL_DIR: public
+
+stages: 
+ - build
+ - test_deployment
+ - production_deployment
+
+.sftp: &sftp_template
+  image: ${CI_REGISTRY_IMAGE}/ubuntu_sftp
+  tags:
+    - wasenweiler.sit-servers.net
+  script:
+    - mkdir -p ~/.ssh
+    - echo "${SFTP_KEY}" > ~/.ssh/id_rsa
+    - echo "${SFTP_HOSTCERT}" > ~/.ssh/known_hosts
+    - chmod 600 ~/.ssh/*
+    - mv ${LOCAL_DIR} ${REMOTE_DIR}
+    - sftp ${SFTP_USERNAME}@${SFTP_HOST} <<< "put -r ${REMOTE_DIR}"
+
+
+brunch_build:
+  stage: build
+  image: node
+  before_script:
+    - npm i -g brunch
+  script:
+    - brunch b --production
+  artifacts:
+    paths:
+      - public/*
+    expire_in: 3 days
+
+test_deploy: 
+  stage: test_deployment
+  dependencies:
+    - brunch_build
+  variables:
+    SFTP_USERNAME: ${TEST_USERNAME}
+    SFTP_KEY: ${TEST_KEY}
+    SFTP_HOST: ${TEST_HOST}
+    SFTP_HOSTCERT: ${TEST_HOSTCERT}
+    REMOTE_DIR: ${TEST_DIR}
+    GIT_STRATEGY: none
+
+  environment:
+    name: Preview
+    url: https://longroute.preview.sauerburger.com/
+
+  <<: *sftp_template
+
+production_deploy: 
+  stage: production_deployment
+  dependencies:
+    - brunch_build
+  variables:
+    SFTP_USERNAME: ${PRODUCTION_USERNAME}
+    SFTP_KEY: ${PRODUCTION_KEY}
+    SFTP_HOST: ${PRODUCTION_HOST}
+    SFTP_HOSTCERT: ${PRODUCTION_HOSTCERT}
+    REMOTE_DIR: ${PRODUCTION_DIR}
+    GIT_STRATEGY: none
+
+  only:
+    - master
+  when: manual
+
+  environment:
+    name: Production
+    url: https://longroute.sauerburger.com/
+
+  <<: *sftp_template
+
-- 
GitLab