From 5f3dd8571e3f8122c3fabe2bce36728e1340ad38 Mon Sep 17 00:00:00 2001 From: Jin IGARASHI Date: Sun, 20 Sep 2020 14:39:36 +0900 Subject: [PATCH] added docker --- .gitignore | 3 ++- Dockerfile | 8 ++++++++ README.md | 25 +++++++++++++++++++++++++ docker-compose.yml | 15 +++++++++++++++ entrypoint.sh | 10 ++++++++++ epanet/tasks.py | 2 +- postgis2epanet.py | 3 +++ 7 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 entrypoint.sh diff --git a/.gitignore b/.gitignore index d87ce1b..c6e737e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /venv /__pycache__ /epanet/__pycache__ -/util/__pycache__ \ No newline at end of file +/util/__pycache__ +/data \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d55e6e6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.7 +RUN mkdir -p /tmp/src +COPY . /tmp/src +WORKDIR /tmp/src +RUN pip install -r ./requirements.txt + +RUN chmod a+x /tmp/src/entrypoint.sh +ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index bdafb7b..39f0b0d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # PostGIS2EPANET +![GitHub](https://img.shields.io/github/license/wasac/postgis2epanet) +![Docker Cloud Automated build](https://img.shields.io/docker/cloud/automated/wasac/postgis2epanet) +![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/wasac/postgis2epanet) ## postgis2epanet.py @@ -50,6 +53,28 @@ If you want to update elevation from DEM file, use ````-e```` parameter to updat python postgis2epanet.py -e ```` +## Using Docker +Firstly, please configure `docker-compose.yml`. +```yaml + - db_user=postgres + - db_password={your password} + - db_host=host.docker.internal + - db_port=5432 + - database=rwss_assets + # If you want to specify districts to be exported, please put here like "51,52,53" + - districts= +``` + +Just execute the below command. +``` +docker-compose up +``` + +If you changed any source code, please do the below. +``` +docker-compose up --build +``` + *** ## Result of the Script: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f543af3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: '2' +services: + python: + image: wasac/postgis2epanet:v2.0.0 + # build: . + environment: + - db_user=postgres + - db_password=wasacgis + - db_host=host.docker.internal + - db_port=5432 + - database=rwss_assets + # If you want to specify districts to be exported, please put here like "51,52,53" + - districts= + volumes: + - ./data:/tmp/src/data diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..0adf243 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +cd /tmp/src + +target="${districts}" +if [ -n "$target" ]; then + python postgis2epanet.py -d $database -H $db_host -p $db_port -u $db_user -w $db_password -l $target +else + python postgis2epanet.py -d $database -H $db_host -p $db_port -u $db_user -w $db_password +fi diff --git a/epanet/tasks.py b/epanet/tasks.py index d77e5f4..60d7981 100644 --- a/epanet/tasks.py +++ b/epanet/tasks.py @@ -19,7 +19,7 @@ def __init__(self, args): self.db = Database(args) districts_obj = Districts(args.dist_id) self.districts = districts_obj.get_wss_list_each_district(self.db) - self.main_dir = datetime.datetime.now().strftime('%Y%m%d_%H%M%S') + "_epanet_data" + self.main_dir = args.output + datetime.datetime.now().strftime('%Y%m%d_%H%M%S') + "_epanet_data" self.exportdir_list = [] wss_list_obj = WaterSupplySystems() if args.elevation == True: diff --git a/postgis2epanet.py b/postgis2epanet.py index e55c063..9176b03 100644 --- a/postgis2epanet.py +++ b/postgis2epanet.py @@ -42,6 +42,9 @@ def create_argument_parser(): default=False, help="If you use this option, the script is going to update elevation field of all layers.") + parser.add_argument("-o", "--output", default="./data/", type=str, + help="Output directory. Default is to export under data directory") + return parser.parse_args()