This repository has been archived by the owner on Jan 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
create-packages.sh
executable file
·227 lines (190 loc) · 7.08 KB
/
create-packages.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/bash
# This script (re)creates `packages` directory
# In this directory application `myapp` is created
# Then, this application is packed into RPM and DEB
# Note, that if you are using OS X, you should have `gnu-sed` installed
# and packing will be performed in docker in this case
set -e
#########
# Flags #
#########
packages_dirname="packages"
keep_old_packages=""
skip_cartridge=""
skip_tdg=""
tdg_version="1.7.17-0-g2a5b4bd1"
usage() {
echo "Usage: ./create-packages.sh [options]"
echo "Options:"
echo " -h, --help Show this help message"
echo " -d <path>, --dir <path> Folder to save packages (default: ${packages_dirname})"
echo " -k, --keep Don't delete packages folder (will be removed by default)"
echo " --skip-cartridge Skip Cartridge packages creation (will be created by default)"
echo " --skip-tdg Skip TDG packages creation (will be created by default)"
echo " -t <version>, --tdg-version <version> Version of TDG to download (default: ${tdg_version})"
}
while [ "$1" != "" ]; do
case "$1" in
-h | --help)
usage
exit
;;
-d | --dir)
packages_dirname="$2"
shift
shift
;;
-k | --keep)
keep_old_packages="true"
shift
;;
--skip-cartridge)
skip_cartridge="true"
shift
;;
--skip-tdg)
skip_tdg="true"
shift
;;
-t | --tdg-version)
tdg_version="$2"
shift
shift
;;
*)
echo "Unexpected parameter: ${1}"
exit 1
;;
esac
done
if [ -z "${skip_cartridge}" ]; then
pack_flags='--use-docker'
if [[ $(tarantool -V) == "Tarantool Enterprise"* && -z "${TARANTOOL_SDK_PATH}" ]]; then
if [[ $(tarantool -V) == *"Target: Darwin"* ]]; then
echo "Set the path to Linux Tarantool SDK using the TARANTOOL_SDK_PATH environment variable!"
exit 1
else
pack_flags+=' --sdk-local'
fi
fi
fi
###############
# Preparation #
###############
lazy_pack() {
lp_format="${1}"
lp_app_name="${2}"
lp_version="${3}"
lp_suffix="${4}"
if [ -n "${lp_suffix}" ]; then
lp_suffix_with_dash="-${lp_suffix}"
fi
lp_extension=${lp_format}
if [ "${lp_extension}" = "tgz" ]; then
lp_extension="tar.gz"
fi
package_name="${lp_app_name}-${lp_version}${lp_suffix_with_dash}.${lp_extension}"
if [ ! -f "${package_name}" ]; then
echo " - Package '${package_name}' creation:"
cartridge pack "${lp_format}" \
--version "${lp_version}" \
--suffix "${lp_suffix}" \
${pack_flags} \
"${lp_app_name}"
else
echo " - Package '${package_name}' already created"
fi
}
if [ -d "${packages_dirname}" ] && [ -z "${keep_old_packages}" ]; then
printf "Removing an existing package directory... "
rm -rf "${packages_dirname}"
echo "OK"
fi
mkdir -p "${packages_dirname}" >/dev/null
pushd "${packages_dirname}" >/dev/null
#######################################
# Packages for default test scenarios #
#######################################
if [ -z "${skip_cartridge}" ]; then
app_name=myapp
version=1.0.0-0
echo ""
echo "Creating packages for default test scenarios:"
echo " - Application creation:"
rm -rf ${app_name}
cartridge create --name ${app_name}
# configure vshard group "hot"
awk '{gsub(/cartridge.cfg\({/, "&\n vshard_groups = { hot = { bucket_count = 20000 } },")}1' \
${app_name}/init.lua >${app_name}/temp.lua
mv ${app_name}/temp.lua ${app_name}/init.lua
# add dependencies to app.roles.custom role
awk '{gsub(/-- dependencies/, "dependencies")}1' \
${app_name}/app/roles/custom.lua >${app_name}/temp.lua
mv ${app_name}/temp.lua ${app_name}/app/roles/custom.lua
# remove setting cluster_cookie on cartridge.cfg
awk '{gsub(/cluster_cookie/, "-- cluster_cookie")}1' \
${app_name}/init.lua >${app_name}/temp.lua
mv ${app_name}/temp.lua ${app_name}/init.lua
lazy_pack tgz "${app_name}" "${version}"
lazy_pack rpm "${app_name}" "${version}"
lazy_pack deb "${app_name}" "${version}"
rm -rf ${app_name}
fi
#################################################
# Packages for 'update_cartridge' test scenario #
#################################################
if [ -z "${skip_cartridge}" ]; then
app_name=myapp
echo ""
echo "Creating packages for 'update_cartridge' test scenario:"
echo " - Application creation:"
rm -rf ${app_name}
cartridge create --name ${app_name}
version=1 # myapp X version uses Cartridge 2.X.0 version
for cartridge_version in '2.1.2' '2.2.0' '2.3.0' '2.5.0' '2.6.0'; do
awk -v cartridge_dep_str="cartridge == ${cartridge_version}-1" \
'{gsub(/cartridge == [0-9.-]+/, cartridge_dep_str);}1' \
${app_name}/${app_name}-scm-1.rockspec >${app_name}/temp.rockspec
mv ${app_name}/temp.rockspec ${app_name}/${app_name}-scm-1.rockspec
lazy_pack tgz "${app_name}" "${version}.0.0-0" "with-c-${cartridge_version}"
((version++))
done
rm -rf ${app_name}
fi
###################################
# Packages for TDG test scenarios #
###################################
if [ -z "${skip_tdg}" ]; then
echo ""
if [ -f "tdg.tar.gz" ]; then
echo "TDG package 'tdg.tar.gz' already downloaded"
else
if [ -n "${DOWNLOAD_TNT_TOKEN}" ]; then
printf "Downloading TDG %s package from 'download.tarantool.io'... " "${tdg_version}"
curl -L -s -o "tdg.tar.gz" \
"https://tarantool:${DOWNLOAD_TNT_TOKEN}@download.tarantool.io/tdg/tdg-${tdg_version}.tar.gz" &>/dev/null
echo 'OK'
elif (command -v aws &>/dev/null) && [ -n "${AWS_ACCESS_KEY_ID}" ] && [ -n "${AWS_SECRET_ACCESS_KEY}" ]; then
printf "Downloading TDG %s package from MCS... " "${tdg_version}"
aws --region eu-central-1 --endpoint-url https://hb.bizmrg.com s3 cp \
"s3://packages/tdg/tdg-${tdg_version}.tar.gz" "tdg.tar.gz" &>/dev/null &&
tdg_exists="true" || tdg_exists="false"
if [ "${tdg_exists}" = "false" ]; then
aws --region eu-central-1 --endpoint-url https://hb.bizmrg.com s3 cp \
"s3://sdk-backup-25.08.21/tdg/tdg-${tdg_version}.tar.gz" "tdg.tar.gz" >/dev/null
fi
echo 'OK'
else
echo "[WARNING] Impossible to download TDG. It's necessary to run TDG tests. You can:"
echo " - specify 'DOWNLOAD_TNT_TOKEN' in environment to download from 'download.tarantool.io';"
echo " - install AWS CLI and specify 'AWS_ACCESS_KEY_ID' and 'AWS_SECRET_ACCESS_KEY' in environment to download from MCS;"
echo " - put 'tdg.tar.gz' package in '${packages_dirname}' directory manually."
fi
fi
fi
##############
# Completion #
##############
echo ""
popd >/dev/null
echo "Packages are placed in '${packages_dirname}' directory"