-
Notifications
You must be signed in to change notification settings - Fork 59
fix(entrypoint): honor STOP_AFTER_INIT if DB already initialized #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
39a064f
6b68776
0191113
409cdc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,11 +36,13 @@ for f in /docker-entrypoint-initdb.d/*; do | |
| echo | ||
| done | ||
|
|
||
| if [[ ! -f /db/init_done ]]; then | ||
| initialize_db_dir() { | ||
| echo "No database directory. Initializing" | ||
| touch /db/changes.log | ||
| mkdir -p /db/diffs | ||
| } | ||
|
|
||
| setup_cookie_jar() { | ||
| if [[ "${USE_OAUTH_COOKIE_CLIENT}" = "yes" ]]; then | ||
| /app/venv/bin/python /app/bin/oauth_cookie_client.py -o /db/cookie.jar -s /secrets/oauth-settings.json --format netscape | ||
| # necessary to add newline at the end as oauth_cookie_client doesn't do that | ||
|
|
@@ -50,8 +52,13 @@ if [[ ! -f /db/init_done ]]; then | |
| echo "${OVERPASS_COOKIE_JAR_CONTENTS}" >>/db/cookie.jar | ||
| fi | ||
| chown -R overpass:overpass /db/cookie.jar /db/changes.log /db/diffs | ||
| } | ||
|
|
||
| if [[ "$OVERPASS_MODE" = "clone" ]]; then | ||
|
|
||
| if [[ "$OVERPASS_MODE" = "clone" ]]; then | ||
| if [[ ! -f /db/init_done ]]; then | ||
| initialize_db_dir | ||
| setup_cookie_jar | ||
| ( | ||
| mkdir -p /db/db && | ||
| /app/bin/download_clone.sh --db-dir=/db/db --source="${OVERPASS_CLONE_SOURCE}" --meta="${OVERPASS_META}" && | ||
|
|
@@ -63,15 +70,14 @@ if [[ ! -f /db/init_done ]]; then | |
| echo "Failed to clone overpass repository" | ||
| exit 1 | ||
| ) | ||
| if [[ "${OVERPASS_STOP_AFTER_INIT}" == "false" ]]; then | ||
| echo "Overpass container ready to receive requests" | ||
| else | ||
| echo "Overpass container initialization complete. Exiting." | ||
| exit 0 | ||
| fi | ||
| fi | ||
| fi | ||
|
|
||
| if [[ "$OVERPASS_MODE" = "init" ]]; then | ||
| if [[ "$OVERPASS_MODE" = "init" ]]; then | ||
| if [[ ! -f /db/init_done ]]; then | ||
| initialize_db_dir | ||
| setup_cookie_jar | ||
|
|
||
| CURL_STATUS_CODE=$(curl -L -b /db/cookie.jar -o /db/planet.osm.bz2 -w "%{http_code}" "${OVERPASS_PLANET_URL}") | ||
| # try again until it's allowed | ||
| while [ "$CURL_STATUS_CODE" = "429" ]; do | ||
|
|
@@ -102,12 +108,6 @@ if [[ ! -f /db/init_done ]]; then | |
| echo "Failed to process planet file" | ||
| exit 1 | ||
| ) | ||
| if [[ "${OVERPASS_STOP_AFTER_INIT}" == "false" ]]; then | ||
| echo "Overpass container ready to receive requests" | ||
| else | ||
| echo "Overpass container initialization complete. Exiting." | ||
| exit 0 | ||
| fi | ||
| elif [[ $CURL_STATUS_CODE = "403" ]]; then | ||
| echo "Access denied when downloading planet file. Check your OVERPASS_PLANET_URL and OVERPASS_COOKIE_JAR_CONTENTS or USE_OAUTH_COOKIE_CLIENT" | ||
| cat /db/cookie.jar | ||
|
|
@@ -120,6 +120,15 @@ if [[ ! -f /db/init_done ]]; then | |
| fi | ||
| fi | ||
|
|
||
| if [[ "$OVERPASS_MODE" = "init" || "$OVERPASS_MODE" = "clone" ]]; then | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the point of this check? Since only "init" or "clone" are allowed values this if is always true. |
||
| if [[ "${OVERPASS_STOP_AFTER_INIT}" == "false" ]]; then | ||
| echo "Overpass container ready to receive requests" | ||
| else | ||
| echo "Overpass container initialization complete. Exiting." | ||
| exit 0 | ||
| fi | ||
|
Comment on lines
+124
to
+129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just move this one |
||
| fi | ||
|
|
||
| # shellcheck disable=SC2016 # ignore SC2016 (variables within single quotes) as this is exactly what we want to do here | ||
| envsubst '${OVERPASS_MAX_TIMEOUT}' </etc/nginx/nginx.conf.template >/etc/nginx/nginx.conf | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see a lot of readability improvement by introducing those two functions and reversing the order of checks for
OVERPASS_MODEand-f /db/init_done. Can you elaborate, why you think this improves readability?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The refactor itself wasn’t actually "the goal". it was needed so I could introduce the logic change (moving the OVERPASS_STOP_AFTER_INIT check after the init_done guard) in a clean, isolated commit. Breaking it out into functions made the flow easier to rearrange without duplicating code, and kept the "fix commit" focused more on behavior.
Basically the fix introduced required refactors, and I split the refactors out of the fix commit, to keep the scope solely to the fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced that this change was necessary. What is the reason in changing:
Into: