Skip to content

Commit

Permalink
优化 Docker 镜像
Browse files Browse the repository at this point in the history
💩 改为使用 nginx 启动服务进一步压缩容器大小
  • Loading branch information
Stapxs committed Dec 11, 2024
1 parent cc1b48e commit b8515f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 35 deletions.
36 changes: 10 additions & 26 deletions .github/workflows/build-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
uses: actions/checkout@v4
with:
submodules: recursive
persist-credentials: false
# 初始化一些流程需要的环境变量
- name: Init Env
id: step_init
Expand All @@ -30,13 +29,13 @@ jobs:
name: 构建 Web 版本(根目录)
runs-on: ubuntu-latest
needs: init

steps:
# 拉取代码
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
persist-credentials: false
# 设置 Node.js 版本
- name: Load Node.js
uses: actions/setup-node@v4
Expand Down Expand Up @@ -70,31 +69,18 @@ jobs:
- build-root-web

steps:
# 拉取代码
# 拉取代码(不需要子模块,只是获取 dockerfile)
- name: Checkout
uses: actions/checkout@v4
# 下载上一步构建的结果
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
submodules: recursive
persist-credentials: false
# 设置 Node.js 版本
- name: Load Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
# 更新依赖
- name: Install
run: yarn
# 构建
- name: Build
run: yarn build
# 构建 starter
- name: Build Starter
run: |
cd ssqq.npx-web-quick-start
yarn
yarn build
cd ..
# 登录到 Docker Hub
name: ${{ needs.init.outputs.version }}-web
# 解压(不输出细节)
- name: Unzip
run: unzip -q Stapxs.QQ.Lite-${{ needs.init.outputs.version }}-web.zip
# 登录到 Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
Expand All @@ -118,7 +104,6 @@ jobs:
uses: actions/checkout@v4
with:
submodules: recursive
persist-credentials: false
# 设置 Node.js 版本
- name: Load Node.js
uses: actions/setup-node@v4
Expand Down Expand Up @@ -159,7 +144,6 @@ jobs:
uses: actions/checkout@v4
with:
submodules: recursive
persist-credentials: false
# 设置 Node.js 版本
- name: Load Node.js
uses: actions/setup-node@v4
Expand Down
17 changes: 8 additions & 9 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# 为了减小包大小,此 dockerfile 中不负责构建项目,只负责运行项目
# 确保在构建项目后再运行此 dockerfile
# ssqq quick start nginx dockerfile
# 请确保项目已经构建完成存在 dist 目录

FROM node:hydrogen-alpine
FROM nginx:alpine

COPY ssqq.npx-web-quick-start/bin /app/bin
COPY dist /app/dist
COPY ssqq.npx-web-quick-start/package.json /app/package.json
RUN rm -rf /usr/share/nginx/html/*
COPY dist /usr/share/nginx/html

WORKDIR /app
RUN yarn install
# 修改nginx配置文件,将端口改为8080,以免影响已有用户的配置
RUN sed -i 's/listen 80;/listen 8080;/' /etc/nginx/conf.d/default.conf

EXPOSE 8080
CMD node bin/index.js -- hostname=0.0.0.0 port=8080 skip-update
CMD ["nginx", "-g", "daemon off;"]

0 comments on commit b8515f3

Please sign in to comment.