77
88latest_version_string = "7.2.5"
99
10+ # Platform mapping for simplified platform arguments
11+ platform_mapping = {
12+ "amd64" : "linux/amd64" ,
13+ "arm64" : "linux/arm64" ,
14+ "both" : "linux/amd64,linux/arm64" ,
15+ "multi" : "linux/amd64,linux/arm64"
16+ }
17+
18+ def get_platforms (platform_arg ):
19+ """
20+ Convert simplified platform argument to full platform string
21+ """
22+ if platform_arg in platform_mapping :
23+ return platform_mapping [platform_arg ]
24+ # If it's already a full platform string, return as-is
25+ return platform_arg
26+
1027# Unpublished versions
1128version_config_mapping = []
1229version_config_mapping += [f"3.0.{ i } " for i in range (0 , 8 )]
@@ -72,19 +89,23 @@ def _docker_build(config):
7289 """
7390 Internal multiprocess method to run docker build command
7491 """
75- c , version = config
76- print (f" -- Starting docker build for version : { version } " )
77- build_command = f"docker build --build-arg redis_version={ version } -t grokzen/redis-cluster:{ version } ."
92+ c , version , platforms = config
93+ print (f" -- Starting docker build for version : { version } on platforms: { platforms } " )
94+ # Create buildx builder if it doesn't exist
95+ c .run ("docker buildx create --use --name redis-cluster-builder || docker buildx use redis-cluster-builder" , warn = True )
96+ build_command = f"docker buildx build --platform={ platforms } --build-arg redis_version={ version } -t grokzen/redis-cluster:{ version } ."
7897 c .run (build_command )
7998
8099
81100def _docker_push (config ):
82101 """
83- Internal multiprocess method to run docker push command
102+ Internal multiprocess method to run docker push command with multi-arch support
84103 """
85- c , version = config
86- print (f" -- Starting docker push for version : { version } " )
87- build_command = f"docker push grokzen/redis-cluster:{ version } "
104+ c , version , platforms = config
105+ print (f" -- Starting docker push for version : { version } with platforms: { platforms } " )
106+ # Use buildx to build and push multi-arch images
107+ c .run ("docker buildx create --use --name redis-cluster-builder || docker buildx use redis-cluster-builder" , warn = True )
108+ build_command = f"docker buildx build --platform={ platforms } --build-arg redis_version={ version } -t grokzen/redis-cluster:{ version } --push ."
88109 c .run (build_command )
89110
90111
@@ -103,33 +124,76 @@ def pull(c, version, cpu=None):
103124
104125
105126@task
106- def build (c , version , cpu = None ):
107- print (f" -- Docker building version : { version } " )
127+ def build (c , version , cpu = None , platforms = "both" ):
128+ platforms = get_platforms (platforms )
129+ print (f" -- Docker building version : { version } for platforms : { platforms } " )
108130
109131 pool = Pool (get_pool_size (cpu ))
110132 pool .map (
111133 _docker_build ,
112134 [
113- [c , version ]
135+ [c , version , platforms ]
114136 for version in version_name_to_version (version )
115137 ],
116138 )
117139
118140
119141@task
120- def push (c , version , cpu = None ):
121- print (f" -- Docker push version to docker-hub : { version } " )
142+ def push (c , version , cpu = None , platforms = "both" ):
143+ platforms = get_platforms (platforms )
144+ print (f" -- Docker push version to docker-hub : { version } for platforms : { platforms } " )
122145
123146 pool = Pool (get_pool_size (cpu ))
124147 pool .map (
125148 _docker_push ,
126149 [
127- [c , version ]
150+ [c , version , platforms ]
128151 for version in version_name_to_version (version )
129152 ],
130153 )
131154
132155
156+ @task
157+ def buildx (c , version , cpu = None , platforms = "both" ):
158+ """
159+ Build multi-architecture images using docker buildx without pushing.
160+ Use the separate push command to push the images after building.
161+
162+ Usage:
163+ invoke buildx 7.2.5 # Build both platforms (default)
164+ invoke buildx 7.2.5 --platforms=amd64 # Build only AMD64
165+ invoke buildx 7.2.5 --platforms=arm64 # Build only ARM64
166+ """
167+ platforms = get_platforms (platforms )
168+ print (f" -- Docker buildx for version : { version } on platforms : { platforms } " )
169+
170+ # Create buildx builder if it doesn't exist
171+ c .run ("docker buildx create --use --name redis-cluster-builder || docker buildx use redis-cluster-builder" , warn = True )
172+
173+ pool = Pool (get_pool_size (cpu ))
174+ pool .map (
175+ _docker_buildx ,
176+ [
177+ [c , version , platforms ]
178+ for version in version_name_to_version (version )
179+ ],
180+ )
181+
182+
183+ def _docker_buildx (config ):
184+ """
185+ Internal multiprocess method to run docker buildx command
186+ """
187+ c , version , platforms = config
188+
189+ # Build without loading to local Docker daemon by default
190+ action = ""
191+
192+ print (f" -- Starting docker buildx for version : { version } on platforms: { platforms } " )
193+ build_command = f"docker buildx build --platform={ platforms } --build-arg redis_version={ version } -t grokzen/redis-cluster:{ version } ."
194+ c .run (build_command )
195+
196+
133197@task
134198def list (c ):
135199 from pprint import pprint
0 commit comments