Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cfdc5e5d9a | |||
| 745360f93f | |||
| 3b9ed0dcca | |||
| 0a8058b882 |
@ -15,4 +15,7 @@ dist
|
||||
.idea
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
*~
|
||||
bun.lock
|
||||
.git
|
||||
.gitea
|
||||
@ -12,6 +12,9 @@ jobs:
|
||||
- name: 释放内存
|
||||
run: docker system prune -a -f
|
||||
|
||||
- name: 设置 Docker Buildx
|
||||
run: docker buildx create --use
|
||||
|
||||
- name: 拉取自定义 checkout action
|
||||
run: git clone http://114.67.155.184:3000//niyyzf/checkout.git ./.actions/checkout
|
||||
|
||||
@ -23,7 +26,7 @@ jobs:
|
||||
max-attempts: 5
|
||||
|
||||
- name: 构建 Docker 镜像
|
||||
run: docker build -t watch-stock-list:latest .
|
||||
run: docker build --cache-from type=gha --cache-to type=gha,mode=max -t watch-stock-list:latest .
|
||||
|
||||
- name: 启动/重启服务(Docker Compose)
|
||||
run: |
|
||||
|
||||
19
Dockerfile
19
Dockerfile
@ -8,13 +8,10 @@ RUN apk add --no-cache libc6-compat
|
||||
WORKDIR /app
|
||||
|
||||
# 安装依赖
|
||||
COPY package.json bun.lock* package-lock.json* pnpm-lock.yaml* ./
|
||||
RUN \
|
||||
if [ -f bun.lockb ]; then bun install --frozen-lockfile; \
|
||||
elif [ -f package-lock.json ]; then npm ci; \
|
||||
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
|
||||
else echo "Lockfile not found." && exit 1; \
|
||||
fi
|
||||
COPY package.json ./
|
||||
# 使用 npm 缓存来加速构建
|
||||
RUN npm config set cache /tmp/npm-cache && \
|
||||
npm install --cache /tmp/npm-cache --prefer-offline --no-audit --no-fund
|
||||
|
||||
# 构建阶段
|
||||
FROM base AS builder
|
||||
@ -29,7 +26,7 @@ RUN npm run build
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV production
|
||||
ENV NODE_ENV=production
|
||||
# 在 Linux 上,需要明确设置用户
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 svelte
|
||||
@ -41,10 +38,10 @@ COPY --from=builder --chown=svelte:nodejs /app/package.json ./package.json
|
||||
|
||||
USER svelte
|
||||
|
||||
EXPOSE 3000
|
||||
EXPOSE 7799
|
||||
|
||||
ENV PORT 3000
|
||||
ENV HOSTNAME "0.0.0.0"
|
||||
ENV PORT=7799
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
|
||||
# 启动应用
|
||||
CMD ["node", "build"]
|
||||
25
build.sh
Normal file
25
build.sh
Normal file
@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 本地构建脚本 - 包含缓存优化
|
||||
set -e
|
||||
|
||||
echo "🚀 开始构建 Docker 镜像..."
|
||||
|
||||
# 清理旧镜像(可选)
|
||||
# docker system prune -f
|
||||
|
||||
# 使用 Buildx 和缓存构建
|
||||
docker buildx build \
|
||||
--cache-from type=local,src=/tmp/.buildx-cache \
|
||||
--cache-to type=local,dest=/tmp/.buildx-cache,mode=max \
|
||||
--tag watch-stock-list:latest \
|
||||
--load \
|
||||
.
|
||||
|
||||
echo "✅ 构建完成!"
|
||||
|
||||
# 启动容器(可选)
|
||||
echo "🐳 启动容器..."
|
||||
docker-compose up -d
|
||||
|
||||
echo "🎉 部署完成!应用运行在 http://localhost:7799"
|
||||
@ -4,14 +4,14 @@ services:
|
||||
image: watch-stock-list:latest
|
||||
container_name: watch-stock-list-app
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- "7799:7799"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- PORT=3000
|
||||
- PORT=7799
|
||||
- HOSTNAME=0.0.0.0
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:3000"]
|
||||
test: ["CMD", "curl", "-f", "http://localhost:7799"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
Reference in New Issue
Block a user