-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_docker_image.sh
More file actions
executable file
·89 lines (77 loc) · 1.75 KB
/
build_docker_image.sh
File metadata and controls
executable file
·89 lines (77 loc) · 1.75 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
# build docker images in alpine
# to use in alpine must with ldflags
NAME=app_blog # binary opt
ENTRY=app.go # go build entry
IMAGE=blog # docker image name
TAG=${tag} # docker tag try use export tag=vx.x
echo "start build blog binary"
echo "build tag is ${TAG}"
echo "output is ${NAME}"
if [[ -z $TAG ]];then
echo "you don't export blog tag"
exit 1
fi
go_exist=$(which go)
if [[ -z ${go_exist} ]];then
echo "go tools not exist"
exit 1
fi
# start build
export GO111MODULE=on
export CGO_ENABLED=1
go build -o ${NAME} --ldflags "-w -s -extldflags -static" -trimpath -tags="nomsgpack go_json" ${ENTRY}
if [[ $? != 0 ]];then
echo "build failed"
exit 1
fi
# start npm build
echo -n "if you want to build frontend file into docker? [Y/N]"
read arg
# default build html
if [[ $arg == "n" || $arg == "N" ]];then
echo "skip build frontend file"
else
echo "build total frontend file"
echo "file will be build into /app/html"
echo "your app.ini should set try_file: /app/html/index.html"
cd html && npm install && npm run build
if [[ $? != 0 ]];then
echo "npm build failed"
exit 1
fi
if [[ -d ../dist ]];then
rm -rf ../dist
fi
echo "start to mv dist"
mv dist ../dist
# exit current dir
cd ..
fi
echo "start build docker image"
if [[ ! -f Dockerfile ]];then
echo "Dockerfile not exist"
exit 1
fi
docker_exist=$(which docker)
if [[ -z ${docker_exist} ]];then
echo "docker not exist"
exit 1
fi
# start build docker image
# default use alpine:latest
if [[ ! -d ./dist ]];then
mkdir dist
touch dist/frontend_file.txt
fi
docker build -t ${IMAGE}:${TAG} .
# clean
echo "clean build file"
if [[ -f ./$NAME ]];then
echo "delete $NAME"
rm -f ./$NAME
fi
if [[ -d ./dist ]];then
echo "delete dist"
rm -rf ./dist
fi