使用docker构建前端项目
# docker-compose
docker-compose.yml
version: "3"
services:
puredoc:
image: node:14.18.1
container_name: puredoc
volumes:
- ./app:/app
working_dir: /app
command: >
bash -c '
if [ -d /app/.git ]; then
cd /app &&
git pull &&
yarn install &&
yarn build
else
git clone -b dev https://帐号:密码@gitlab.xxxx.cn/pure-doc.git /app &&
cd /app &&
yarn install &&
yarn build
fi &&
tail -f /dev/null
'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 说明
- "git clone -b dev"中 -b dev指的是拉取dev分支 可根据实际情况修改
- 容器启动后便一直在运行中,启动后可查看日志,等待日志输出构建完成后可手动关闭容器
- 首次启动会git clone代码,第二次启动会git pull代码。检测条件为[ -d /app/.git ]
# 操作命令
# 启动容器构建前端项目
docker-compose up -d
1
# 查看日志构建进度
docker logs -f puredoc
1
若日志输出如下,则说明已经构建完成
ℹ Compiling Client
ℹ Compiling Server
Language does not exist: @data
✔ Server: Compiled successfully in 34.50s
✔ Client: Compiled successfully in 40.62s
wait Rendering static HTML...
SITEMAP Generating sitemap...
SITEMAP found 61 locations
SITEMAP 61 locations have been written.
success Generated static files in docs/.vuepress/dist.
Done in 48.61s.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 关闭容器
docker-compose down
1
# 构建dist包目录
可根据日志输出得知构建完成的目录地址为
docs/.vuepress/dist.
1
由已经把docker目录地址映射出来,可在当前目录地址app下查看
上次更新: 2023/06/01, 03:48:34