fuliai commited on
Commit
51a147c
·
verified ·
1 Parent(s): 3a9b786

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +46 -34
Dockerfile CHANGED
@@ -1,36 +1,48 @@
1
- # 1. 选择基础镜像
2
- FROM ubuntu:22.04
3
-
4
- # 2. 设置维护者信息
5
- LABEL maintainer="[email protected]"
6
-
7
- # 3. 更新包管理器并安装依赖项
8
- RUN apt-get update && apt-get install -y \
9
- curl \
10
- git \
11
- build-essential
12
-
13
- # 4. 安装Node.js 20
14
- RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
15
- && apt-get install -y nodejs
16
-
17
- # 5. 安装yarn
18
- RUN npm install -g yarn
19
-
20
- # 6. 克隆Electerm项目仓库
21
- RUN git clone https://github.com/electerm/electerm.git /opt/electerm
22
-
23
- # 7. 设置工作目录
24
- WORKDIR /opt/electerm
25
-
26
- # 8. 安装项目依赖
27
- RUN yarn install
28
-
29
- # 9. 构建项目
30
- RUN yarn run prepare-build
31
-
32
- # 10. 暴露端口7860
 
 
 
 
 
 
 
 
 
 
 
 
33
  EXPOSE 7860
34
 
35
- # 11. 启动Electerm
36
- CMD ["yarn", "start"]
 
1
+ # 使用基于 Ubuntu 的官方 Node.js 20 镜像
2
+ FROM node:20
3
+
4
+ # 定义构建时间参数
5
+ ARG BUILD_DATE
6
+ LABEL build-date=$BUILD_DATE
7
+ LABEL maintainer="ZHAO Xudong <zxdong@gmail.com>"
8
+ LABEL description="This is Docker image for electerm-web"
9
+ LABEL url="https://github.com/electerm/electerm-web-docker"
10
+ LABEL vendor="electerm"
11
+ LABEL version="2.39.109"
12
+
13
+ # 安装构建工具,创建用户并设置权限
14
+ RUN apt-get update && apt-get install -y git make build-essential g++ \
15
+ && groupadd -r electerm && useradd -r -g electerm -d /home/electerm -s /bin/bash electerm \
16
+ && mkdir /home/electerm && chown -R electerm:electerm /home/electerm && chmod 755 /home/electerm
17
+
18
+ # 设置工作目录并确保权限正确
19
+ USER electerm
20
+ WORKDIR /app
21
+ RUN git clone --depth 1 https://github.com/electerm/electerm-web.git
22
+
23
+ WORKDIR /app/electerm-web
24
+
25
+ # 安装依赖并构建项目
26
+ RUN npm uninstall @playwright/test chai playwright \
27
+ && npm install --production \
28
+ && npm run build \
29
+ && cp .sample.env .env \
30
+ && npm cache clean --force
31
+
32
+ # 切换回 root 用户以删除不再需要的包,并清理系统
33
+ USER root
34
+ RUN apt-get remove -y git make build-essential g++ \
35
+ && apt-get clean && rm -rf /var/lib/apt/lists/*
36
+
37
+ # 切换回 electerm 用户继续运行应用
38
+ USER electerm
39
+ WORKDIR /app/electerm-web
40
+
41
+ # 设置环境变量
42
+ ENV NODE_ENV=production
43
+
44
+ # 暴露必要的端口 (根据项目需求)
45
  EXPOSE 7860
46
 
47
+ # 运行应用
48
+ CMD ["node", "./src/app/app.js"]