-
Notifications
You must be signed in to change notification settings - Fork 1
/
release.sh
executable file
·88 lines (67 loc) · 1.69 KB
/
release.sh
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
#!/bin/bash
set -xe
image_name="ex_domain"
trap 'clean_tmp; exit' QUIT TERM EXIT
function clean_tmp() {
echo "clean temporary file..."
[ -f Dockerfile.release ] && rm -rf Dockerfile.release
}
function release(){
release_name="master"
release_version="latest"
if [ "$release_name" == "master" ];then
branch_name=${release_name}
git checkout ${branch_name}
else
branch_name=${release_name}-${release_version}
git checkout ${branch_name}
fi
echo "Pull newest code..." && sleep 3
git pull origin master
# get commit sha
git_commit=$(git log -n 1 --pretty --format=%h)
# get git describe info
version=${release_version}-${git_commit}
sed "s/__VERSION__/$version/" Dockerfile >Dockerfile.release
docker build --no-cache -t projectdc/${image_name}:${release_name} -f Dockerfile.release .
}
function encode_release(){
release_name="dev"
release_version="latest"
if [ "$release_name" == "dev" ];then
branch_name=${release_name}
git checkout ${branch_name}
else
branch_name=${release_name}-${release_version}
git checkout ${branch_name}
fi
echo "Pull newest code..." && sleep 3
git pull origin dev
# get commit sha
git_commit=$(git log -n 1 --pretty --format=%h)
# get git describe info
version=${release_version}-${git_commit}
sed "s/__VERSION__/$version/" Dockerfile.encode >Dockerfile.release
cat > ./.gitignore <<EOF
.release/
release.sh
.idea/
.env/
__pycahche__/
*.pyc
ex_domain.py
Dockerfile
Dockerfile.release
EOF
docker build --no-cache -t projectdc/${image_name}:${release_name} -f Dockerfile.release .
}
case $1 in
encode)
encode_release
clean_tmp
;;
*)
release
clean_tmp
;;
esac