From 66adad013ea0b7e52ab692a3ca1fce5a75d70be1 Mon Sep 17 00:00:00 2001 From: Travis Rivers <trivers@contractor.usgs.gov> Date: Fri, 7 Aug 2020 10:31:11 -0600 Subject: [PATCH 1/8] add mage deploy to gitlab pipeline --- .gitlab-ci.yml | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a584a793..ae31f15d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -75,6 +75,44 @@ variables: variables: PYTHON_VERSION: 3.8 +.deploy: + cache: {} + extends: + - .adjust_image_names + image: ${CODE_REGISTRY}/ghsc/hazdev/cloud-formation/hazdev-build-runner:latest + script: + - git clone ${GENERIC_SWARM_DEPLOY_REPO} generic-deploy + - cp -v + generic-deploy/default.config.sh + generic-deploy/default.funcs.sh + generic-deploy/deploy.sh + scripts/. + - export APP_NAME=${APP_NAME} + - export IMAGE_NAME=${IMAGE_NAME} + - export REGISTRY=${CI_REGISTRY_IMAGE} + - export STACK_NAME=${APP_NAME} + - ./scripts/deploy.sh + stage: deploy + tags: + - deploy + - swarm + +.mage: + services: + web: + variables: + - DATA_HOST=cwbpub.cr.usgs.gov + - DATA_PORT=2060 + - DATA_TYPE=edge + - GEOMAG_VERSION=0.3.1 + - WEBSERVICE=true + ports: + - '8000:8000' + +.staging: + only: + - master@ghsc/geomag/geomag-algorithms + - tags@ghsc/geomag/geomag-algorithms ## -------------------------------------------------- # Test Stage ## -------------------------------------------------- @@ -106,3 +144,12 @@ Build Algorithms Docker Image: - .build_docker_image variables: APP_NAME: geomag-algorithms +## -------------------------------------------------- +# Deploy Stage +## -------------------------------------------------- + +Deploy Mage01: + extends: + - .deploy + - .staging + - .mage -- GitLab From 6101429949d8e1076e8babf340cd9fb05af606d1 Mon Sep 17 00:00:00 2001 From: Travis Rivers <trivers@contractor.usgs.gov> Date: Fri, 7 Aug 2020 10:36:07 -0600 Subject: [PATCH 2/8] update yml --- .gitlab-ci.yml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ae31f15d..c24d98b1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -98,16 +98,14 @@ variables: - swarm .mage: - services: - web: - variables: - - DATA_HOST=cwbpub.cr.usgs.gov - - DATA_PORT=2060 - - DATA_TYPE=edge - - GEOMAG_VERSION=0.3.1 - - WEBSERVICE=true - ports: - - '8000:8000' + variables: + - DATA_HOST=cwbpub.cr.usgs.gov + - DATA_PORT=2060 + - DATA_TYPE=edge + - GEOMAG_VERSION=0.3.1 + - WEBSERVICE=true + ports: + - '8000:8000' .staging: only: -- GitLab From 9af4e8abf6b022a6d53cdce8a7b691bc8f9e6fd8 Mon Sep 17 00:00:00 2001 From: Travis Rivers <trivers@contractor.usgs.gov> Date: Fri, 7 Aug 2020 10:38:52 -0600 Subject: [PATCH 3/8] remove ports --- .gitlab-ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c24d98b1..876b1fef 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -104,8 +104,6 @@ variables: - DATA_TYPE=edge - GEOMAG_VERSION=0.3.1 - WEBSERVICE=true - ports: - - '8000:8000' .staging: only: -- GitLab From db617becbb17b163e0cb6ee04e71ed212be80597 Mon Sep 17 00:00:00 2001 From: Travis Rivers <trivers@contractor.usgs.gov> Date: Fri, 7 Aug 2020 10:40:33 -0600 Subject: [PATCH 4/8] key value pairs for variables, duh --- .gitlab-ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 876b1fef..e2f45018 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -99,11 +99,11 @@ variables: .mage: variables: - - DATA_HOST=cwbpub.cr.usgs.gov - - DATA_PORT=2060 - - DATA_TYPE=edge - - GEOMAG_VERSION=0.3.1 - - WEBSERVICE=true + - DATA_HOST: 'cwbpub.cr.usgs.gov' + - DATA_PORT: '2060' + - DATA_TYPE: 'edge' + - GEOMAG_VERSION: '0.3.1' + - WEBSERVICE: 'true' .staging: only: -- GitLab From 59f73c250be5b303cae26b1180c289c8ec8bf048 Mon Sep 17 00:00:00 2001 From: Travis Rivers <trivers@contractor.usgs.gov> Date: Fri, 7 Aug 2020 10:41:42 -0600 Subject: [PATCH 5/8] syntax --- .gitlab-ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e2f45018..2691d219 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -99,11 +99,11 @@ variables: .mage: variables: - - DATA_HOST: 'cwbpub.cr.usgs.gov' - - DATA_PORT: '2060' - - DATA_TYPE: 'edge' - - GEOMAG_VERSION: '0.3.1' - - WEBSERVICE: 'true' + DATA_HOST: 'cwbpub.cr.usgs.gov' + DATA_PORT: '2060' + DATA_TYPE: 'edge' + GEOMAG_VERSION: '0.3.1' + WEBSERVICE: 'true' .staging: only: -- GitLab 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 6/8] 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 2691d219..de03d6c9 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 00000000..f7af0d0b --- /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 00000000..2cdd66ba --- /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 From ad143dbd768bbae93c8f391d41febc2286564d02 Mon Sep 17 00:00:00 2001 From: Travis Rivers <trivers@contractor.usgs.gov> Date: Fri, 14 Aug 2020 18:46:44 -0600 Subject: [PATCH 7/8] custom func config and pipeline variable updates --- .gitlab-ci.yml | 4 ++++ scripts/custom.funcs.sh | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index de03d6c9..e0b451ea 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -96,6 +96,8 @@ variables: tags: - deploy - swarm + variables: + APP_NAME: geomag-algorithms .mage: variables: @@ -148,3 +150,5 @@ Deploy Mage01: - .deploy - .staging - .mage + variables: + APP_NAME: geomag-algorithms diff --git a/scripts/custom.funcs.sh b/scripts/custom.funcs.sh index 2cdd66ba..c09190d2 100644 --- a/scripts/custom.funcs.sh +++ b/scripts/custom.funcs.sh @@ -11,7 +11,6 @@ preStackDeployHook () { ## writeYmlFile () { local ymlFileName="${APP_NAME}.yml"; - local configName="assets-$(date +%H%M%S)-$$"; cat <<-EO_YML > ${ymlFileName} version: "3.5" @@ -32,14 +31,12 @@ services: order: start-first parallelism: 3 ports: - - 8000: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 From 585fcf0c655c0f549699d1285a2644bccdbb23cc Mon Sep 17 00:00:00 2001 From: Travis Rivers <trivers@contractor.usgs.gov> Date: Mon, 17 Aug 2020 09:49:57 -0600 Subject: [PATCH 8/8] add webservice variable to custom funcs --- scripts/custom.funcs.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/custom.funcs.sh b/scripts/custom.funcs.sh index c09190d2..2a9e7f13 100644 --- a/scripts/custom.funcs.sh +++ b/scripts/custom.funcs.sh @@ -38,5 +38,6 @@ services: - DATA_PORT=${DATA_PORT} - DATA_TYPE=${DATA_TYPE} - SITE_URL=${SITE_URL} + - WEBSERVICE=true EO_YML } -- GitLab