Skip to content

Commit

Permalink
feat: 优化docker构建过程,减小镜像尺寸
Browse files Browse the repository at this point in the history
  • Loading branch information
lincenying committed Aug 15, 2024
1 parent 6086839 commit 75a23a1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
TAG=1.0.0
TAG=1.0.1
3 changes: 0 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
*/
"scss.lint.unknownAtRules": "ignore",

// Enable the flat config support
"eslint.experimental.useFlatConfig": true,

// Disable the default formatter
"editor.formatOnSave": false,

Expand Down
23 changes: 22 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ARG NODE_VERSION=node:18-alpine

# 生产环境镜像
FROM $NODE_VERSION AS production
FROM $NODE_VERSION AS dependency-base

# 安装 pnpm
RUN npm config set registry https://registry.npmmirror.com
Expand All @@ -20,6 +20,27 @@ RUN pnpm install --frozen-lockfile
# 编译项目
RUN pnpm build

# Stage 2: Production image
FROM $NODE_VERSION AS production

# Create app directory
WORKDIR /app

# Copy built assets from previous stage
COPY --from=dependency-base /app/dist /app/dist
COPY --from=dependency-base /app/public /app/public
COPY --from=dependency-base /app/views /app/views
COPY --from=dependency-base /app/package.json /app/package.json
COPY --from=dependency-base /app/pnpm-lock.yaml /app/pnpm-lock.yaml
COPY --from=dependency-base /app/.npmrc /app/.npmrc

RUN npm config set registry https://registry.npmmirror.com
RUN npm install -g pnpm

RUN pnpm install --only=prod

RUN pnpm store prune

# 设置环境变量
## 生产环境
ENV NODE_ENV=production
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ exports.SECRET_KEY = ''
install nodejs, MongoDB, And start the
```bash
# Install dependencies
pnpm
pnpm install & npx simple-git-hooks

# or
npm install
npm install & npx simple-git-hooks

# Start the API server
pnpm serve
Expand Down

0 comments on commit 75a23a1

Please sign in to comment.