From 29da78dcca3f5e74ea2e64d9b15a1d6381a0ab42 Mon Sep 17 00:00:00 2001 From: lixin Date: Fri, 10 Jan 2025 14:40:49 +0800 Subject: [PATCH] =?UTF-8?q?build(docker):=20=E9=87=8D=E6=9E=84=20Dockerfil?= =?UTF-8?q?e=20=E5=B9=B6=E7=AE=80=E5=8C=96=20CI=20=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构 Dockerfile,使用多阶段构建以减小最终镜像大小 - 更新 .drone.yml,使用单一步骤完成构建和推送 - 移除不必要的依赖和配置,简化构建过程 - 设置生产环境变量和端口 --- .drone.yml | 17 ++++++++++------- Dockerfile | 8 +++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.drone.yml b/.drone.yml index fbdece8..6698bca 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,19 +3,22 @@ type: docker name: default steps: - - name: build-and-push + - name: build image: plugins/docker settings: - repo: your-registry/automated-api + dockerfile: Dockerfile + dry_run: true + repo: automated-api tags: - latest - - ${DRONE_COMMIT_SHA:0:8} - registry: your-registry - - trigger: branch: - - main + - dev-2.0.0 event: - push + +volumes: + - name: docker + host: + path: /var/run/docker.sock diff --git a/Dockerfile b/Dockerfile index 35272e9..c27a19f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,13 @@ # 构建阶段 -FROM node:18-alpine as builder +FROM node:18-alpine AS builder WORKDIR /app COPY package.json . COPY package-lock.json* . -RUN npm install +RUN npm config set registry https://registry.npmmirror.com/ && \ + npm install COPY . . @@ -21,7 +22,8 @@ COPY --from=builder /app/dist ./dist COPY --from=builder /app/package.json . COPY --from=builder /app/bootstrap.js . -RUN npm install --production +RUN npm config set registry https://registry.npmmirror.com/ && \ + npm install --production ENV NODE_ENV=production ENV PORT=8001