Skip to content

Commit

Permalink
Rename one environment variable: DOCKER_CONTAINER -> `DOCKER_CONTAI…
Browse files Browse the repository at this point in the history
…NER_NAME`
  • Loading branch information
jarkkoka committed Mar 22, 2022
1 parent 45b0907 commit e25420a
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions export_infra_network_csv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ set -euxo pipefail
source "$(cd "$(dirname "$0")"; pwd -P)/set_env_vars.sh"

# Start Docker container. The container is expected to exist and contain all the data to be exported.
docker start $DOCKER_CONTAINER
docker start $DOCKER_CONTAINER_NAME

# Wait for PostgreSQL to start.
docker exec "${DOCKER_CONTAINER}" sh -c "$PG_WAIT_LOCAL"
docker exec "${DOCKER_CONTAINER_NAME}" sh -c "$PG_WAIT_LOCAL"

# Export CSV file to output directory.
OUTPUT_FILENAME="infra_network_digiroad.csv"
OUTPUT_FOLDER="${WORK_DIR}/csv"
mkdir -p "${OUTPUT_FOLDER}"
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${CWD}/sql:/tmp/sql -v ${OUTPUT_FOLDER}:/tmp/csv ${DOCKER_IMAGE} \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${CWD}/sql:/tmp/sql -v ${OUTPUT_FOLDER}:/tmp/csv ${DOCKER_IMAGE} \
sh -c "$PSQL -v ON_ERROR_STOP=1 -f /tmp/sql/select_infra_links_as_csv.sql -v schema=${DB_IMPORT_SCHEMA_NAME} -o /tmp/csv/${OUTPUT_FILENAME}"

# Stop Docker container.
docker stop $DOCKER_CONTAINER
docker stop $DOCKER_CONTAINER_NAME
8 changes: 4 additions & 4 deletions export_mbtiles_dr_linkki.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ GEOJSON_OUTPUT_FILE="${OUTPUT_FILE_BASENAME}.geojson"
MBTILES_OUTPUT_FILE="${OUTPUT_FILE_BASENAME}.mbtiles"

# Start Docker container. The container is expected to exist and contain required database table to be exported.
docker start $DOCKER_CONTAINER
docker start $DOCKER_CONTAINER_NAME

# Wait for PostgreSQL to start.
docker run --rm --link "${DOCKER_CONTAINER}":postgres $DOCKER_IMAGE sh -c "$PG_WAIT"
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres $DOCKER_IMAGE sh -c "$PG_WAIT"

PGSQL2SHP='pgsql2shp -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -u digiroad'

# Export pg_dump file from database.
time docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${SHP_OUTPUT_DIR}/:/tmp/shp $DOCKER_IMAGE \
time docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${SHP_OUTPUT_DIR}/:/tmp/shp $DOCKER_IMAGE \
sh -c "$PGSQL2SHP -f /tmp/shp/${SHP_OUTPUT_FILE} digiroad ${DB_MBTILES_SCHEMA_NAME}.${DB_TABLE_NAME}"

# Convert from Shapefile to GeoJSON.
Expand All @@ -51,4 +51,4 @@ docker run --rm -v ${MBTILES_OUTPUT_DIR}/:/tmp/mbtiles -v ${GEOJSON_OUTPUT_DIR}:
sh -c "tippecanoe /tmp/geojson/$GEOJSON_OUTPUT_FILE -o /tmp/$MBTILES_OUTPUT_FILE -z$MBTILES_MAX_ZOOM_LEVEL -X -l $MBTILES_LAYER_NAME -n \"$MBTILES_DESCRIPTION\" -f; mv /tmp/$MBTILES_OUTPUT_FILE /tmp/mbtiles/$MBTILES_OUTPUT_FILE"

# Stop Docker container.
docker stop $DOCKER_CONTAINER
docker stop $DOCKER_CONTAINER_NAME
8 changes: 4 additions & 4 deletions export_mbtiles_dr_pysakki.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ GEOJSON_OUTPUT_FILE="${OUTPUT_FILE_BASENAME}.geojson"
MBTILES_OUTPUT_FILE="${OUTPUT_FILE_BASENAME}.mbtiles"

# Start Docker container. The container is expected to exist and contain required database table to be exported.
docker start $DOCKER_CONTAINER
docker start $DOCKER_CONTAINER_NAME

# Wait for PostgreSQL to start.
docker run --rm --link "${DOCKER_CONTAINER}":postgres $DOCKER_IMAGE sh -c "$PG_WAIT"
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres $DOCKER_IMAGE sh -c "$PG_WAIT"

