35 lines
1.1 KiB
Docker
35 lines
1.1 KiB
Docker
ARG NODE_BUILDER_IMAGE=docker.m.daocloud.io/library/node:22-alpine
|
|
ARG CADDY_BASE_IMAGE=docker.m.daocloud.io/library/caddy:2-alpine
|
|
ARG NPM_REGISTRY=https://registry.npmmirror.com
|
|
ARG ALPINE_MIRROR=https://mirrors.aliyun.com/alpine
|
|
|
|
FROM ${NODE_BUILDER_IMAGE} AS frontend-builder
|
|
|
|
ARG NPM_REGISTRY
|
|
|
|
WORKDIR /app/frontend
|
|
|
|
# 先安装依赖,利用 Docker 层缓存 / Install dependencies first for Docker cache
|
|
COPY frontend/package.json frontend/package-lock.json ./
|
|
RUN npm config set registry "${NPM_REGISTRY}" \
|
|
&& npm ci
|
|
|
|
COPY frontend ./
|
|
RUN npm run build
|
|
|
|
FROM ${CADDY_BASE_IMAGE}
|
|
|
|
ARG ALPINE_MIRROR
|
|
ENV TZ=Asia/Shanghai
|
|
RUN sed -i "s|https://dl-cdn.alpinelinux.org/alpine|${ALPINE_MIRROR}|g; s|http://dl-cdn.alpinelinux.org/alpine|${ALPINE_MIRROR}|g" /etc/apk/repositories \
|
|
&& apk --no-cache add tzdata \
|
|
&& ln -snf "/usr/share/zoneinfo/${TZ}" /etc/localtime \
|
|
&& echo "${TZ}" >/etc/timezone
|
|
|
|
COPY Caddyfile /etc/caddy/Caddyfile
|
|
COPY --from=frontend-builder /app/frontend/dist /usr/share/caddy
|
|
|
|
EXPOSE 80 443
|
|
|
|
CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
|