From f17f0b8163149f8abca0e76bd89588fcf37c701a Mon Sep 17 00:00:00 2001 From: Chris Calloway Date: Tue, 1 Nov 2022 17:07:32 -0400 Subject: [PATCH] Initial commit. --- .gitignore | 4 ++++ COPYRIGHT | 2 ++ LICENSE | 29 +++++++++++++++++++++++++++++ README.md | 10 ++++++++++ docker-compose.yml | 17 +++++++++++++++++ loaddb.sh | 24 ++++++++++++++++++++++++ 6 files changed, 86 insertions(+) create mode 100644 .gitignore create mode 100644 COPYRIGHT create mode 100644 LICENSE create mode 100644 README.md create mode 100644 docker-compose.yml create mode 100755 loaddb.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..16064f5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# -*- mode: gitignore; -*- +*~ +\#*\# +.\#* diff --git a/COPYRIGHT b/COPYRIGHT new file mode 100644 index 0000000..26d43c8 --- /dev/null +++ b/COPYRIGHT @@ -0,0 +1,2 @@ +Copyright © 2022, Consortium of Universities for the Advancement of Hydrologic Science, Inc. (CUAHSI) +All Rights Reserved diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c13b67b --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2022, Critical Zone Collaborative Network Hub (CZNet Hub) +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0ce744c --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# hs_postgis +A datbase for Hydroshare based on official images. + +1. Open port 5432 on the host's firewall to the subnets making connections. +1. `docker-compose up -d` +1. Place a SQL dump to load into the database in /var/scratch/pg.deploy.sql on the host. +1. `./loaddb.sh` +1. The default postgres user password is configured in two places in the Hydroshare codebase: + 1. hydroshare/hydroshare/local_settings.py + 1. hydroshare/config/hydroshare-config.yaml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..dc5ec5f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: "3" + +services: + postgis: + image: postgis/postgis:15-3.3 + environment: + POSTGRES_PASSWORD: 'postgres' + container_name: postgis + restart: unless-stopped + volumes: + - "postgis_data_vol:/var/lib/postgresql/data" + - "/var/scratch:/var/scratch" + ports: + - "5432:5432" + +volumes: + postgis_data_vol: diff --git a/loaddb.sh b/loaddb.sh new file mode 100755 index 0000000..c7e1b30 --- /dev/null +++ b/loaddb.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +echo "Start: $(date)" +echo "Revoking connections..." +docker exec postgis psql -U postgres -d template1 -w -c 'REVOKE CONNECT ON DATABASE postgres FROM public;' +echo "Terminating backends..." +docker exec postgis psql -U postgres -d template1 -w -c "SELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'postgres' AND pid <> pg_backend_pid();" +echo "Dropping postgis extension..." +docker exec postgis psql -U postgres -d template1 -w -c 'DROP EXTENSION postgis;' +echo "Dropping hstore extension..." +docker exec postgis psql -U postgres -d template1 -w -c 'DROP EXTENSION hstore;' +echo "Dropping postgres database..." +docker exec postgis dropdb -U postgres postgres +echo "Creating postgis extension..." +docker exec postgis psql -U postgres -d template1 -w -c 'CREATE EXTENSION postgis;' +echo "Creating hstore extennsion..." +docker exec postgis psql -U postgres -d template1 -w -c 'CREATE EXTENSION hstore;' +echo "Creating postgres database..." +docker exec postgis createdb -U postgres postgres --encoding UNICODE --template=template1 +echo "Setting message level..." +docker exec postgis psql -U postgres -d postgres -w -c 'SET client_min_messages TO WARNING;' +echo "Loading database. It is normal to see an error that the postgres role already exists..." +docker exec postgis psql -U postgres -d postgres -q -f /var/scratch/pg.deploy.sql +echo "End: $(date)"