PGSQL2SHP='pgsql2shp -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -u digiroad'

# Export pg_dump file from database.
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${SHP_OUTPUT_DIR}/:/tmp/shp $DOCKER_IMAGE \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${SHP_OUTPUT_DIR}/:/tmp/shp $DOCKER_IMAGE \
sh -c "$PGSQL2SHP -f /tmp/shp/${SHP_OUTPUT_FILE} digiroad ${DB_MBTILES_SCHEMA_NAME}.${DB_TABLE_NAME}"

# Convert from Shapefile to GeoJSON.
Expand All @@ -51,4 +51,4 @@ docker run --rm -v ${MBTILES_OUTPUT_DIR}/:/tmp/mbtiles -v ${GEOJSON_OUTPUT_DIR}:
sh -c "tippecanoe /tmp/geojson/$GEOJSON_OUTPUT_FILE -o /tmp/$MBTILES_OUTPUT_FILE -z$MBTILES_MAX_ZOOM_LEVEL -X -l $MBTILES_LAYER_NAME -n \"$MBTILES_DESCRIPTION\" -f; mv /tmp/$MBTILES_OUTPUT_FILE /tmp/mbtiles/$MBTILES_OUTPUT_FILE"

# Stop Docker container.
docker stop $DOCKER_CONTAINER
docker stop $DOCKER_CONTAINER_NAME
8 changes: 4 additions & 4 deletions export_pgdump_digiroad.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ set -euxo pipefail
source "$(cd "$(dirname "$0")"; pwd -P)/set_env_vars.sh"

# Start Docker container. The container is expected to exist and contain all the data to be exported.
docker start $DOCKER_CONTAINER
docker start $DOCKER_CONTAINER_NAME

# Wait for PostgreSQL to start.
docker run --rm --link "${DOCKER_CONTAINER}":postgres $DOCKER_IMAGE sh -c "$PG_WAIT"
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres $DOCKER_IMAGE sh -c "$PG_WAIT"

PGDUMP_OUTPUT="digiroad_r_$(date "+%Y-%m-%d").pgdump"
OUTPUT_TABLES="dr_linkki dr_pysakki dr_kaantymisrajoitus"
Expand All @@ -19,8 +19,8 @@ OUTPUT_TABLE_OPTIONS="`echo ${OUTPUT_TABLES[@]} | sed \"s/dr_/-t ${DB_IMPORT_SCH
mkdir -p ${WORK_DIR}/pgdump

# Export pg_dump file.
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${WORK_DIR}/pgdump/:/tmp/pgdump $DOCKER_IMAGE \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${WORK_DIR}/pgdump/:/tmp/pgdump $DOCKER_IMAGE \
sh -c "$PG_DUMP -Fc --clean -f /tmp/pgdump/${PGDUMP_OUTPUT} $OUTPUT_TABLE_OPTIONS"

# Stop Docker container.
docker stop $DOCKER_CONTAINER
docker stop $DOCKER_CONTAINER_NAME
14 changes: 7 additions & 7 deletions export_routing_schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ source "$(cd "$(dirname "$0")"; pwd -P)/set_env_vars.sh"
#
# The container is expected to exist and contain Digiroad schema with data
# populated from shapefiles.
docker start $DOCKER_CONTAINER
docker start $DOCKER_CONTAINER_NAME

# Wait for PostgreSQL to start.
docker exec "${DOCKER_CONTAINER}" sh -c "$PG_WAIT_LOCAL"
docker exec "${DOCKER_CONTAINER_NAME}" sh -c "$PG_WAIT_LOCAL"

# Create routing schema. pgRouting topology is created as well.
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${CWD}/sql:/tmp/sql ${DOCKER_IMAGE} \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${CWD}/sql:/tmp/sql ${DOCKER_IMAGE} \
sh -c "$PSQL -v ON_ERROR_STOP=1 -f /tmp/sql/routing/create_routing_schema.sql -v source_schema=${DB_IMPORT_SCHEMA_NAME} -v schema=${DB_ROUTING_SCHEMA_NAME} -v sql_dir=/tmp/sql"

DUMP_DIR="${WORK_DIR}/pgdump"
Expand All @@ -30,21 +30,21 @@ mkdir -p "${DUMP_DIR}"
# profile of map-matching backend where database migration scripts are bypassed.
# All the table definitions are created and data populated in one shot based on
# this dump.
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${DUMP_DIR}:/tmp/pgdump $DOCKER_IMAGE \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${DUMP_DIR}:/tmp/pgdump $DOCKER_IMAGE \
sh -c "$PG_DUMP --clean --if-exists --no-owner -f /tmp/pgdump/${SQL_OUTPUT} --schema=${DB_ROUTING_SCHEMA_NAME}"

