- Downgrade Go version from 1.25.1 to 1.24.0 in go.mod and Dockerfile to resolve build failure (Go 1.25 is not yet released). - Add `netcat-openbsd` to Dockerfile runtime image to ensure `nc` command is available for health checks. - Update `entrypoint.sh` to robustly wait for `stunnel` to start using `nc` loop, preventing app startup failure when DB TLS is enabled. - Add explicit error handling in `entrypoint.sh` if `stunnel` fails to start within timeout.
39 lines
935 B
Docker
39 lines
935 B
Docker
# ------------------------------
|
||
# Stage 1 — Build
|
||
# ------------------------------
|
||
FROM golang:1.24 AS builder
|
||
|
||
WORKDIR /src
|
||
|
||
# 先复制 go.mod / go.sum,使 Docker 构建缓存层可复用
|
||
COPY go.mod go.sum ./
|
||
RUN go mod download
|
||
|
||
# 再复制源码
|
||
COPY . .
|
||
|
||
# 编译
|
||
RUN CGO_ENABLED=0 go build -o account ./cmd/accountsvc/main.go
|
||
|
||
# ------------------------------
|
||
# Stage 2 — Runtime
|
||
# ------------------------------
|
||
FROM ubuntu:24.04
|
||
|
||
WORKDIR /app
|
||
|
||
RUN apt-get update \
|
||
&& apt-get install -y --no-install-recommends ca-certificates stunnel4 gettext-base netcat-openbsd \
|
||
&& rm -rf /var/lib/apt/lists/* \
|
||
&& mkdir -p /var/run/stunnel \
|
||
&& chown -R nobody:nogroup /var/run/stunnel
|
||
|
||
COPY --from=builder /src/account /usr/local/bin/account
|
||
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
||
COPY config /app/config
|
||
|
||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||
|
||
EXPOSE 8080
|
||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|