-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci
executable file
·194 lines (166 loc) · 5.62 KB
/
ci
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
#!/bin/bash
# Language (force it so getopt messages are always in english, as the script)
LANG=en_EN
# Get script name
SCRIPT=$(basename ${0})
# Supported distributions
SUPPORTEDDISTROS='centos6 centos7 rockylinux8 opensuseleap15.5'
# Supported PostgreSQL major versions
POSTGRESQLMAJORVERS='9.3 9.4 9.5 9.6 10 11 12 13 14 15 16'
# Ignored combinations, will exit without errors so the CI does not fail
IGNOREDCOMBINATIONS="centos7|16"
# Allocate tty by default
TTY='-t'
# Use podman by default
CENGINE='podman'
print_info() {
echo -e "\033[1;36m[INFO] ${1}\033[0m"
}
print_error() {
echo -e "\033[1;31m[ERROR] ${1}\033[0m"
}
print_ok() {
echo -e "\033[1;32m[INFO] ${1}\033[0m"
}
print_incorrect_syntax() {
print_error "Incorrect syntax. Use ${SCRIPT} -h for help"
}
print_error_unsupported_distro() {
print_error "Unsupported distro. Use ${SCRIPT} -h for help"
}
print_error_unsupported_nexus_major_ver() {
print_error "Unsupported PostgreSQL major version. Use ${SCRIPT} -h for help"
}
print_help() {
echo ""
echo "Script to perform tds_fdw-rpm CI"
echo ""
echo "Syntax: "
echo ""
echo "${SCRIPT} <ARGUMENTS>"
echo ""
echo "Mandatory arguments:"
echo ""
echo " --distro=<$(echo ${1}|tr ' ' '|')>"
echo " --postgresql-major-ver=<$(echo ${2}|tr ' ' '|')>"
echo ""
echo "Optional arguments:"
echo ""
echo " --name=<CONTAINER_NAME> Define the container name"
echo " If undefined, container name will be"
echo " s3fs-fuse-rpm-<DISTRO>-<TIMESTAMP>"
echo " --docker If present, use docker instead of podman"
echo " --remove-on-error If present, remove the container on errors"
echo " --notty If present, does not allocate a tty for docker"
echo " --nocleanup If present, do not run the cleanup script before exiting"
echo ""
}
remove_container() {
${CENGINE} container rm -f ${1}
}
exit_error() {
if [ ${1} -ne 0 ]; then
print_error "An error happened! Check log!"
if [ ! -z ${REMOVE_ON_ERROR} ]; then
remove_container ${CONTAINER_NAME}
fi
exit 1
fi
}
docker_run() {
if [ ! -z ${3} ]; then
local COMMAND_USER="-u ${3}"
fi
local COMMAND="${CENGINE} container exec -i ${TTY} ${COMMAND_USER} ${1} ${2}"
local RESULT=$(${COMMAND})
exit_error ${?}
if [ "${RESULT}" != "" ]; then
echo "${RESULT}"
fi
}
check_pgver() {
local SUPPORTEDPGVER=""
for SUPPORTEDPGVER in ${POSTGRESQLMAJORVERS}; do
if [ "${POSTGRESQLMAJORVER}" == "${SUPPORTEDPGVER}" ]; then
echo "${POSTGRESQLMAJORVER}"
return 0
fi
done
echo ""
return 1
}
# read the options
ARGS=$(getopt -o h --long help,docker,remove-on-error,notty,nocleanup,distro:,postgresql-major-ver:,name: -n "${SCRIPT}" -- "$@")
if [ $? -ne 0 ];
then
print_incorrect_syntax
exit 1
fi
eval set -- "${ARGS}"
# extract options and their arguments into variables
while true ; do
case "${1}" in
-h|--help) print_help "${SUPPORTEDDISTROS}" "${POSTGRESQLMAJORVERS}"; exit 1;;
--docker) CENGINE="docker"; shift 1 ;;
--remove-on-error) REMOVE_ON_ERROR="--rm"; shift 1 ;;
--notty) TTY=""; shift 1 ;;
--nocleanup) NOCLEANUP="TRUE"; shift ;;
--distro) DISTRO="${2}"; shift 2;;
--postgresql-major-ver) POSTGRESQLMAJORVER="${2}"; shift 2;;
--name) CONTAINER_NAME="${2}"; shift 2;;
--) shift ; break ;;
*) print_incorrect_syntax; exit 1;;
esac
done
# Check distribution
case "${DISTRO}" in
centos6) IMAGE="docker.io/tdsfdw/centos6-postgresql:${POSTGRESQLMAJORVER}";;
centos7) IMAGE="docker.io/tdsfdw/centos7-postgresql:${POSTGRESQLMAJORVER}";;
rockylinux8) IMAGE="docker.io/tdsfdw/rockylinux8-postgresql:${POSTGRESQLMAJORVER}";;
opensuseleap15.5) IMAGE="docker.io/tdsfdw/opensuseleap15.5-postgresql:${POSTGRESQLMAJORVER}";;
*) print_error_unsupported_distro
exit 1;;
esac
if [ "${CENGINE}" == "podman" ]; then
EXTRA_FLAGS="${EXTRA_FLAGS} --userns=keep-id"
fi
# Check PostgreSQL version
PG_VER="$(check_pgver)"
if [ "${PG_VER}" == "" ]; then
print_error_unknown_unsupported_pgver
exit 1
fi
export SHORTVER="$(echo ${PG_VER}|tr -d '.')"
for IGNOREDCOMBINATION in ${IGNOREDCOMBINATIONS}; do
IGNOREDDISTRO=$(echo ${IGNOREDCOMBINATION}|cut -d'|' -f1)
IGNOREDVER=$(echo ${IGNOREDCOMBINATION}|cut -d'|' -f2)
if [ "${IGNOREDDISTRO}" == "${DISTRO}" ] && [ "${IGNOREDVER}" == "${PG_VER}" ]; then
echo "${IGNOREDDISTRO} with PostgreSQL ${IGNOREDVER} is not available"
exit 0
fi
done
# Check name
if [ -z ${CONTAINER_NAME} ]; then
CONTAINER_NAME="tdsfdw-rpm-${DISTRO}-$(date +'%s')"
fi
# Package name
PACKAGE_NAME="postgresql-${SHORTVER}-tds_fdw"
print_info "Pulling latest image..."
${CENGINE} pull ${IMAGE}
print_info "Starting container ${CONTAINER_NAME}..."
${CENGINE} container run -i ${TTY} ${REMOVE_ON_ERROR} --name "${CONTAINER_NAME}" -v ${PWD}:/tmp/tds_fdw-rpms ${EXTRA_FLAGS} -w /tmp/tds_fdw-rpms -d ${IMAGE}
print_info "Cleaning up"
docker_run "${CONTAINER_NAME}" "./clean" "postgres"
print_info "Building tds_fdw package..."
docker_run "${CONTAINER_NAME}" "./tds_fdw-rpm -p ${POSTGRESQLMAJORVER}" "postgres"
print_info "Installing tds_fdw package..."
docker_run "${CONTAINER_NAME}" "/bin/rpm -i RPMS/$HOSTTYPE/${PACKAGE_NAME}-*.*.$HOSTTYPE.rpm" "root"
print_info "Testing RPM removal..."
docker_run "${CONTAINER_NAME}" "/bin/rpm -e ${PACKAGE_NAME}" "root"
if [ "${NOCLEANUP}" != "TRUE" ]; then
print_info "Cleaning up"
docker_run "${CONTAINER_NAME}" "./clean" "postgres"
fi
print_info "Removing container..."
remove_container ${CONTAINER_NAME}
print_ok "Everything is OK"