Skip to content

Commit 4523583

Browse files
committed
CBD-5454: Fix for older packages in RPM-based distributions
Extend test scenarios to check for existence of older packages. Change-Id: I03b7d1ed1cde02da98fb6e10196310d2db21e567 Reviewed-on: https://review.couchbase.org/c/build-tools/+/193963 Tested-by: Chris Hillery <[email protected]> Reviewed-by: Ming Ho <[email protected]>
1 parent 3eadebf commit 4523583

File tree

4 files changed

+81
-29
lines changed

4 files changed

+81
-29
lines changed

repo_manage/couchbase-release/couchbase-release-build

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,41 @@ import pathlib
77
import shutil
88
import sys
99
import yaml
10-
from typing import Any, Dict, List, Union
10+
from typing import Any, Dict, List, Tuple, Union
1111
from util import enable_run_trace, pushd, render_template, run
1212

1313
SCRIPT_DIR: pathlib.Path = pathlib.Path(__file__).resolve().parent
1414

15+
16+
17+
class TestSpec:
18+
def __init__(
19+
self, baseimage: str, format: str, testver1: str, testver2: str
20+
):
21+
self.baseimage: str = baseimage
22+
self.format: str = format
23+
self.testver1: str = testver1
24+
self.testver2: str = testver2
25+
26+
def context_for(self, arch: str):
27+
"""
28+
Return a template context for this arch
29+
"""
30+
31+
context: Dict[str, str] = {}
32+
context["baseimage"] = self.baseimage
33+
34+
# Older versions available only on amd64
35+
if arch == "arm64":
36+
context["testver1"] = "7.1.2"
37+
context["testver2"] = "7.1.4"
38+
else:
39+
context["testver1"] = self.testver1
40+
context["testver2"] = self.testver1
41+
42+
return context
43+
44+
1545
class CouchbaseReleaseBuilder:
1646