# Export the entire routing schema (with data) as a dump file in PostgreSQL's
# custom format. With custom format, the restoration of schema and/or table
# data items can be selectively filtered and applied by passing a toc list
# (table of contents) file as an argument to `pg_restore` command.
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${DUMP_DIR}:/tmp/pgdump $DOCKER_IMAGE \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${DUMP_DIR}:/tmp/pgdump $DOCKER_IMAGE \
sh -c "$PG_DUMP --format=c --clean --no-owner -f /tmp/pgdump/${PGDUMP_OUTPUT} --schema=${DB_ROUTING_SCHEMA_NAME}"

# Dump a toc list file (for the generated pg_dump file) that lists the items
# contained in the dump file. The list can be edited by re-ordering or
# removing items that are not intended to be restored. That makes it possible
# to e.g. restore data only for selected database tables.
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${DUMP_DIR}:/tmp/pgdump $DOCKER_IMAGE \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${DUMP_DIR}:/tmp/pgdump $DOCKER_IMAGE \
sh -c "pg_restore --list \"/tmp/pgdump/${PGDUMP_OUTPUT}\" --file=\"/tmp/pgdump/${PGDUMP_OUTPUT}.list\""

# Derive additional toc lists for restoring data (and only data) for selected
Expand All @@ -53,4 +53,4 @@ docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${DUMP_DIR}:/tmp/pgdump
${CWD}/util/create_additional_pgdump_tocs.sh ${DUMP_DIR}/${PGDUMP_OUTPUT}

# Stop Docker container.
docker stop $DOCKER_CONTAINER
docker stop $DOCKER_CONTAINER_NAME
8 changes: 4 additions & 4 deletions export_stops_csv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ set -euxo pipefail
source "$(cd "$(dirname "$0")"; pwd -P)/set_env_vars.sh"

# Start Docker container. The container is expected to exist and contain all the data to be exported.
docker start $DOCKER_CONTAINER
docker start $DOCKER_CONTAINER_NAME

# Wait for PostgreSQL to start.
docker exec "${DOCKER_CONTAINER}" sh -c "$PG_WAIT_LOCAL"
docker exec "${DOCKER_CONTAINER_NAME}" sh -c "$PG_WAIT_LOCAL"

# Export csv file to output directory.
OUTPUT_FILENAME="digiroad_stops.csv"
mkdir -p ${WORK_DIR}/csv
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${CWD}/sql:/tmp/sql -v ${WORK_DIR}/csv:/tmp/csv ${DOCKER_IMAGE} \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${CWD}/sql:/tmp/sql -v ${WORK_DIR}/csv:/tmp/csv ${DOCKER_IMAGE} \
sh -c "$PSQL -v ON_ERROR_STOP=1 -f /tmp/sql/select_stops_as_csv.sql -v schema=${DB_IMPORT_SCHEMA_NAME} -o /tmp/csv/${OUTPUT_FILENAME}"

# Stop Docker container.
docker stop $DOCKER_CONTAINER
docker stop $DOCKER_CONTAINER_NAME
26 changes: 13 additions & 13 deletions import_digiroad_shapefiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ if [[ ! -f "${SHP_FILE_DIR}/DR_PYSAKKI.shp" ]]; then
fi

# Remove possibly running/existing Docker container.
docker kill $DOCKER_CONTAINER &> /dev/null || true
docker rm -v $DOCKER_CONTAINER &> /dev/null || true
docker kill $DOCKER_CONTAINER_NAME &> /dev/null || true
docker rm -v $DOCKER_CONTAINER_NAME &> /dev/null || true

# Create and start new Docker container.
docker run --name $DOCKER_CONTAINER -e POSTGRES_HOST_AUTH_METHOD=trust -d $DOCKER_IMAGE
docker run --name $DOCKER_CONTAINER_NAME -e POSTGRES_HOST_AUTH_METHOD=trust -d $DOCKER_IMAGE

# Wait for PostgreSQL to start.
docker exec "${DOCKER_CONTAINER}" sh -c "$PG_WAIT_LOCAL"
docker exec "${DOCKER_CONTAINER_NAME}" sh -c "$PG_WAIT_LOCAL"

