Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbcunc committed Nov 1, 2022
0 parents commit f17f0b8
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- mode: gitignore; -*-
*~
\#*\#
.\#*
2 changes: 2 additions & 0 deletions COPYRIGHT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Copyright © 2022, Consortium of Universities for the Advancement of Hydrologic Science, Inc. (CUAHSI)
All Rights Reserved
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
24 changes: 24 additions & 0 deletions loaddb.sh
Original file line number Diff line number Diff line change
@@ -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)"

0 comments on commit f17f0b8

Please sign in to comment.