ultimate docker solution

This commit is contained in:
Alireza Ahmadi
2024-04-18 22:34:38 +02:00
parent c1c05c4863
commit 3d263d500f
10 changed files with 156 additions and 13 deletions
+28
View File
@@ -0,0 +1,28 @@
FROM --platform=$BUILDPLATFORM golang:1.22-alpine AS singbox-builder
LABEL maintainer="Alireza <alireza7@gmail.com>"
WORKDIR /app
ARG TARGETOS TARGETARCH
ARG SINGBOX_VER=v1.8.10
ARG SINGBOX_TAGS="with_quic,with_grpc,with_wireguard,with_ech,with_utls,with_reality_server,with_acme,with_v2ray_api,with_clash_api,with_gvisor"
ARG GOPROXY=""
ENV GOPROXY ${GOPROXY}
ENV CGO_ENABLED=0
ENV GOOS=$TARGETOS
ENV GOARCH=$TARGETARCH
RUN apk --no-cache --update add build-base gcc wget unzip git
RUN set -ex \
&& git clone --depth 1 --branch $SINGBOX_VER https://github.com/SagerNet/sing-box.git \
&& cd sing-box \
&& go build -v -trimpath -tags \
$SINGBOX_TAGS \
-ldflags "-X \"github.com/sagernet/sing-box/constant.Version=$SINGBOX_VER\" -s -w -buildid=" \
./cmd/sing-box
FROM --platform=$BUILDPLATFORM alpine
LABEL maintainer="Alireza <alireza7@gmail.com>"
ENV TZ=Asia/Tehran
WORKDIR /app
RUN apk add --no-cache --update ca-certificates tzdata bash
COPY --from=singbox-builder /app/sing-box/sing-box .
COPY runSingbox.sh .
ENTRYPOINT [ "./runSingbox.sh" ]
+45
View File
@@ -0,0 +1,45 @@
#!/bin/bash
set -e
tokill=$$
runSingbox(){
./sing-box run &
tokill=$!
}
terminateSingbox()
{
if kill -0 $tokill > /dev/null 2>&1; then
echo "Terminating singbox PID=$tokill"
kill $tokill
while kill -0 $tokill > /dev/null 2>&1; do
sleep 1
done
fi
}
trap terminateSingbox SIGINT SIGTERM SIGKILL
runSingbox
while true
do
sleep 5
if [ -f "signal" ]; then
signal=`cat signal`
echo "Signal received: $signal"
# Remove singnal file
rm -f signal >> /dev/null 2>&1
case ${signal} in
"stop")
terminateSingbox
;;
"restart")
terminateSingbox
runSingbox
;;
esac
fi
done