-
Notifications
You must be signed in to change notification settings - Fork 76
/
builder.bash
executable file
·186 lines (135 loc) · 4.91 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/sh
set -e
REPO_DIR=`pwd`
APP_VERSION=$(cat gradle.properties | grep -oP 'version=\K(.+)')
export VERSION=${APP_VERSION}
echo "> builder.bash version=${APP_VERSION}, path=${REPO_DIR}"
generateDocs(){
echo "> Generating docs version=${1}, target=${2}"
mkdir -p "${2}"
hugo --baseURL=http://mageddo.github.io/dns-proxy-server/$1 \
--destination $2 \
--ignoreCache --source docs/
echo "> Generated docs version=$1, out files:"
ls -lhS $2
}
copyFileFromService(){
serviceName=$1
from=$2
to=$3
docker-compose down
id=$(docker-compose up --no-start --force-recreate $serviceName 2>&1 | grep Container | awk '{print $2}' | head -1)
echo "> copy from service=${serviceName}, id=${id}, from=${from}, to=${to}"
docker cp "$id:$from" "$to"
}
case $1 in
copy-from-docker-service )
service=$2
from=$3
to=$4
copyFileFromService ${service} ${from} ${to}
;;
build-frontend )
tmpDir=$(mktemp -d)
echo "> Building frontend files... tmpDir=${tmpDir}"
docker-compose build --no-cache --progress=plain build-frontend
copyFileFromService build-frontend /static ${tmpDir}
tgzPath=./src/main/resources/META-INF/resources/static.tgz
mkdir -p $(dirname ${tgzPath})
rm -vf ${tgzPath}
tar -czvf ${tgzPath} -C ${tmpDir} .
;;
build-backend )
OS=linux
ARCH=$2
BUILD_SERVICE_NAME="build-${OS}-${ARCH}"
IMAGE_SERVICE_NAME="image-${OS}-${ARCH}"
ARTIFACTS_DIR="${REPO_DIR}/build/artifacts"
echo "> Building backend to: os=${OS}, arch=${ARCH}"
mkdir -p ${ARTIFACTS_DIR}
docker-compose build --no-cache --progress=plain ${BUILD_SERVICE_NAME}
tmpDir=$(mktemp -d)
echo "> Copying artifacts to ${tmpDir}..."
copyFileFromService ${BUILD_SERVICE_NAME} /app/build/artifacts $tmpDir
mv -v ${tmpDir}/artifacts/* ${ARTIFACTS_DIR}
echo "> Building image ${IMAGE_SERVICE_NAME} ..."
docker-compose build --no-cache --progress=plain "${IMAGE_SERVICE_NAME}"
echo "> Backend build done ${IMAGE_SERVICE_NAME}"
;;
compress-artifacts )
echo "> compress the files ..."
ARTIFACTS_DIR="${REPO_DIR}/build/artifacts"
COMPRESSED_ARTIFACTS_DIR="${REPO_DIR}/build/compressed-artifacts"
mkdir -p ${COMPRESSED_ARTIFACTS_DIR}
cd ${ARTIFACTS_DIR}
ls ${ARTIFACTS_DIR} | grep -v "native-image-source" |\
while read -r artPath ; do
tgz="${COMPRESSED_ARTIFACTS_DIR}/dns-proxy-server-${artPath}-${APP_VERSION}.tgz"
tar -czvf ${tgz} -C ${artPath} .
echo "> compressed ${artPath} to ${tgz} ..."
done
echo "> done! files compressed to ${COMPRESSED_ARTIFACTS_DIR}"
ls -lhS ${COMPRESSED_ARTIFACTS_DIR}
;;
docker-push )
echo "> Push docker images to docker hub"
docker tag defreitas/dns-proxy-server:${APP_VERSION} defreitas/dns-proxy-server:nightly &&\
docker tag defreitas/dns-proxy-server:${APP_VERSION} defreitas/dns-proxy-server:unstable &&\
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin &&\
docker-compose push image-linux-amd64 &&\
docker push defreitas/dns-proxy-server:nightly &&\
docker push defreitas/dns-proxy-server:unstable
echo "Push done"
;;
docker-push-arm )
echo "> Push docker images to docker hub"
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin &&\
docker-compose push image-linux-aarch64
echo "Push done"
;;
deploy )
echo "> Deploy started , current branch=$CURRENT_BRANCH"
rm -vrf build
ls -lhS
./builder.bash build-frontend
# also builds the jar
./builder.bash build-backend amd64
./builder.bash compress-artifacts
./builder.bash docker-push
echo "> deploy done"
;;
deploy-arm )
echo "> Arm deploy started , current branch=$CURRENT_BRANCH"
ls -lhS build/*
./builder.bash build-backend aarch64
./builder.bash compress-artifacts
./builder.bash docker-push-arm
echo "> arm deploy done"
;;
deploy-docs )
echo "> Docs build"
P="${REPO_DIR}/build/hugo"
echo "> Generating in ${P} ..."
MINOR_VERSION=$(echo $APP_VERSION | awk -F '.' '{ print $1"."$2}');
rm -r "${P}/docs" || echo "> build dir already clear"
# Generate link for generated docs versions
versionsFile=docs/content/versions/_index.en.md
{ git ls-tree origin/gh-pages | grep -E -o '[0-9]+\.[0-9]+'; echo "${MINOR_VERSION}"; } |\
sort -V -r |\
while read -r v; do echo "* [${v}](http://mageddo.github.io/dns-proxy-server/${v})"; done |\
cat >> $versionsFile
TARGET="${P}/docs/${MINOR_VERSION}"
generateDocs ${MINOR_VERSION} ${TARGET}
LATEST_VERSION=latest
TARGET_LATEST="${P}/docs/${LATEST_VERSION}"
generateDocs ${LATEST_VERSION} ${TARGET_LATEST}
echo "> Preparing new files ..."
git checkout -f gh-pages
rsync -t --info=ALL4 --recursive ${P}/docs/ ./
git status
echo "> Uploading ..."
git add ${LATEST_VERSION} ${MINOR_VERSION}
git commit -m "${MINOR_VERSION} docs"
git push origin gh-pages
;;
esac