Skip to content

Commit f4299af

Browse files
authored
Merge pull request #204 from keveinliu/image-tool
[feat] Sidecar image tool
2 parents ac40805 + 7df3e72 commit f4299af

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ RUN rm -fr pipy/build \
5252
FROM alpine:3.16.1 as prod
5353
COPY --from=builder /pipy/bin/pipy /usr/local/bin/pipy
5454
COPY --from=builder /pipy/tutorial /etc/pipy/tutorial
55+
COPY tools/* /usr/local/bin/
5556
RUN apk add --no-cache ca-certificates libstdc++ libcap su-exec tar curl busybox-extras iptables tzdata socat logrotate
5657
RUN adduser -Su 1340 pipy \
5758
&& chmod -R g=u /usr/local/bin/pipy /etc/pipy \

Dockerfile-loongnix

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ FROM cr.loongnix.cn/loongson/loongnix-server:8.3 as prod
5252
COPY --from=builder /pipy/bin/pipy /usr/local/bin/pipy
5353
COPY --from=builder /pipy/tutorial /etc/pipy
5454
COPY --from=builder /usr/bin/su-exec /usr/bin/su-exec
55+
COPY tools/* /usr/local/bin/
5556
RUN yum install -y --quiet ca-certificates libstdc++ libcap tar curl iptables tzdata socat logrotate
5657
RUN useradd -ru 1340 pipy \
5758
&& chmod -R g=u /usr/local/bin/pipy /etc/pipy \

tools/gkill

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env sh
2+
3+
#Gracefully kill sidecar.
4+
#Pipy won't accept new connections when receiving SIGINT signal
5+
#And quit after all connections are closed.
6+
7+
kill -SIGINT 1

tools/wait-pipy

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env sh
2+
3+
# Default values
4+
DEFAULT_URL="http://127.0.0.1:15000/config_dump"
5+
DEFAULT_REQ_TMOUT=1 # Single request timeout in seconds
6+
DEFAULT_INTERVAL=1 # Interval between requests in seconds
7+
DEFAULT_TIMEOUT=60 # Total timeout in seconds
8+
9+
# Display usage
10+
usage() {
11+
echo "Usage: $0 [options]"
12+
echo "Options:"
13+
echo " -u, --url URL URL to check (default: $DEFAULT_URL)"
14+
echo " -r, --req-tmout SEC Single request timeout in seconds (default: $DEFAULT_REQ_TMOUT)"
15+
echo " -i, --interval SEC Interval between requests in seconds (default: $DEFAULT_INTERVAL)"
16+
echo " -t, --timeout SEC Total timeout in seconds (default: $DEFAULT_TIMEOUT)"
17+
echo " -h, --help Show this help message"
18+
}
19+
20+
# Initialize variables with default values
21+
URL=$DEFAULT_URL
22+
REQ_TMOUT=$DEFAULT_REQ_TMOUT
23+
INTERVAL=$DEFAULT_INTERVAL
24+
TIMEOUT=$DEFAULT_TIMEOUT
25+
26+
# Parse command line arguments
27+
while [[ $# -gt 0 ]]; do
28+
case $1 in
29+
-u|--url)
30+
URL="$2"
31+
shift 2
32+
;;
33+
-r|--req-tmout)
34+
REQ_TMOUT="$2"
35+
shift 2
36+
;;
37+
-i|--interval)
38+
INTERVAL="$2"
39+
shift 2
40+
;;
41+
-t|--timeout)
42+
TIMEOUT="$2"
43+
shift 2
44+
;;
45+
-h|--help)
46+
usage
47+
exit 0
48+
;;
49+
*)
50+
echo "Unknown parameter: $1"
51+
usage
52+
exit 1
53+
;;
54+
esac
55+
done
56+
57+
# Calculate start time
58+
start_time=$(date +%s)
59+
60+
echo "Starting HTTP service check..."
61+
echo "URL: $URL"
62+
echo "Single request timeout (REQ_TMOUT): $REQ_TMOUT seconds"
63+
echo "Request interval (INTERVAL): $INTERVAL seconds"
64+
echo "Total timeout (TIMEOUT): $TIMEOUT seconds"
65+
66+
while true; do
67+
# Check if total timeout is exceeded
68+
current_time=$(date +%s)
69+
elapsed=$((current_time - start_time))
70+
71+
if [ $elapsed -ge $TIMEOUT ]; then
72+
echo "Total timeout of $TIMEOUT seconds reached. Service check failed!"
73+
exit 1
74+
fi
75+
76+
# Send HTTP request
77+
response=$(curl -s -o /dev/null -w "%{http_code}" \
78+
--connect-timeout $REQ_TMOUT \
79+
--max-time $REQ_TMOUT \
80+
"$URL" 2>/dev/null)
81+
82+
if [ "$response" = "200" ]; then
83+
echo "HTTP service is ready!"
84+
echo "Total time elapsed: $elapsed seconds"
85+
exit 0
86+
else
87+
echo "Service not ready, HTTP status code: $response"
88+
echo "Time elapsed: $elapsed seconds, timeout: $TIMEOUT seconds"
89+
echo "Waiting $INTERVAL seconds before next attempt..."
90+
sleep $INTERVAL
91+
fi
92+
done
93+

0 commit comments

Comments
 (0)