feat: add Docker/OpenTofu deployment and DE/NL routing
This commit is contained in:
+74
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
|
||||
TEST_DIR="$(mktemp -d)"
|
||||
trap 'rm -rf "$TEST_DIR"' EXIT
|
||||
|
||||
export WATERMAPS_DATA_DIR="$TEST_DIR/data"
|
||||
export WATERMAPS_RUNTIME_DIR="$TEST_DIR/runtime"
|
||||
mkdir -p "$WATERMAPS_DATA_DIR/local" "$WATERMAPS_RUNTIME_DIR"
|
||||
|
||||
# shellcheck source=../common.sh
|
||||
source "$ROOT_DIR/deploy/scripts/common.sh"
|
||||
|
||||
route_file="$(wm_route_file)"
|
||||
route_marker="$(wm_route_marker)"
|
||||
|
||||
write_valid_route() {
|
||||
cat >"$route_file" <<'JSON'
|
||||
{
|
||||
"version": 1,
|
||||
"generatorVersion": 2,
|
||||
"source": "germany+netherlands",
|
||||
"sources": [
|
||||
{
|
||||
"region": "germany",
|
||||
"file": "germany-latest.osm.pbf",
|
||||
"checksumMd5": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"sizeBytes": 1
|
||||
},
|
||||
{
|
||||
"region": "netherlands",
|
||||
"file": "netherlands-latest.osm.pbf",
|
||||
"checksumMd5": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||
"sizeBytes": 1
|
||||
}
|
||||
],
|
||||
"ways": [{"id": "1"}]
|
||||
}
|
||||
JSON
|
||||
chmod 0644 "$route_file"
|
||||
}
|
||||
|
||||
write_valid_route
|
||||
wm_write_route_marker "$route_file" "$route_marker"
|
||||
wm_route_data_ready
|
||||
|
||||
sed -i 's/^size_bytes=.*/size_bytes=1/' "$route_marker"
|
||||
if wm_route_data_ready; then
|
||||
printf 'Ungültige Markergröße wurde akzeptiert.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
wm_write_route_marker "$route_file" "$route_marker"
|
||||
jq '.sources = [.sources[0]] | .source = "germany"' \
|
||||
"$route_file" >"$route_file.tmp"
|
||||
mv "$route_file.tmp" "$route_file"
|
||||
chmod 0644 "$route_file"
|
||||
wm_write_route_marker "$route_file" "$route_marker"
|
||||
if wm_route_data_ready; then
|
||||
printf 'Deutschland-only-Index wurde akzeptiert.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
write_valid_route
|
||||
wm_write_route_marker "$route_file" "$route_marker"
|
||||
chmod 0600 "$route_file"
|
||||
if wm_route_data_ready; then
|
||||
printf 'Für den App-Container unlesbarer Index wurde akzeptiert.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf 'Routingdaten- und Markerprüfungen: OK\n'
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
|
||||
TEST_DIR="$(mktemp -d)"
|
||||
trap 'rm -rf "$TEST_DIR"' EXIT
|
||||
|
||||
FAKE_BIN="$TEST_DIR/bin"
|
||||
DATA_DIR="$TEST_DIR/data"
|
||||
RUNTIME_DIR="$TEST_DIR/runtime"
|
||||
ENV_FILE="$TEST_DIR/production.env"
|
||||
mkdir -p "$FAKE_BIN" "$DATA_DIR/local" "$RUNTIME_DIR"
|
||||
|
||||
cat >"$ENV_FILE" <<EOF
|
||||
WATERMAPS_DATA_DIR=$DATA_DIR
|
||||
WATERMAPS_RUNTIME_DIR=$RUNTIME_DIR
|
||||
EOF
|
||||
|
||||
cat >"$FAKE_BIN/id" <<'SH'
|
||||
#!/usr/bin/env bash
|
||||
if [[ "${1:-}" == "-u" ]]; then
|
||||
printf '0\n'
|
||||
else
|
||||
exec /usr/bin/id "$@"
|
||||
fi
|
||||
SH
|
||||
|
||||
cat >"$FAKE_BIN/mountpoint" <<'SH'
|
||||
#!/usr/bin/env bash
|
||||
exit 0
|
||||
SH
|
||||
|
||||
cat >"$FAKE_BIN/docker" <<'SH'
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
if [[ "${1:-}" == "inspect" ]]; then
|
||||
printf 'healthy\n'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
arguments=" $* "
|
||||
if [[ "$arguments" == *" ps --quiet watermaps "* ]]; then
|
||||
printf 'watermaps-test-container\n'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$arguments" == *" run "*" route-data "* ||
|
||||
"$arguments" == *" run "*" route-data" ]]; then
|
||||
route_file="$WATERMAPS_DATA_DIR/local/.germany-netherlands-fairways.candidate.json"
|
||||
marker_file="$WATERMAPS_DATA_DIR/local/.germany-netherlands-fairways.candidate.ready"
|
||||
cat >"$route_file" <<JSON
|
||||
{
|
||||
"version": 1,
|
||||
"generatorVersion": 2,
|
||||
"source": "germany+netherlands",
|
||||
"revision": ${FAKE_ROUTE_REVISION:-1},
|
||||
"sources": [
|
||||
{
|
||||
"region": "germany",
|
||||
"file": "germany-latest.osm.pbf",
|
||||
"checksumMd5": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"sizeBytes": 1
|
||||
},
|
||||
{
|
||||
"region": "netherlands",
|
||||
"file": "netherlands-latest.osm.pbf",
|
||||
"checksumMd5": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||
"sizeBytes": 1
|
||||
}
|
||||
],
|
||||
"ways": [{"id": "1"}]
|
||||
}
|
||||
JSON
|
||||
# shellcheck source=../common.sh
|
||||
source "$WM_TEST_ROOT/deploy/scripts/common.sh"
|
||||
wm_write_route_marker "$route_file" "$marker_file"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$arguments" == *" exec --no-TTY watermaps "* ]]; then
|
||||
active_file="$WATERMAPS_DATA_DIR/local/germany-netherlands-fairways.json"
|
||||
active_revision="$(jq --raw-output '.revision // 0' "$active_file" 2>/dev/null || true)"
|
||||
if [[ -n "${FAKE_FAIL_REVISION:-}" && "$active_revision" == "$FAKE_FAIL_REVISION" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit 0
|
||||
SH
|
||||
|
||||
chmod +x "$FAKE_BIN/id" "$FAKE_BIN/mountpoint" "$FAKE_BIN/docker"
|
||||
|
||||
export PATH="$FAKE_BIN:$PATH"
|
||||
export WATERMAPS_ENV_FILE="$ENV_FILE"
|
||||
export WM_TEST_ROOT="$ROOT_DIR"
|
||||
|
||||
# A first successful activation creates an active index and a validated marker.
|
||||
FAKE_ROUTE_REVISION=1 "$ROOT_DIR/deploy/scripts/update-route-data.sh"
|
||||
active_file="$DATA_DIR/local/germany-netherlands-fairways.json"
|
||||
active_marker="$DATA_DIR/local/.germany-netherlands-fairways.ready"
|
||||
[[ "$(jq --raw-output '.revision' "$active_file")" == "1" ]]
|
||||
|
||||
export WATERMAPS_DATA_DIR="$DATA_DIR"
|
||||
export WATERMAPS_RUNTIME_DIR="$RUNTIME_DIR"
|
||||
# shellcheck source=../common.sh
|
||||
source "$ROOT_DIR/deploy/scripts/common.sh"
|
||||
wm_route_data_files_ready "$active_file" "$active_marker"
|
||||
|
||||
# A candidate that fails its route smoke test must restore and retest revision 1.
|
||||
set +e
|
||||
FAKE_ROUTE_REVISION=2 FAKE_FAIL_REVISION=2 \
|
||||
"$ROOT_DIR/deploy/scripts/update-route-data.sh"
|
||||
update_status=$?
|
||||
set -e
|
||||
[[ "$update_status" -ne 0 ]]
|
||||
[[ "$(jq --raw-output '.revision' "$active_file")" == "1" ]]
|
||||
wm_route_data_files_ready "$active_file" "$active_marker"
|
||||
[[ ! -e "$RUNTIME_DIR/locks/route-update.transaction" ]]
|
||||
|
||||
# A hard-crash marker restores the durable previous index before any new build.
|
||||
backup_file="$DATA_DIR/local/.germany-netherlands-fairways.previous.json"
|
||||
backup_marker="$DATA_DIR/local/.germany-netherlands-fairways.previous.ready"
|
||||
cp "$active_file" "$backup_file"
|
||||
wm_write_route_marker "$backup_file" "$backup_marker"
|
||||
jq '.revision = 9' "$active_file" >"$active_file.tmp"
|
||||
mv "$active_file.tmp" "$active_file"
|
||||
chmod 0644 "$active_file"
|
||||
wm_write_route_marker "$active_file" "$active_marker"
|
||||
printf 'had_previous=true\n' >"$RUNTIME_DIR/locks/route-update.transaction"
|
||||
|
||||
FAKE_ROUTE_REVISION=1 "$ROOT_DIR/deploy/scripts/update-route-data.sh"
|
||||
[[ "$(jq --raw-output '.revision' "$active_file")" == "1" ]]
|
||||
wm_route_data_files_ready "$active_file" "$active_marker"
|
||||
[[ ! -e "$RUNTIME_DIR/locks/route-update.transaction" ]]
|
||||
|
||||
# Without a previous valid index, a failed first candidate must not stay ready.
|
||||
rm -f "$active_file" "$active_marker" \
|
||||
"$DATA_DIR/local/.germany-netherlands-fairways.previous.json" \
|
||||
"$DATA_DIR/local/.germany-netherlands-fairways.previous.ready"
|
||||
set +e
|
||||
FAKE_ROUTE_REVISION=3 FAKE_FAIL_REVISION=3 \
|
||||
"$ROOT_DIR/deploy/scripts/update-route-data.sh"
|
||||
first_update_status=$?
|
||||
set -e
|
||||
[[ "$first_update_status" -ne 0 ]]
|
||||
[[ ! -e "$active_file" ]]
|
||||
[[ ! -e "$active_marker" ]]
|
||||
[[ ! -e "$RUNTIME_DIR/locks/route-update.transaction" ]]
|
||||
|
||||
printf 'Staging-, Rollback- und First-Update-Prüfungen: OK\n'
|
||||
Reference in New Issue
Block a user