-
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
Open
bastien8060
wants to merge
4
commits into
wiktorn:master
Choose a base branch
from
bastien8060:fix/entrypoint-stop-after-init
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
39a064f
refactor: Extract initialization logic into separate functions for cl…
bastien8060 6b68776
refactor: Rearrange initialization logic for clarity in entrypoint sc…
bastien8060 0191113
fix(entrypoint): honor OVERPASS_STOP_AFTER_INIT when DB already initi…
bastien8060 409cdc0
refactor: simply init logic by consolidating exit conditions
bastien8060 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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,21 @@ 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 | ||
|
|
||
| if [[ "$OVERPASS_MODE" = "init" ]]; then | ||
| 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 | ||
|
|
||
| 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 +115,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 | ||
|
|
@@ -118,6 +125,13 @@ if [[ ! -f /db/init_done ]]; then | |
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| 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 | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: