forked from jitsucom/jitsu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release-tool.sh
executable file
·173 lines (146 loc) · 7.48 KB
/
release-tool.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
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
#!/usr/bin/env bash
SDK_VERSION=$(cat js-sdk-version)
# Highlights args with color
# Only red is supported so far
#
function chalk() {
local color=$1; shift
local color_code=0
if [[ $color == "red" ]]; then
color_code=1
elif [[ $color == "green" ]]; then
color_code=2
fi
echo -e "$(tput setaf $color_code)$*$(tput sgr0)"
}
function fail() {
local error="$*" || 'Unknown error'
echo "$(chalk red "${error}")" ; exit 1
}
function build_configurator() {
echo "Building Configurator UI locally.."
rm -f configurator/frontend/main/public/app-version.json
rm -f configurator/backend/build/dist/configurator && rm -rf configurator/frontend/main/build && \
cd configurator/frontend/ && pnpm clean && pnpm i && CI=false ANALYTICS_KEYS='{"eventnative": "js.gpon6lmpwquappfl07tuq.ka5sxhsm08cmblny72tevi", "sentry": "https://[email protected]/6365760"}' pnpm build && \
cd ../../ || fail 'Configurator build failed'
}
function release_server() {
docker login -u="$JITSU_DOCKER_LOGIN" -p="$JITSU_DOCKER_PASSWORD" || fail "Docker jitsu ($JITSU_DOCKER_LOGIN) login failed"
if [[ $1 =~ $SEMVER_EXPRESSION ]]; then
echo "**** Server amd64/arm64 release [$1] ****"
docker buildx build --platform linux/amd64,linux/arm64 --push -t jitsucom/server:"$1" -t jitsucom/server:latest -f server.Dockerfile --build-arg dhid=jitsucom --build-arg SDK_VERSION=$SDK_VERSION . || fail 'Server dockerx build semver failed'
docker login -u="$KSENSE_DOCKER_LOGIN" -p="$KSENSE_DOCKER_PASSWORD" || fail "Docker ksense login failed"
docker buildx build --platform linux/amd64 --push -t ksense/eventnative:"$1" -t ksense/eventnative:latest -f server.Dockerfile --build-arg dhid=ksense --build-arg SDK_VERSION=$SDK_VERSION . || fail 'ksense/eventnative dockerx build semver failed'
else
if [[ "$1" == "beta" ]]; then
echo "**** Server $2 release [$1] ****"
docker buildx build --platform $2 --push -t jitsucom/server:"$1" -f server.Dockerfile --build-arg dhid=jitsucom --build-arg SDK_VERSION=$SDK_VERSION . || fail 'Server dockerx build failed'
else
echo "**** Server $2 release [$1] ****"
docker buildx build --platform $2 --push -t jitsucom/server:"$1" -f server.Dockerfile --build-arg dhid=jitsucom --build-arg SDK_VERSION=$SDK_VERSION . || fail 'Server dockerx build failed'
fi
fi
}
function release_configurator() {
docker login -u="$JITSU_DOCKER_LOGIN" -p="$JITSU_DOCKER_PASSWORD" || fail 'Docker jitsu login failed'
if [[ $1 =~ $SEMVER_EXPRESSION ]]; then
echo "**** Configurator amd64/arm64 release [$1] ****"
docker buildx build --platform linux/amd64,linux/arm64 --push -t jitsucom/configurator:"$1" -t jitsucom/configurator:latest --build-arg dhid=jitsucom -f configurator-release.Dockerfile . || fail 'Configurator dockerx build semver failed'
else
if [[ "$1" == "beta" ]]; then
echo "**** Configurator $2 release [$1] ****"
docker buildx build --platform $2 --push -t jitsucom/configurator:"$1" --build-arg dhid=jitsucom -f configurator-release.Dockerfile . || fail 'Configurator dockerx build failed'
else
echo "**** Configurator $2 release [$1] ****"
docker buildx build --platform $2 --push -t jitsucom/configurator:"$1" --build-arg dhid=jitsucom -f configurator-release.Dockerfile . || fail 'Configurator dockerx build failed'
fi
fi
}
function release_jitsu() {
echo "**** Jitsu release [$1] ****"
docker login -u="$JITSU_DOCKER_LOGIN" -p="$JITSU_DOCKER_PASSWORD" || fail 'Docker jitsu login failed'
cd docker && \
docker pull jitsucom/configurator:"$1" && \
docker pull jitsucom/configurator:latest && \
docker pull jitsucom/server:"$1" && \
docker pull jitsucom/server:latest || fail 'Jitsu docker pull failed'
if [[ $1 =~ $SEMVER_EXPRESSION ]]; then
docker buildx build --platform linux/amd64,linux/arm64 --push -t jitsucom/jitsu:"$1" -t jitsucom/jitsu:latest --build-arg dhid=jitsu --build-arg SRC_VERSION=latest . || { echo 'Jitsu dockerx build semver failed' ; exit 1; }
else
if [[ "$1" == "beta" ]]; then
docker buildx build --platform $2 --push -t jitsucom/jitsu:"$1" --build-arg dhid=jitsu --build-arg SRC_VERSION="$1" . || { echo 'Jitsu dockerx build failed' ; exit 1; }
else
docker buildx build --platform $2 --push -t jitsucom/jitsu:"$1" --build-arg dhid=jitsu --build-arg SRC_VERSION="$1" . || { echo 'Jitsu dockerx build failed' ; exit 1; }
fi
fi
cd ../
}
SEMVER_EXPRESSION='^([0-9]+\.){0,2}(\*|[0-9]+)$'
echo "Release tool running..."
CURRENT_BRANCH=$(git branch --show-current)
echo "Fetching remote changes from git with git fetch"
git fetch origin "$CURRENT_BRANCH" > /dev/null 2>&1
echo "Running checks..."
git diff --shortstat --exit-code $CURRENT_BRANCH origin/$CURRENT_BRANCH > /dev/null 2>&1 || fail " ❌ Some changes are not pulled. Run git pull!"
echo " ✅ No incoming changes detected"
docker login -u="$JITSU_DOCKER_LOGIN" -p="$JITSU_DOCKER_PASSWORD" >/dev/null 2>&1|| fail ' ❌ Jitsu docker login failed. Make sure that JITSU_DOCKER_LOGIN and JITSU_DOCKER_PASSWORD are properly set'
echo " ✅ Can login with jitsu docker account"
docker login -u="$KSENSE_DOCKER_LOGIN" -p="$KSENSE_DOCKER_PASSWORD" >/dev/null 2>&1|| fail ' ❌ Ksense legacy docker account login failed. Make sure that KSENSE_DOCKER_LOGIN" and KSENSE_DOCKER_PASSWORD are properly set'
echo " ✅ Can login with ksense legacy docker account"
if [[ $CURRENT_BRANCH == "master" || $CURRENT_BRANCH == "beta" ]]; then
echo " ✅ Git branch is $CURRENT_BRANCH"
else
echo " ⚠️ Git branch $CURRENT_BRANCH is not master or beta."
fi
#git diff-index --quiet HEAD || fail " ❌ Repository has local changes. Run git diff. And commit them! (And sometimes this command fails due to cache try to re-run it)"
echo " ✅ No local changes"
[[ -z $(git cherry) ]] || fail " ❌ Not all changes are pushed. Please run git diff HEAD^ HEAD to see them"
echo " ✅ No unpushed changes"
platform="linux/amd64"
if [[ $TARGET_ARCH == "arm" ]]; then
platform="linux/arm64"
elif [[ $TARGET_ARCH == "both" ]]; then
platform="linux/amd64,linux/arm64"
fi
if [ $# -eq 2 ]; then
version=$1
subsystem=$2
else
subsystem="jitsu"
if [[ $( git branch --show-current) == "master" ]]; then
echo "Releasing master. Checking if HEAD is tagged"
git describe --tags --exact-match HEAD >/dev/null 2>&1 || fail " ❌ HEAD is not tagged. Run git describe --exact-match HEAD "
latest_tag=$(git describe --tags --exact-match HEAD)
version=${latest_tag//v/}
echo " ✅ Latest tag is $latest_tag, version is $version"
elif [[ $( git branch --show-current) == "beta" ]]; then
echo "Releasing beta. Target platform: $platform"
version='beta'
else
echo "Releasing custom branch: $( git branch --show-current) Target platform: $platform"
while [ -z "$version" ]; do
read -r -p "Please provide docker image tag for the custom branch release: " version
done
fi
fi
chalk green "=== Release version: $version ==="
chalk green "=== Release subsystem: $subsystem ==="
case $subsystem in
[s][e][r][v][e][r])
release_server $version $platform
;;
[c][o][n][f][i][g][u][r][a][t][o][r])
build_configurator
release_configurator $version $platform
;;
[j][i][t][s][u])
build_configurator
release_server $version $platform
release_configurator $version $platform
release_jitsu $version $platform
;;
*)
echo "Invalid input service [$subsystem]..."
exit 1
;;
esac