gw / Dockerfile
bl791's picture
Upload 2 files
71b648c verified
Raw
History Blame Contribute Delete
991 Bytes
FROM golang:1.22-bookworm
WORKDIR /app
ENV PORT=7860
ENV ADDR=:7860
ENV CGO_ENABLED=0
RUN cat <<'EOF' > /usr/local/bin/run-gateway
#!/bin/sh
set -eu
if [ -n "${PORT:-}" ]; then
export ADDR=":${PORT}"
fi
if [ -n "${GO_CODE_B64:-}" ]; then
printf '%s' "$GO_CODE_B64" | base64 -d > /app/main.go
elif [ -n "${GO_CODE:-}" ]; then
printf '%s' "$GO_CODE" > /app/main.go
else
echo "missing GO_CODE_B64 or GO_CODE" >&2
exit 2
fi
if [ -n "${GO_MOD_B64:-}" ]; then
printf '%s' "$GO_MOD_B64" | base64 -d > /app/go.mod
elif [ -n "${GO_MOD:-}" ]; then
printf '%s' "$GO_MOD" > /app/go.mod
elif [ ! -f /app/go.mod ]; then
cat > /app/go.mod <<'MOD'
module hf-space-gateway
go 1.22
MOD
fi
go mod tidy >/dev/null 2>&1 || {
echo "build failed" >&2
exit 2
}
go build -trimpath -ldflags="-s -w" -o /tmp/gateway . >/dev/null 2>&1 || {
echo "build failed" >&2
exit 2
}
exec /tmp/gateway
EOF
RUN chmod +x /usr/local/bin/run-gateway
EXPOSE 7860
CMD ["/usr/local/bin/run-gateway"]