forked from mageddo/dns-proxy-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.bash
executable file
·142 lines (101 loc) · 3.05 KB
/
builder.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/sh
set -e
CUR_DIR=`pwd`
APP_VERSION=$(cat VERSION)
REPO_URL=mageddo/dns-proxy-server
assemble(){
echo "> Testing ..."
go test -p 1 -cover -ldflags "-X github.com/mageddo/dns-proxy-server/flags.version=test" ./.../
echo "> Tests completed"
echo "> Building..."
rm -rf build/
mkdir -p build/
cp -r /static build/
}
generateDocs(){
rm -r ${TARGET} || echo "not exists ${TARGET}"
hugo --baseURL=http://mageddo.github.io/dns-proxy-server/$1 \
--destination $2 \
--ignoreCache --source docs/
}
case $1 in
setup-repository )
git remote remove origin && git remote add origin https://${REPO_TOKEN}@github.com/$REPO_URL.git
git checkout -b build_branch ${CURRENT_BRANCH}
echo "> Repository added, travisBranch=${CURRENT_BRANCH}"
;;
upload-release )
DESC=$(cat RELEASE-NOTES.md | awk 'BEGIN {RS="|"} {print substr($0, 0, index(substr($0, 3), "###"))}' | sed ':a;N;$!ba;s/\n/\\r\\n/g')
github-cli release mageddo dns-proxy-server $APP_VERSION $CURRENT_BRANCH "${DESC}" $PWD/build/*.tgz
;;
docs )
VERSION=$(cat VERSION | awk -F '.' '{ print $1"."$2}');
TARGET=$PWD/../dns-proxy-server-docs/${VERSION}
generateDocs ${VERSION} ${TARGET}
VERSION=latest
TARGET=$PWD/../dns-proxy-server-docs/${VERSION}
generateDocs ${VERSION} ${TARGET}
;;
apply-version )
# updating files version
sed -i -E "s/(dns-proxy-server.*)[0-9]+\.[0-9]+\.[0-9]+/\1$APP_VERSION/" docker-compose.yml
sed -i -E "s/[0-9]+\.[0-9]+\.[0-9]+/$APP_VERSION/g" Dockerfile*.hub
;;
assemble )
assemble
;;
build )
assemble
if [ ! -z "$2" ]
then
builder.bash compile $2 $3
exit 0
fi
# ARM
builder.bash compile linux arm
builder.bash compile linux arm64
# LINUX
# INTEL / AMD
builder.bash compile linux 386
builder.bash compile linux amd64
echo "> Build success"
;;
compile )
export GOOS=$2
export GOARCH=$3
echo "> Compiling os=${GOOS}, arch=${GOARCH}"
go build -o $PWD/build/dns-proxy-server -ldflags "-X github.com/mageddo/dns-proxy-server/flags.version=$APP_VERSION"
TAR_FILE=dns-proxy-server-${GOOS}-${GOARCH}-${APP_VERSION}.tgz
cd $PWD/build/
tar --exclude=*.tgz -czf $TAR_FILE *
;;
validate-release )
if git rev-parse "$APP_VERSION^{}" >/dev/null 2>&1; then
echo "> Version already exists $APP_VERSION"
exit 3
fi
;;
deploy-ci )
EC=0
docker-compose up --force-recreate --abort-on-container-exit prod-ci-deploy || EC=$?
if [ "$EC" = "3" ]; then
exit 0
elif [ "$EC" -ne "0" ]; then
exit $EC
fi
docker-compose build prod-build-image-dps-arm7x86 prod-build-image-dps-arm8x64 &&\
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin &&\
docker-compose push prod-build-image-dps-arm7x86 prod-build-image-dps-arm8x64
;;
release )
echo "> build started, current branch=$CURRENT_BRANCH"
if [ "$CURRENT_BRANCH" = "master" ]; then
echo "> deploying new version"
builder.bash validate-release && builder.bash apply-version && builder.bash build && builder.bash upload-release
else
echo "> building candidate"
builder.bash validate-release
builder.bash build
fi
;;
esac