ci(docker): simplify Go builder pipeline and trim runtime images

This commit is contained in:
Haitao Pan 2025-12-04 22:57:12 +08:00
parent f6d3b82153
commit a6ee35499f
3 changed files with 20 additions and 28 deletions

View File

@ -17,9 +17,7 @@ RUN make build && make -pv /out/ && cp account /out/
# ------------------------------
# Stage 2 — Runtime
# ------------------------------
ARG GO_RUNTIME_IMAGE=ghcr.io/cloud-neutral-toolkit/go-runtime:latest
ARG INSTALL_GO=false # runtime 不安装 Go SDK
FROM ${GO_RUNTIME_IMAGE} AS runtime
FROM ubuntu:24.04 AS runtime
RUN apt-get update \
&& apt-get install -y --no-install-recommends \

View File

@ -16,7 +16,6 @@ LABEL maintainer="XControl" \
ENV CGO_ENABLED=0 \
TZ=Etc/UTC
ARG INSTALL_GO="false"
ARG GO_VERSION="1.24.5"
RUN set -eux; \
@ -29,30 +28,27 @@ RUN set -eux; \
rm -rf /var/lib/apt/lists/*
# =======================================================
# 可选:安装 Go SDK用于 make build 的情况
# 安装 Go SDK默认开启
# =======================================================
RUN if [ "$INSTALL_GO" = "true" ]; then \
set -eux; \
arch="$(uname -m)"; \
case "$arch" in \
x86_64|amd64) goarch="amd64" ;; \
aarch64|arm64) goarch="arm64" ;; \
*) echo "Unsupported arch: $arch"; exit 1 ;; \
esac; \
tarball="go${GO_VERSION}.linux-${goarch}.tar.gz"; \
url="https://go.dev/dl/${tarball}"; \
echo "Installing Go ${GO_VERSION} for ${goarch}"; \
wget -q "$url" -O "/tmp/go.tgz"; \
rm -rf /usr/local/go; \
tar -C /usr/local -xzf "/tmp/go.tgz"; \
rm /tmp/go.tgz; \
echo 'export PATH=$PATH:/usr/local/go/bin' > /etc/profile.d/go.sh; \
fi
RUN set -eux; \
arch="$(uname -m)"; \
case "$arch" in \
x86_64|amd64) goarch="amd64" ;; \
aarch64|arm64) goarch="arm64" ;; \
*) echo "Unsupported arch: $arch"; exit 1 ;; \
esac; \
tarball="go${GO_VERSION}.linux-${goarch}.tar.gz"; \
url="https://go.dev/dl/${tarball}"; \
echo "=== Installing Go ${GO_VERSION} (${goarch}) ==="; \
wget -q "$url" -O "/tmp/go.tgz"; \
rm -rf /usr/local/go; \
tar -C /usr/local -xzf "/tmp/go.tgz"; \
rm /tmp/go.tgz; \
echo 'export PATH=$PATH:/usr/local/go/bin' > /etc/profile.d/go.sh;
ENV PATH="${PATH}:/usr/local/go/bin"
# ---- 应用目录 ----
# ---- 应用构建目录builder 用) ----
WORKDIR /app
# ---- 默认 shell 入口(最终服务会覆盖 CMD ----
CMD ["/bin/sh"]

View File

@ -2,7 +2,7 @@
# Stage 1 — Builder
# =======================================================
ARG GO_RUNTIME_IMAGE=ghcr.io/cloud-neutral-toolkit/go-runtime:latest
ARG INSTALL_GO=true # 为 builder 启用 Go SDKgo-runtime.Dockerfile 会处理)
FROM ${GO_RUNTIME_IMAGE} AS builder
# 在 builder 中启用 Go SDK
@ -24,9 +24,7 @@ RUN make build && mkdir -p /out && cp rag-server /out/rag-server
# =======================================================
# Stage 2 — Runtime
# =======================================================
ARG GO_RUNTIME_IMAGE=ghcr.io/cloud-neutral-toolkit/go-runtime:latest
ARG INSTALL_GO=false # runtime 不安装 Go SDK
FROM ${GO_RUNTIME_IMAGE} AS runtime
FROM ubuntu:24.04 AS runtime
WORKDIR /app