Spaces:
Running
Running
OpenCode Bot commited on
Commit ·
75ad4b4
1
Parent(s): acd83e3
Build new-api with SMTP timeout patch
Browse filesFiles changed (3)
- Dockerfile+45-6
- README.md+2
- email.go.patchAdded+54
1234567891011121314FROM calciumion/new-api:latestENV PORT=7860 \TZ=Asia/Shanghai \ERROR_LOG_ENABLED=true \BATCH_UPDATE_ENABLED=true \NODE_NAME=hf-new-apiEXPOSE 7860RUN mkdir -p /dataWORKDIR /dataCMD ["sh", "-c", "echo SQL_DSN configured: ${SQL_DSN:+yes}; echo SESSION_SECRET configured: ${SESSION_SECRET:+yes}; exec /new-api"]1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253FROM alpine/git:2.51.2 AS sourceWORKDIR /srcRUN git clone --depth 1 https://github.com/QuantumNous/new-api.git .FROM oven/bun:1@sha256:0733e50325078969732ebe3b15ce4c4be5082f18c4ac1a0f0ca4839c2e4e42a7 AS builderWORKDIR /build/webCOPY --from=source /src/web/package.json /src/web/bun.lock ./COPY --from=source /src/web/default/package.json ./default/package.jsonCOPY --from=source /src/web/classic/package.json ./classic/package.jsonRUN bun install --frozen-lockfileCOPY --from=source /src/web/default ./defaultCOPY --from=source /src/VERSION /build/VERSIONRUN cd default && DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$(cat /build/VERSION) bun run buildFROM oven/bun:1@sha256:0733e50325078969732ebe3b15ce4c4be5082f18c4ac1a0f0ca4839c2e4e42a7 AS builder-classicWORKDIR /build/webCOPY --from=source /src/web/package.json /src/web/bun.lock ./COPY --from=source /src/web/default/package.json ./default/package.jsonCOPY --from=source /src/web/classic/package.json ./classic/package.jsonRUN bun install --filter ./classic --frozen-lockfileCOPY --from=source /src/web/classic ./classicCOPY --from=source /src/VERSION /build/VERSIONRUN cd classic && VITE_REACT_APP_VERSION=$(cat /build/VERSION) bun run buildFROM golang:1.26.1-alpine@sha256:2389ebfa5b7f43eeafbd6be0c3700cc46690ef842ad962f6c5bd6be49ed82039 AS builder-goENV GO111MODULE=on CGO_ENABLED=0 GOEXPERIMENT=greenteagcARG TARGETOSARG TARGETARCHENV GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64}WORKDIR /buildCOPY --from=source /src .COPY email.go.patch /tmp/email.go.patchRUN patch -p0 < /tmp/email.go.patchRUN go mod downloadCOPY --from=builder /build/web/default/dist ./web/default/distCOPY --from=builder-classic /build/web/classic/dist ./web/classic/distRUN go build -ldflags "-s -w -X 'github.com/QuantumNous/new-api/common.Version=$(cat VERSION)'" -o new-apiFROM debian:bookworm-slim@sha256:f06537653ac770703bc45b4b113475bd402f451e85223f0f2837acbf89ab020aRUN apt-get update \&& apt-get install -y --no-install-recommends ca-certificates tzdata libasan8 wget \&& rm -rf /var/lib/apt/lists/* \&& update-ca-certificatesCOPY --from=builder-go /build/new-api /COPY --from=source /src/LICENSE /src/NOTICE /src/THIRD-PARTY-LICENSES.md /licenses/ENV PORT=7860 \TZ=Asia/Shanghai \ERROR_LOG_ENABLED=true \BATCH_UPDATE_ENABLED=true \NODE_NAME=hf-new-apiEXPOSE 7860WORKDIR /dataENTRYPOINT ["/new-api"]
12 unmodified lines13141512 unmodified linesDocker deployment for [QuantumNous/new-api](https://github.com/QuantumNous/new-api).Runtime configuration is provided through Hugging Face Space secrets and variables.12 unmodified lines131415161712 unmodified linesDocker deployment for [QuantumNous/new-api](https://github.com/QuantumNous/new-api).Runtime configuration is provided through Hugging Face Space secrets and variables.This Space builds New API from upstream source and applies a small SMTP timeout patch so email verification fails quickly instead of hanging indefinitely when SMTP is unreachable.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354--- common/email.go+++ common/email.go@@ import ( "crypto/tls" "encoding/base64" "fmt"+ "net" "net/smtp" "slices" "strings" "time" )++const smtpTimeout = 10 * time.Second++type timeoutConn struct {+ net.Conn+}++func (c *timeoutConn) Read(b []byte) (int, error) {+ _ = c.Conn.SetDeadline(time.Now().Add(smtpTimeout))+ return c.Conn.Read(b)+}++func (c *timeoutConn) Write(b []byte) (int, error) {+ _ = c.Conn.SetDeadline(time.Now().Add(smtpTimeout))+ return c.Conn.Write(b)+}@@ func newSMTPClient(addr string) (*smtp.Client, error) {+ dialer := &net.Dialer{Timeout: smtpTimeout} if SMTPSSLEnabled || (SMTPPort == 465 && !SMTPStartTLSEnabled) {- conn, err := tls.Dial("tcp", addr, smtpTLSConfig())+ conn, err := tls.DialWithDialer(dialer, "tcp", addr, smtpTLSConfig()) if err != nil { return nil, err }- client, err := smtp.NewClient(conn, SMTPServer)+ client, err := smtp.NewClient(&timeoutConn{Conn: conn}, SMTPServer) if err != nil { _ = conn.Close() return nil, err@@- client, err := smtp.Dial(addr)+ conn, err := dialer.Dial("tcp", addr)+ if err != nil {+ return nil, err+ }+ client, err := smtp.NewClient(&timeoutConn{Conn: conn}, SMTPServer) if err != nil {+ _ = conn.Close() return nil, err }Dockerfile+45-6
README.md+2
email.go.patchAdded+54