From dff0983571c06ec45de507a459e0f92fd4f5f0c1 Mon Sep 17 00:00:00 2001 From: Nathan Swain Date: Wed, 24 Nov 2021 10:03:34 -0700 Subject: [PATCH] Added Salt State scripts for runtime initialization. --- Dockerfile | 5 ++++ salt/init_apps.sls | 50 ++++++++++++++++++++++++++++++++++++++++ salt/portal_theme.sls | 32 +++++++++++++++++++++++++ salt/tethys_services.sls | 33 ++++++++++++++++++++++++++ salt/top.sls | 8 +++++++ 5 files changed, 128 insertions(+) create mode 100644 salt/init_apps.sls create mode 100644 salt/portal_theme.sls create mode 100644 salt/tethys_services.sls create mode 100644 salt/top.sls diff --git a/Dockerfile b/Dockerfile index c22aa58..027cd5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,6 +50,11 @@ RUN /bin/bash -c "cd ${TETHYS_HOME}/apps/tethysapp-thredds_tutorial && \ . ${CONDA_HOME}/bin/activate tethys && \ tethys install --no-db-sync" +################## +# ADD SALT FILES # +################## +COPY salt/ /srv/salt/ + ######### # PORTS # ######### diff --git a/salt/init_apps.sls b/salt/init_apps.sls new file mode 100644 index 0000000..4719514 --- /dev/null +++ b/salt/init_apps.sls @@ -0,0 +1,50 @@ +{% set CONDA_HOME = salt['environ.get']('CONDA_HOME') %} +{% set TETHYS_HOME = salt['environ.get']('TETHYS_HOME') %} +{% set TETHYS_PERSIST = salt['environ.get']('TETHYS_PERSIST') %} +{% set DAM_INVENTORY_MAX_DAMS = salt['environ.get']('DAM_INVENTORY_MAX_DAMS') %} +{% set EARTH_ENGINE_PRIVATE_KEY_FILE = salt['environ.get']('EARTH_ENGINE_PRIVATE_KEY_FILE') %} +{% set EARTH_ENGINE_SERVICE_ACCOUNT_EMAIL = salt['environ.get']('EARTH_ENGINE_SERVICE_ACCOUNT_EMAIL') %} +{% set THREDDS_SERVICE_NAME = 'tethys_thredds' %} +{% set POSTGIS_SERVICE_NAME = 'tethys_postgis' %} + +Sync_Apps: + cmd.run: + - name: > + . {{ CONDA_HOME }}/bin/activate tethys && + tethys db sync + - shell: /bin/bash + - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/init_apps_setup_complete" ];" + +Set_Custom_Settings: + cmd.run: + - name: > + . {{ CONDA_HOME }}/bin/activate tethys && + tethys app_settings set dam_inventory max_dams {{ DAM_INVENTORY_MAX_DAMS }} && + tethys app_settings set earth_engine service_account_email {{ EARTH_ENGINE_SERVICE_ACCOUNT_EMAIL }} && + tethys app_settings set earth_engine private_key_file {{ EARTH_ENGINE_PRIVATE_KEY_FILE }} + - shell: /bin/bash + - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/init_apps_setup_complete" ];" + +Link_Tethys_Services_to_Apps: + cmd.run: + - name: > + . {{ CONDA_HOME }}/bin/activate tethys && + tethys link persistent:{{ POSTGIS_SERVICE_NAME }} dam_inventory:ps_database:primary_db && + tethys link persistent:{{ POSTGIS_SERVICE_NAME }} postgis_app:ps_database:flooded_addresses && + tethys link spatial:{{ THREDDS_SERVICE_NAME }} thredds_tutorial:ds_spatial:thredds_service + - shell: /bin/bash + - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/init_apps_setup_complete" ];" + +Sync_App_Persistent_Stores: + cmd.run: + - name: > + . {{ CONDA_HOME }}/bin/activate tethys && + tethys syncstores all + - shell: /bin/bash + - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/init_apps_setup_complete" ];" + +Flag_Init_Apps_Setup_Complete: + cmd.run: + - name: touch {{ TETHYS_PERSIST }}/init_apps_setup_complete + - shell: /bin/bash + - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/init_apps_setup_complete" ];" diff --git a/salt/portal_theme.sls b/salt/portal_theme.sls new file mode 100644 index 0000000..9c5573a --- /dev/null +++ b/salt/portal_theme.sls @@ -0,0 +1,32 @@ +{% set CONDA_HOME = salt['environ.get']('CONDA_HOME') %} +{% set TETHYS_PERSIST = salt['environ.get']('TETHYS_PERSIST') %} +{% set STATIC_ROOT = salt['environ.get']('STATIC_ROOT') %} + +Move_Custom_Theme_Files_to_Static_Root: + cmd.run: + - name: mv /tmp/custom_theme {{ STATIC_ROOT }} + - shell: /bin/bash + - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/custom_theme_setup_complete" ];" + +Apply_Custom_Theme: + cmd.run: + - name: > + . {{ CONDA_HOME }}/bin/activate tethys && + tethys site + --title "My Custom Portal" + --tab-title "My Custom Portal" + --library-title "Tools" + --primary-color "#01200F" + --secondary-color "#358600" + --background-color "#ffffff" + --logo "/custom_theme/images/leaf-logo.png" + --favicon "/custom_theme/images/favicon.ico" + --copyright "Copyright © 2021 My Organization" + - shell: /bin/bash + - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/custom_theme_setup_complete" ];" + +Flag_Custom_Theme_Setup_Complete: + cmd.run: + - name: touch {{ TETHYS_PERSIST }}/custom_theme_setup_complete + - shell: /bin/bash + - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/custom_theme_setup_complete" ];" diff --git a/salt/tethys_services.sls b/salt/tethys_services.sls new file mode 100644 index 0000000..d9ee5d4 --- /dev/null +++ b/salt/tethys_services.sls @@ -0,0 +1,33 @@ +{% set CONDA_HOME = salt['environ.get']('CONDA_HOME') %} +{% set TETHYS_PERSIST = salt['environ.get']('TETHYS_PERSIST') %} +{% set TETHYS_DB_HOST = salt['environ.get']('TETHYS_DB_HOST') %} +{% set TETHYS_DB_PORT = salt['environ.get']('TETHYS_DB_PORT') %} +{% set TETHYS_DB_SUPERUSER = salt['environ.get']('TETHYS_DB_SUPERUSER') %} +{% set TETHYS_DB_SUPERUSER_PASS = salt['environ.get']('TETHYS_DB_SUPERUSER_PASS') %} +{% set THREDDS_TUTORIAL_TDS_USERNAME = salt['environ.get']('THREDDS_TUTORIAL_TDS_USERNAME') %} +{% set THREDDS_TUTORIAL_TDS_PASSWORD = salt['environ.get']('THREDDS_TUTORIAL_TDS_PASSWORD') %} +{% set THREDDS_TUTORIAL_TDS_PROTOCOL = salt['environ.get']('THREDDS_TUTORIAL_TDS_PROTOCOL') %} +{% set THREDDS_TUTORIAL_TDS_HOST = salt['environ.get']('THREDDS_TUTORIAL_TDS_HOST') %} +{% set THREDDS_TUTORIAL_TDS_PORT = salt['environ.get']('THREDDS_TUTORIAL_TDS_PORT') %} +{% set THREDDS_SERVICE_NAME = 'tethys_thredds' %} +{% set POSTGIS_SERVICE_NAME = 'tethys_postgis' %} +{% set THREDDS_SERVICE_URL = THREDDS_TUTORIAL_TDS_USERNAME + ':' + THREDDS_TUTORIAL_TDS_PASSWORD + '@' + THREDDS_TUTORIAL_TDS_PROTOCOL +'://' + THREDDS_TUTORIAL_TDS_HOST + ':' + THREDDS_TUTORIAL_TDS_PORT %} +{% set POSTGIS_SERVICE_URL = TETHYS_DB_SUPERUSER + ':' + TETHYS_DB_SUPERUSER_PASS + '@' + TETHYS_DB_HOST + ':' + TETHYS_DB_PORT %} + +Create_PostGIS_Database_Service: + cmd.run: + - name: ". {{ CONDA_HOME }}/bin/activate tethys && tethys services create persistent -n {{ POSTGIS_SERVICE_NAME }} -c {{ POSTGIS_SERVICE_URL }}" + - shell: /bin/bash + - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/tethys_services_complete" ];" + +Create_THREDDS_Spatial_Dataset_Service: + cmd.run: + - name: ". {{ CONDA_HOME }}/bin/activate tethys && tethys services create spatial -t THREDDS -n {{ THREDDS_SERVICE_NAME }} -c {{ THREDDS_SERVICE_URL }}" + - shell: /bin/bash + - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/tethys_services_complete" ];" + +Flag_Tethys_Services_Setup_Complete: + cmd.run: + - name: touch {{ TETHYS_PERSIST }}/tethys_services_complete + - shell: /bin/bash + - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/tethys_services_complete" ];" diff --git a/salt/top.sls b/salt/top.sls new file mode 100644 index 0000000..3d6e779 --- /dev/null +++ b/salt/top.sls @@ -0,0 +1,8 @@ +base: + '*': + - pre_tethys + - tethyscore + - tethys_services + - init_apps + - portal_theme + - post_app