Skip to content

Commit

Permalink
Added Salt State scripts for runtime initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
swainn committed Nov 24, 2021
1 parent 5958dd9 commit dff0983
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
#########
Expand Down
50 changes: 50 additions & 0 deletions salt/init_apps.sls
Original file line number Diff line number Diff line change
@@ -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" ];"
32 changes: 32 additions & 0 deletions salt/portal_theme.sls
Original file line number Diff line number Diff line change
@@ -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" ];"
33 changes: 33 additions & 0 deletions salt/tethys_services.sls
Original file line number Diff line number Diff line change
@@ -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" ];"
8 changes: 8 additions & 0 deletions salt/top.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
base:
'*':
- pre_tethys
- tethyscore
- tethys_services
- init_apps
- portal_theme
- post_app

0 comments on commit dff0983

Please sign in to comment.