Files
website/Dockerfile
T

47 lines
1.5 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 开源项目门户(VitePress)构建镜像
#
# 构建参数:
# SITE_BASE —— 站点资源前缀,同时决定容器内 nginx 的形态:
# /www/ 过渡形态:挂在已有网关的 /www/ 路径下(没有独立域名时用)
# / 独立域名形态:站点独占域名根路径
#
# 前缀与 nginx 形态必须配套:VitePress 产物里的资源引用是绝对路径
# (<base>assets/xxx),base=/www/ 时只能由带 alias 的 location 提供服务;
# base=/ 时只能由根路径 location 提供服务。混用会出现「页面 200 但 JS/CSS 全 404」。
#
# 用法(仓库根目录):
# docker build -t snowgoat-open-portal:dev --build-arg SITE_BASE=/www/ .
FROM node:22-alpine AS builder
ARG SITE_BASE=/www/
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk add --no-cache git
WORKDIR /app
COPY package*.json .npmrc ./
RUN npm ci
COPY . .
RUN SITE_BASE=${SITE_BASE} npm run build
FROM nginx:1.27-alpine
ARG SITE_BASE=/www/
COPY --from=builder /app/.vitepress/dist /usr/share/nginx/html
COPY docker/nginx.root.conf /etc/nginx/conf.d/default.conf
COPY docker/nginx.prefix.conf /tmp/nginx.prefix.conf
RUN set -eu; \
base="${SITE_BASE%/}"; \
if [ "$base" = "" ]; then \
echo "门户形态:独立域名(根路径)"; \
else \
sed -e "s|__SITE_BASE__|${SITE_BASE}|g" -e "s|__SITE_BASE_NO_SLASH__|${base}|g" \
/tmp/nginx.prefix.conf > /etc/nginx/conf.d/default.conf; \
echo "门户形态:子路径 ${SITE_BASE}"; \
fi
EXPOSE 80