|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 | set -e
|
3 |
| -export VOLUME_DIR=/mnt/data |
4 | 3 |
|
5 | 4 | # osmosis tuning: https://wiki.openstreetmap.org/wiki/Osmosis/Tuning,https://lists.openstreetmap.org/pipermail/talk/2012-October/064771.html
|
6 | 5 | if [ -z "$MEMORY_JAVACMD_OPTIONS" ]; then
|
|
10 | 9 | echo JAVACMD_OPTIONS=\"-server -Xmx$memory\" >~/.osmosis
|
11 | 10 | fi
|
12 | 11 |
|
13 |
| -# Read the DB and create the planet osm file |
| 12 | +export VOLUME_DIR=/mnt/data |
14 | 13 | date=$(date '+%y%m%d_%H%M')
|
| 14 | + |
15 | 15 | local_planetPBFFile=$VOLUME_DIR/planet-${date}.osm.pbf
|
16 | 16 | cloud_planetPBFFile=planet/planet-${date}.osm.pbf
|
| 17 | +stateFile="$VOLUME_DIR/state.txt" |
17 | 18 |
|
18 |
| -# In case overwrite the file |
| 19 | +# If overwrite flag is enabled, use fixed filenames |
19 | 20 | if [ "$OVERWRITE_PLANET_FILE" == "true" ]; then
|
20 | 21 | local_planetPBFFile=$VOLUME_DIR/planet-latest.osm.pbf
|
21 | 22 | cloud_planetPBFFile=planet/planet-latest.osm.pbf
|
22 | 23 | fi
|
23 | 24 |
|
24 |
| -stateFile="$VOLUME_DIR/state.txt" |
| 25 | +# =============================== |
| 26 | +# Download db .dump file |
| 27 | +# =============================== |
| 28 | +download_dump_file() { |
| 29 | + local_dumpFile="$VOLUME_DIR/input-latest.dump" |
| 30 | + echo "Downloading db .dump file from cloud..." |
25 | 31 |
|
26 |
| -# Creating the replication file |
27 |
| -osmosis --read-apidb \ |
28 |
| - host=$POSTGRES_HOST \ |
29 |
| - database=$POSTGRES_DB \ |
30 |
| - user=$POSTGRES_USER \ |
31 |
| - password=$POSTGRES_PASSWORD \ |
32 |
| - validateSchemaVersion=no \ |
33 |
| - --write-pbf \ |
34 |
| - file=$local_planetPBFFile |
| 32 | + if [ "$CLOUDPROVIDER" == "aws" ]; then |
| 33 | + aws s3 cp "$DUMP_CLOUD_URL" "$local_dumpFile" |
| 34 | + elif [ "$CLOUDPROVIDER" == "gcp" ]; then |
| 35 | + gsutil cp "$DUMP_CLOUD_URL" "$local_dumpFile" |
| 36 | + fi |
| 37 | +} |
35 | 38 |
|
36 |
| -# AWS |
37 |
| -if [ $CLOUDPROVIDER == "aws" ]; then |
38 |
| - # Save the path file |
39 |
| - AWS_URL=${AWS_S3_BUCKET/s3:\/\//http:\/\/} |
40 |
| - echo "$AWS_URL.s3.amazonaws.com/$cloud_planetPBFFile" > $stateFile |
41 |
| - # Upload planet.osm.pbf file to s3 |
42 |
| - aws s3 cp $local_planetPBFFile $AWS_S3_BUCKET/$cloud_planetPBFFile --acl public-read |
43 |
| - # Upload state.txt file to s3 |
44 |
| - aws s3 cp $stateFile $AWS_S3_BUCKET/planet/state.txt --acl public-read |
45 |
| -fi |
| 39 | +# =============================== |
| 40 | +# Upload planet + state |
| 41 | +# =============================== |
| 42 | +upload_planet_file() { |
| 43 | + echo "Uploading planet file and updating state.txt..." |
46 | 44 |
|
47 |
| -# gcp |
48 |
| -if [ $CLOUDPROVIDER == "gcp" ]; then |
49 |
| - # Save the path file |
50 |
| - echo "https://storage.cloud.google.com/$GCP_STORAGE_BUCKET/$cloud_planetPBFFile" > $stateFile |
51 |
| - # Upload planet.osm.pbf file to cloud storage |
52 |
| - gsutil cp -a public-read $local_planetPBFFile $GCP_STORAGE_BUCKET/$cloud_planetPBFFile |
53 |
| - # Upload state.txt file to cloud storage |
54 |
| - gsutil cp -a public-read $stateFile $GCP_STORAGE_BUCKET/planet/state.txt |
55 |
| -fi |
| 45 | + if [ "$CLOUDPROVIDER" == "aws" ]; then |
| 46 | + AWS_URL=${AWS_S3_BUCKET/s3:\/\//http:\/\/} |
| 47 | + echo "$AWS_URL.s3.amazonaws.com/$cloud_planetPBFFile" > "$stateFile" |
| 48 | + aws s3 cp "$local_planetPBFFile" "$AWS_S3_BUCKET/$cloud_planetPBFFile" --acl public-read |
| 49 | + aws s3 cp "$stateFile" "$AWS_S3_BUCKET/planet/state.txt" --acl public-read |
| 50 | + |
| 51 | + elif [ "$CLOUDPROVIDER" == "gcp" ]; then |
| 52 | + echo "https://storage.cloud.google.com/$GCP_STORAGE_BUCKET/$cloud_planetPBFFile" > "$stateFile" |
| 53 | + gsutil cp -a public-read "$local_planetPBFFile" "$GCP_STORAGE_BUCKET/$cloud_planetPBFFile" |
| 54 | + gsutil cp -a public-read "$stateFile" "$GCP_STORAGE_BUCKET/planet/state.txt" |
| 55 | + fi |
| 56 | +} |
| 57 | + |
| 58 | +# =============================== |
| 59 | +# Generate planet file |
| 60 | +# =============================== |
56 | 61 |
|
57 |
| -# Azure |
58 |
| -if [ $CLOUDPROVIDER == "azure" ]; then |
59 |
| - # Save the path file |
60 |
| - echo "https://$AZURE_STORAGE_ACCOUNT.blob.core.windows.net/$AZURE_CONTAINER_NAME/$cloud_planetPBFFile" > $stateFile |
61 |
| - # Upload planet.osm.pbf file to blob storage |
62 |
| - az storage blob upload \ |
63 |
| - --container-name $AZURE_CONTAINER_NAME \ |
64 |
| - --file $local_planetPBFFile \ |
65 |
| - --name $cloud_planetPBFFile \ |
66 |
| - --output table |
67 |
| - # Upload state.txt file to blob storage |
68 |
| - az storage blob upload \ |
69 |
| - --container-name $AZURE_CONTAINER_NAME \ |
70 |
| - --file $stateFile \ |
71 |
| - --name planet/state.txt \ |
72 |
| - --output table |
| 62 | +if [ "$PLANET_EXPORT_METHOD" == "planet-dump-ng" ]; then |
| 63 | + download_dump_file |
| 64 | + echo "Generating planet file with planet-dump-ng..." |
| 65 | + planet-dump-ng \ |
| 66 | + --dump-file "$VOLUME_DIR/input-latest.dump" \ |
| 67 | + --pbf "$local_planetPBFFile" |
| 68 | +elif [ "$PLANET_EXPORT_METHOD" == "osmosis" ]; then |
| 69 | + echo "Generating planet file with osmosis..." |
| 70 | + if [ -z "$MEMORY_JAVACMD_OPTIONS" ]; then |
| 71 | + echo JAVACMD_OPTIONS=\"-server\" > ~/.osmosis |
| 72 | + else |
| 73 | + memory="${MEMORY_JAVACMD_OPTIONS//i/}" |
| 74 | + echo JAVACMD_OPTIONS=\"-server -Xmx$memory\" > ~/.osmosis |
| 75 | + fi |
| 76 | + |
| 77 | + osmosis --read-apidb \ |
| 78 | + host=$POSTGRES_HOST \ |
| 79 | + database=$POSTGRES_DB \ |
| 80 | + user=$POSTGRES_USER \ |
| 81 | + password=$POSTGRES_PASSWORD \ |
| 82 | + validateSchemaVersion=no \ |
| 83 | + --write-pbf \ |
| 84 | + file=$local_planetPBFFile |
| 85 | +else |
| 86 | + echo "Error: Unknown PLANET_EXPORT_METHOD value. Use 'planet-dump-ng' or 'osmosis'." |
| 87 | + exit 1 |
73 | 88 | fi
|
| 89 | + |
| 90 | +# Upload results |
| 91 | +upload_planet_file |
0 commit comments