-
Notifications
You must be signed in to change notification settings - Fork 9
/
dev.bash
executable file
·70 lines (60 loc) · 1.96 KB
/
dev.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
BaseImage=node:16-alpine
ZhBlogsImage=ohyee/zhblogs
DockerImage=ghcr.io/zh-blogs/zhblogs
function func_run_docker() {
docker run \
-p 3000:3000 \
--rm \
-it \
-v $(pwd):/data \
--workdir /data \
${BaseImage} \
$@
}
function func_build_image() {
if [[ "$(git status | grep 'nothing to commit' | wc -l)" -eq "1" ]]; then
Commit=$(git rev-parse --short HEAD)
echo $Commit
docker build -t ${ZhBlogsImage}:${Commit} .
echo "镜像: ${ZhBlogsImage}:${Commit}"
backendLatest="$(echo $backendImage | cut -d ":" -f 1):latest"
else
echo "存在未提交的更改,请提交后再构建镜像"
fi
}
function func_push_image() {
Commit=$(git rev-parse --short HEAD)
echo "最新版本: ${Commit}"
docker tag ${ZhBlogsImage}:${Commit} ${ZhBlogsImage}:latest
docker push ${ZhBlogsImage}:${Commit}
docker push ${ZhBlogsImage}:latest
docker tag ${ZhBlogsImage}:${Commit} ${DockerImage}:${Commit}
docker tag ${ZhBlogsImage}:${Commit} ${DockerImage}:latest
docker push ${DockerImage}:${Commit}
docker push ${DockerImage}:latest
}
function func_help() {
echo "$0 zhblogs 开发环境"
echo " pull 拉取镜像到本地"
echo " install 安装依赖到本地"
echo " dev 进入开发模式"
echo " lint 格式化"
echo " test 执行测试"
echo " build 构建生产环境镜像"
echo " push 推送镜像"
}
if [ $# -eq "0" ]; then
func_help
else
case $1 in
"pull") docker pull ${BaseImage};;
"install") func_run_docker yarn install --frozen-lockfile;;
"dev") func_run_docker yarn dev;;
"lint") func_run_docker yarn lint;;
"test") func_run_docker yarn mocha;;
"build") func_build_image;;
"push") func_push_image;;
*) func_help ;;
esac
fi