-
Notifications
You must be signed in to change notification settings - Fork 0
Next #15
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
Merged
Next #15
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -1,14 +1,16 @@ | ||
| FROM nginx:alpine | ||
|
|
||
| RUN apk add python3 py3-pip supervisor | ||
| RUN pip3 install --break-system-packages google-cloud-run | ||
| RUN apk add curl jq bash supervisor | ||
|
|
||
| COPY nginx.conf /etc/nginx/nginx.conf | ||
|
|
||
| COPY supervisord.conf /etc/supervisord.conf | ||
| COPY supervisor/supervisord.conf /etc/supervisord.conf | ||
| RUN mkdir -p /var/log/supervisor | ||
| RUN mkdir -p /etc/supervisor/conf.d | ||
|
|
||
| COPY cleanup_watcher.py /usr/local/bin/cleanup_watcher.py | ||
| RUN chmod +x /usr/local/bin/cleanup_watcher.py | ||
| COPY supervisor/conf.d /etc/supervisor/conf.d | ||
|
|
||
| COPY cleanup.bash /usr/local/bin/cleanup.bash | ||
| RUN chmod +x /usr/local/bin/cleanup.bash | ||
|
|
||
| CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"] | ||
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 |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #!/usr/bin/env bash | ||
| set -uo pipefail | ||
|
|
||
| PARENT="${PARENT:?PARENT env var required}" | ||
| SERVICE_NAME="${K_SERVICE:?K_SERVICE env var required}" | ||
|
|
||
| # ============================================= | ||
| # Cleanup / Crash Handler | ||
| # ============================================= | ||
| cleanup() { | ||
| EXIT_CODE=$? | ||
| if [ $EXIT_CODE -ne 0 ]; then | ||
| echo "==================================================================" | ||
| echo "❌ SCRIPT CRASHED with exit code ${EXIT_CODE}" | ||
| echo " This usually means something went wrong during health checking" | ||
| echo " or during the delete operation." | ||
| echo "==================================================================" | ||
| else | ||
| echo "Script finished normally." | ||
| fi | ||
| } | ||
|
|
||
| # Catch errors, interrupts, and normal exit | ||
| trap cleanup EXIT | ||
| trap 'echo "❌ Script interrupted (SIGINT)"; exit 1' INT | ||
| trap 'echo "❌ Script terminated (SIGTERM)"; exit 1' TERM | ||
|
|
||
| delete_service() { | ||
| echo "Flask appears down → Deleting service ${PARENT}/services/${SERVICE_NAME}" | ||
|
|
||
| # Get an OAuth2 access token from the GCE/Cloud Run metadata server | ||
| local token | ||
| token=$(curl -s -H "Metadata-Flavor: Google" \ | ||
| "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" \ | ||
| | jq -r .access_token) | ||
|
|
||
| if [ -z "$token" ]; then | ||
| echo "Delete failed: could not obtain access token" | ||
| return 1 | ||
| fi | ||
|
|
||
| local http_code | ||
| http_code=$(curl -s -o /tmp/delete_response.json -w "%{http_code}" \ | ||
| -X DELETE \ | ||
| -H "Authorization: Bearer ${token}" \ | ||
| "https://run.googleapis.com/v2/${PARENT}/services/${SERVICE_NAME}") | ||
|
|
||
| if [[ "$http_code" == 2* ]]; then | ||
| echo "Service deletion request accepted (HTTP ${http_code})" | ||
| else | ||
| echo "Delete failed (HTTP ${http_code}): $(cat /tmp/delete_response.json)" | ||
| fi | ||
| } | ||
|
|
||
| while true; do | ||
| sleep 30 | ||
| response=$(curl -s -o /dev/null -w "%{http_code}" --max-time 5 "http://127.0.0.1/geode/health") | ||
| echo "response ${response}" | ||
|
|
||
| if [ "$response" != "200" ]; then | ||
| delete_service | ||
| break | ||
| fi | ||
| done | ||
|
|
||
| echo "Health check loop ended." |
This file was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [program:cleanup] | ||
| command=bash /usr/local/bin/cleanup.bash | ||
| autostart=true | ||
| autorestart=true | ||
| stdout_logfile=/dev/stdout | ||
| stdout_logfile_maxbytes=0 | ||
| stderr_logfile=/dev/stderr | ||
| stderr_logfile_maxbytes=0 |
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [program:nginx] | ||
| command=nginx -g 'daemon off;' | ||
| autostart=true | ||
| autorestart=true | ||
| stdout_logfile=/dev/stdout | ||
| stdout_logfile_maxbytes=0 | ||
| stderr_logfile=/dev/stderr | ||
| stderr_logfile_maxbytes=0 |
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [supervisord] | ||
| nodaemon=true | ||
| logfile=/dev/stdout | ||
| logfile_maxbytes=0 | ||
| pidfile=/var/run/supervisord.pid | ||
|
|
||
| [include] | ||
| files = /etc/supervisor/conf.d/*.conf |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
Toujours utile ?
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.
oui lui c'est le maitre, celui qui lance supervisor