# Create digiroad import schema into database.
docker exec "${DOCKER_CONTAINER}" sh -c "$PSQL -nt -c \"CREATE SCHEMA ${DB_IMPORT_SCHEMA_NAME};\""
docker exec "${DOCKER_CONTAINER_NAME}" sh -c "$PSQL -nt -c \"CREATE SCHEMA ${DB_IMPORT_SCHEMA_NAME};\""

SHP2PGSQL="shp2pgsql -D -i -s 3067 -S -N abort -W $SHP_ENCODING"

Expand All @@ -62,33 +62,33 @@ do
TABLE_NAME="${DB_IMPORT_SCHEMA_NAME}.`echo ${SUB_AREA_SHP_TYPE} | awk '{print tolower($0)}'`"

# Create database table for each shape type.
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${SHP_FILE_DIR}:/tmp/shp $DOCKER_IMAGE \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${SHP_FILE_DIR}:/tmp/shp $DOCKER_IMAGE \
sh -c "$SHP2PGSQL -p /tmp/shp/${SUB_AREA}/${SUB_AREA_SHP_TYPE}.shp $TABLE_NAME | $PSQL -v ON_ERROR_STOP=1 -q"

# Populate database table from multiple shapefiles from sub areas.
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${SHP_FILE_DIR}:/tmp/shp $DOCKER_IMAGE \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${SHP_FILE_DIR}:/tmp/shp $DOCKER_IMAGE \
sh -c "for SUB_AREA in ${SUB_AREAS}; do $SHP2PGSQL -a /tmp/shp/\${SUB_AREA}/${SUB_AREA_SHP_TYPE}.shp $TABLE_NAME | $PSQL -v ON_ERROR_STOP=1; done"
done

# Process road geometries and filtering properties in database.
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${CWD}/sql:/tmp/sql \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${CWD}/sql:/tmp/sql \
${DOCKER_IMAGE} sh -c "$PSQL -v ON_ERROR_STOP=1 -f /tmp/sql/transform_dr_linkki.sql -v schema=${DB_IMPORT_SCHEMA_NAME} -v sql_dir=/tmp/sql"

# Load DR_PYSAKKI shapefile into database.
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${SHP_FILE_DIR}:/tmp/shp $DOCKER_IMAGE \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${SHP_FILE_DIR}:/tmp/shp $DOCKER_IMAGE \
sh -c "$SHP2PGSQL -c /tmp/shp/DR_PYSAKKI.shp ${DB_IMPORT_SCHEMA_NAME}.dr_pysakki | $PSQL -v ON_ERROR_STOP=1"

# Process stops and filter properties in database.
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${CWD}/sql:/tmp/sql \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${CWD}/sql:/tmp/sql \
${DOCKER_IMAGE} sh -c "$PSQL -v ON_ERROR_STOP=1 -f /tmp/sql/transform_dr_pysakki.sql -v schema=${DB_IMPORT_SCHEMA_NAME} -v sql_dir=/tmp/sql"

# Process turn restrictions and filter properties in database.
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${CWD}/sql:/tmp/sql \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${CWD}/sql:/tmp/sql \
${DOCKER_IMAGE} sh -c "$PSQL -v ON_ERROR_STOP=1 -f /tmp/sql/transform_dr_kaantymisrajoitus.sql -v schema=${DB_IMPORT_SCHEMA_NAME}"

# Create separate schema for exporting data in MBTiles format.
docker run --rm --link "${DOCKER_CONTAINER}":postgres -v ${CWD}/sql:/tmp/sql \
docker run --rm --link "${DOCKER_CONTAINER_NAME}":postgres -v ${CWD}/sql:/tmp/sql \
${DOCKER_IMAGE} sh -c "$PSQL -v ON_ERROR_STOP=1 -f /tmp/sql/create_mbtiles_schema.sql -v source_schema=${DB_IMPORT_SCHEMA_NAME} -v schema=${DB_MBTILES_SCHEMA_NAME} -v sql_dir=/tmp/sql"

# Stop Docker container.
docker stop $DOCKER_CONTAINER
docker stop $DOCKER_CONTAINER_NAME
2 changes: 1 addition & 1 deletion set_env_vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export WORK_DIR="${CWD}/workdir"
export SHP_ENCODING="UTF-8"

export DOCKER_IMAGE="jore4/postgis-digiroad"
export DOCKER_CONTAINER="jore4-postgis-digiroad"
export DOCKER_CONTAINER_NAME="jore4-postgis-digiroad"

# Database details
export DB_NAME="digiroad"
Expand Down

0 comments on commit e25420a

Please sign in to comment.