@@ -7,11 +7,41 @@ import pathlib
77import shutil
88import sys
99import yaml
10- from typing import Any , Dict , List , Union
10+ from typing import Any , Dict , List , Tuple , Union
1111from util import enable_run_trace , pushd , render_template , run
1212
1313SCRIPT_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+
1545class 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 :
0 commit comments