diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a584a7939d9200f9789f3ef5061b75242f6b330e..e0b451ea6da3eb39ca9404202d128d37d2a2943e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -75,6 +75,40 @@ 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 + variables: + APP_NAME: geomag-algorithms + +.mage: + variables: + DATA_HOST: 'cwbpub.cr.usgs.gov' + DATA_PORT: '2060' + DATA_TYPE: 'edge' + +.staging: + only: + - master@ghsc/geomag/geomag-algorithms + - tags@ghsc/geomag/geomag-algorithms ## -------------------------------------------------- # Test Stage ## -------------------------------------------------- @@ -106,3 +140,15 @@ Build Algorithms Docker Image: - .build_docker_image variables: APP_NAME: geomag-algorithms + +## -------------------------------------------------- +# Deploy Stage +## -------------------------------------------------- + +Deploy Mage01: + extends: + - .deploy + - .staging + - .mage + variables: + APP_NAME: geomag-algorithms diff --git a/scripts/custom.config.sh b/scripts/custom.config.sh new file mode 100644 index 0000000000000000000000000000000000000000..f7af0d0ba9c666bbd1c0e808a5d0d3d3598d1f57 --- /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 0000000000000000000000000000000000000000..2a9e7f137c9ec32c8aff18448c4e15e0837af892 --- /dev/null +++ b/scripts/custom.funcs.sh @@ -0,0 +1,43 @@ +# 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"; + + 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 + environment: + - BASE_HREF=${BASE_HREF} + - DATA_HOST=${DATA_HOST} + - DATA_PORT=${DATA_PORT} + - DATA_TYPE=${DATA_TYPE} + - SITE_URL=${SITE_URL} + - WEBSERVICE=true +EO_YML +}