build(docker): 重构 Dockerfile 并简化 CI 流程
- 重构 Dockerfile,使用多阶段构建以减小最终镜像大小 - 更新 .drone.yml,使用单一步骤完成构建和推送 - 移除不必要的依赖和配置,简化构建过程 - 设置生产环境变量和端口
This commit is contained in:
parent
d42c83c9e9
commit
29da78dcca
17
.drone.yml
17
.drone.yml
@ -3,19 +3,22 @@ type: docker
|
|||||||
name: default
|
name: default
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build-and-push
|
- name: build
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
repo: your-registry/automated-api
|
dockerfile: Dockerfile
|
||||||
|
dry_run: true
|
||||||
|
repo: automated-api
|
||||||
tags:
|
tags:
|
||||||
- latest
|
- latest
|
||||||
- ${DRONE_COMMIT_SHA:0:8}
|
|
||||||
registry: your-registry
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
branch:
|
branch:
|
||||||
- main
|
- dev-2.0.0
|
||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: docker
|
||||||
|
host:
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
# 构建阶段
|
# 构建阶段
|
||||||
FROM node:18-alpine as builder
|
FROM node:18-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY package.json .
|
COPY package.json .
|
||||||
COPY package-lock.json* .
|
COPY package-lock.json* .
|
||||||
|
|
||||||
RUN npm install
|
RUN npm config set registry https://registry.npmmirror.com/ && \
|
||||||
|
npm install
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
@ -21,7 +22,8 @@ COPY --from=builder /app/dist ./dist
|
|||||||
COPY --from=builder /app/package.json .
|
COPY --from=builder /app/package.json .
|
||||||
COPY --from=builder /app/bootstrap.js .
|
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 NODE_ENV=production
|
||||||
ENV PORT=8001
|
ENV PORT=8001
|
||||||
|
Loading…
Reference in New Issue
Block a user