Skip to content

Commit 2b036d3

Browse files
committed
test
1 parent 08ddc31 commit 2b036d3

6 files changed

Lines changed: 74 additions & 29 deletions

File tree

Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
FROM nginx:alpine
22

3-
RUN apk add python3 py3-pip supervisor
4-
RUN pip3 install --break-system-packages google-cloud-run
3+
RUN apk add curl jq supervisor
54

6-
COPY nginx.conf /etc/nginx/nginx.conf
75

8-
COPY supervisord.conf /etc/supervisord.conf
6+
COPY supervisor/supervisord.conf /etc/supervisord.conf
97
RUN mkdir -p /var/log/supervisor
8+
RUN mkdir -p /etc/supervisor/conf.d
109

11-
COPY cleanup_watcher.py /usr/local/bin/cleanup_watcher.py
12-
RUN chmod +x /usr/local/bin/cleanup_watcher.py
10+
COPY supervisor/conf.d /etc/supervisor/conf.d
11+
12+
COPY cleanup.bash /usr/local/bin/cleanup.bash
13+
RUN chmod +x /usr/local/bin/cleanup.bash
1314

1415
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]

cleanup.bash

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
set -uo pipefail
3+
4+
PARENT="${PARENT:?PARENT env var required}"
5+
SERVICE_NAME="${K_SERVICE:?K_SERVICE env var required}"
6+
7+
delete_service() {
8+
echo "Flask appears down → Deleting service ${PARENT}/services/${SERVICE_NAME}"
9+
10+
# Get an OAuth2 access token from the GCE/Cloud Run metadata server
11+
local token
12+
token=$(curl -s -H "Metadata-Flavor: Google" \
13+
"http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" \
14+
| jq -r .access_token)
15+
16+
if [ -z "$token" ]; then
17+
echo "Delete failed: could not obtain access token"
18+
return 1
19+
fi
20+
21+
local http_code
22+
http_code=$(curl -s -o /tmp/delete_response.json -w "%{http_code}" \
23+
-X DELETE \
24+
-H "Authorization: Bearer ${token}" \
25+
"https://run.googleapis.com/v2/${PARENT}/services/${SERVICE_NAME}")
26+
27+
if [[ "$http_code" == 2* ]]; then
28+
echo "Service deletion request accepted (HTTP ${http_code})"
29+
else
30+
echo "Delete failed (HTTP ${http_code}): $(cat /tmp/delete_response.json)"
31+
fi
32+
}
33+
34+
while true; do
35+
sleep 30
36+
response=$(curl -s -o /dev/null -w "%{http_code}" --max-time 5 "http://127.0.0.1/geode/health")
37+
echo "response ${response}"
38+
39+
if [ "$response" != "200" ]; then
40+
delete_service
41+
break
42+
fi
43+
done

supervisor/conf.d/cleanup.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[program:cleanup-watcher]
2+
command=bash /usr/local/bin/cleanup.bash
3+
autostart=true
4+
autorestart=true
5+
stdout_logfile=/dev/stdout
6+
stdout_logfile_maxbytes=0
7+
stderr_logfile=/dev/stderr
8+
stderr_logfile_maxbytes=0

supervisor/conf.d/nginx.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[program:nginx]
2+
command=nginx -g 'daemon off;'
3+
autostart=true
4+
autorestart=true
5+
stdout_logfile=/dev/stdout
6+
stdout_logfile_maxbytes=0
7+
stderr_logfile=/dev/stderr
8+
stderr_logfile_maxbytes=0

supervisor/supervisord.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[supervisord]
2+
nodaemon=true
3+
logfile=/dev/stdout
4+
logfile_maxbytes=0
5+
pidfile=/var/run/supervisord.pid
6+
7+
[include]
8+
files = /etc/supervisor/conf.d/*.conf

supervisord.conf

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)