flood-project is a tool.
The main functions are:
- existing
- Ensure the following requirements are met and the dependencies are set up
- PostgreSQL (>=11) database with the PostGIS & PostGIS Raster extension (>=3.1) installed
- PostGIS needed installed locally so you have access to
raster2pgsql
- PostGIS needed installed locally so you have access to
- Python 3.8
- GDAL >= 2.2.3
- unzip
- bcdata Python Library
- PostgreSQL (>=11) database with the PostGIS & PostGIS Raster extension (>=3.1) installed
sudo apt install make
sudo apt install unzip
sudo apt-get install gdal-bin
sudo apt install postgresql-client-12
sudo apt install postgis
sudo apt-get install p7zip-fullpip install bcdata- Ensure you have
PGenvironment variables set to point at your database, for example:
export PGHOST=localhost
export PGPORT=5432
export PGDATABASE=pineapple
export PGUSER=username
export PGPASSWORD=password
export PGTILESERVER_PASSWORD=password- Download the repo and run the setup bash file
git clone git@github.com:FoundrySpatial/flood-project.git
cd flood-project
./setup.sh- Choose a data setup bash file depending on if full data is desired or not
./setup_full_data.sh./setup_seed_data.shSee the terraform-db directory for details.
The repository creates an azure postgresql database on a flexible server, as well as a container instance to initialize the database. The container instance requires credentials to access our azure container registry (acr) and assumes a docker image exists for it (the default variable values point to an existing image to use). To recreate the docker image, run docker build -t <name> . from the root of this repository. To push the new image, login to azure acr with az acr login --name <repository-name> and push the new image with docker push <image-name>.
To create the database, ensure you have the az cli and terraform cli installed. Then:
- Authenticate to azure with
az login - Create a file in the /terraform directory named
secrets.tfvars, and add the following values:
acr_username=
acr_password=
psql_db=
psql_port=
psql_user=
psql_password=
Where acr_username and acr_password are credentials to access the azure container registry. If there is not already a service principal created,
see here for creating a new one. psql_db will be the name of the database, psql_port the port it exposes, and the user and password will be the admin credentials to access the database.
- If you haven't initialized terraform in this repository before, run
terraform init - Create the resources with
terraform apply -var-file="secrets.tfvars"
This will provision an Azure Database for Postgres with network rules set to allow communication from internal azure resources . See here for information on the inter-service network rules.
Known Issue: When running terraform destroy, the azure extensions cause an error when being deleted. Just run the command again if it throws an error.
If you need to connect directly with psql, you will have to change the firewall rules to get access.
- In the azure portal, navigate to the psql server and select
Networkingfrom the lefthand menu. Under the firewall rules, click theAdd current client ip addressto allow your ip to connect. - From the same page, go to
Connection stringson the left side menu and copy the psql string, updating the dbname and password. - Run that command in your terminal to connect
- Once finished, go back to connection security and remove your IP address from the firewall rules.