1747
def __init__(
@@ -28,6 +58,24 @@ class CouchbaseReleaseBuilder:
2858
self.build_dir: pathlib.Path = self.script_dir / "build"
2959
shutil.rmtree(self.build_dir, ignore_errors=True)
3060
self.build_dir.mkdir(exist_ok = True)
61+
self.testspecs: List[TestSpec] = []
62+
self.init_testspecs()
63+
64+
65+
def init_testspecs(self):
66+
"""
67+
Initializes the set of testspecs to run
68+
"""
69+
70+
self.testspecs.append(TestSpec("centos:7", "rpm", "6.5.2", "7.1.1"))
71+
self.testspecs.append(TestSpec("almalinux:8", "rpm", "6.6.1", "7.1.0"))
72+
self.testspecs.append(TestSpec("almalinux:9", "rpm", "7.2.0", "7.2.0"))
73+
self.testspecs.append(TestSpec("amazonlinux:2", "rpm", "6.6.2", "7.0.4"))
74+
self.testspecs.append(TestSpec("amazonlinux:2023", "rpm", "7.2.0", "7.2.0"))
75+
self.testspecs.append(TestSpec("debian:10", "deb", "6.6.3", "7.1.1"),)
76+
self.testspecs.append(TestSpec("debian:11", "deb", "7.1.1", "7.1.3"),)
77+
self.testspecs.append(TestSpec("ubuntu:20.04", "deb", "6.6.5", "7.0.5"),)
78+
self.testspecs.append(TestSpec("ubuntu:22.04", "deb", "7.1.0", "7.1.1"),)
3179

3280

3381
def context_for(self, target: str) -> Dict[str, Union[str, pathlib.Path]]:
@@ -143,50 +191,40 @@ class CouchbaseReleaseBuilder:
143191

144192

145193
def run_test(
146-
self, target: str, baseimage: str, format: str, arch: str
194+
self, target: str, testspec: TestSpec, arch: str
147195
) -> None:
148196
"""
149197
Builds a local Docker image to test the created
150198
couchbase-release packages
151199
"""
152200

153-
logging.info(f"Running test build for {target} - {baseimage}")
201+
logging.info(f"Running test build for {target} - {testspec.baseimage}")
154202
context = self.context_for(target)
155-
context["baseimage"] = baseimage
203+
context.update(testspec.context_for(arch))
156204
render_template(
157-
self.script_dir / "test" / f"Dockerfile.{format}.j2",
205+
self.script_dir / "test" / f"Dockerfile.{testspec.format}.j2",
158206
self.build_dir / "Dockerfile",
159207
context
160208
)
161209
with pushd(self.build_dir):
162-
run(
163-
f"docker buildx build --platform {arch} --pull --no-cache ."
164-
)
165-
run(
166-
"docker buildx prune -f"
167-
)
210+
try:
211+
run(
212+
f"docker buildx build --platform {arch} --pull --no-cache ."
213+
)
214+
finally:
215+
run(
216+
"docker buildx prune -f"
217+
)
168218

169219

170220
def test_target(self, target: str) -> None:
171221
"""
172222
Runs tests for created installers across defined set of OSes
173223
"""
174224

175-
for arch in ["amd64", "arm64"]:
176-
for baseimage in [
177-
"almalinux:8",
178-
"almalinux:9",
179-
"amazonlinux:2",
180-
"amazonlinux:2023"
181-
]:
182-
self.run_test(target, baseimage, "rpm", arch)
183-
for baseimage in [
184-
"debian:10",
185-
"debian:11",
186-
"ubuntu:20.04",
187-
"ubuntu:22.04"
188-
]:
189-
self.run_test(target, baseimage, "deb", arch)
225+
for testspec in self.testspecs:
226+
for arch in ["arm64", "amd64"]:
227+
self.run_test(target, testspec, arch)
190228

191229

192230
def test(self, targets: List[str]) -> None:

repo_manage/couchbase-release/rpm/couchbase-release.spec.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if [ -f /etc/os-release ]; then
3232
. /etc/os-release
3333
fi
3434

35-
MAJVER=$(echo "$VERSION" | sed -e 's/\..*//')
35+
MAJVER=$(echo "$VERSION_ID" | sed -e 's/\..*//')
3636

3737
if [ "${ID}" = "amzn" ]; then
3838
DISTRO="${ID}${MAJVER}"

repo_manage/couchbase-release/test/Dockerfile.deb.j2

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@ RUN set -x \
66
&& apt-get update \
77
&& apt-get install -y /tmp/${DEBFILE} \
88
&& apt-get update \
9-
&& apt-cache search couchbase | grep couchbase-server
9+
&& apt list -a couchbase-server | grep couchbase-server | tee /tmp/output.txt
10+
11+
{% if target == "release" %}
12+
RUN set -x \
13+
&& fgrep {{ testver1 }} /tmp/output.txt \
14+
&& fgrep {{ testver2 }} /tmp/output.txt \
15+
&& fgrep 7.2.0 /tmp/output.txt
16+
{% endif %}

repo_manage/couchbase-release/test/Dockerfile.rpm.j2

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ ARG RPMFILE=couchbase-{{ target }}-{{ version }}-{{ bld_num }}.noarch.rpm
44
COPY ${RPMFILE} /tmp
55
RUN set -x \
66
&& yum install -y /tmp/${RPMFILE} \
7-
&& yum search --showduplicates -y couchbase | grep couchbase-server
7+
&& yum search --showduplicates -y couchbase-server | grep couchbase-server | tee /tmp/output.txt
8+
9+
{% if target == "release" %}
10+
RUN set -x \
11+
&& fgrep {{ testver1 }} /tmp/output.txt \
12+
&& fgrep {{ testver2 }} /tmp/output.txt \
13+
&& fgrep 7.2.0 /tmp/output.txt
14+
{% endif %}

0 commit comments

Comments
 (0)