From e82166b76886efe2cc8fdb08526e0d69e07ef321 Mon Sep 17 00:00:00 2001
From: Travis Rivers <trivers@contractor.usgs.gov>
Date: Fri, 7 Aug 2020 16:30:26 -0600
Subject: [PATCH] add scripts

---
 .gitlab-ci.yml           |  3 +--
 scripts/custom.config.sh | 10 +++++++++
 scripts/custom.funcs.sh  | 45 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+), 2 deletions(-)
 create mode 100644 scripts/custom.config.sh
 create mode 100644 scripts/custom.funcs.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 2691d219e..de03d6c93 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -102,8 +102,6 @@ variables:
     DATA_HOST: 'cwbpub.cr.usgs.gov'
     DATA_PORT: '2060'
     DATA_TYPE: 'edge'
-    GEOMAG_VERSION: '0.3.1'
-    WEBSERVICE: 'true'
 
 .staging:
   only:
@@ -140,6 +138,7 @@ Build Algorithms Docker Image:
     - .build_docker_image
   variables:
     APP_NAME: geomag-algorithms
+
 ## --------------------------------------------------
 # Deploy Stage
 ## --------------------------------------------------
diff --git a/scripts/custom.config.sh b/scripts/custom.config.sh
new file mode 100644
index 000000000..f7af0d0ba
--- /dev/null
+++ b/scripts/custom.config.sh
@@ -0,0 +1,10 @@
+
+export SITE_URL="${SITE_URL_PREFIX}geomag${SITE_URL_SUFFIX}";
+export SERVICE_MAP=(
+  "/${BASE_HREF}":'web'
+);
+# Algorithms Environment Variables
+export DATA_HOST=${DATA_HOST:-cwbpub.cr.usgs.gov}
+export DATA_PORT=${DATA_PORT:-2060}
+export DATA_TYPE=${DATA_TYPE:-edge}
+
diff --git a/scripts/custom.funcs.sh b/scripts/custom.funcs.sh
new file mode 100644
index 000000000..2cdd66ba7
--- /dev/null
+++ b/scripts/custom.funcs.sh
@@ -0,0 +1,45 @@
+# This file contains any custom functions / hooks for the geomag-algorithms
+# deployment process.
+
+preStackDeployHook () {
+  writeYmlFile;
+}
+
+##
+# Write a customized YML file for deploying the stack. Necessary because
+# by default, YML files do not allow variables for defining configs.
+##
+writeYmlFile () {
+  local ymlFileName="${APP_NAME}.yml";
+  local configName="assets-$(date +%H%M%S)-$$";
+
+  cat <<-EO_YML > ${ymlFileName}
+version: "3.5"
+services:
+  # Do not change the name of the "web" service without also updating the
+  # custom.funcs.sh and the custom.config.sh as well. Probably just do not
+  # ever do this...
+  web:
+    image: ${REGISTRY}/${IMAGE_NAME}
+    deploy:
+      restart_policy:
+        condition: any
+        delay: 5s
+        max_attempts: 3
+        window: 120s
+      replicas: 3
+      update_config:
+        order: start-first
+        parallelism: 3
+    ports:
+      - 8000:8000
+    environment:
+      - BASE_HREF=${BASE_HREF}
+      - DATA_HOST=${DATA_HOST}
+      - DATA_PORT=${DATA_PORT}
+      - DATA_TYPE=${DATA_TYPE}
+      - SITE_URL=${SITE_URL}
+    configs:
+      - source: ${configName}
+EO_YML
+}
-- 
GitLab