Skip to content

Commit 7eac053

Browse files
committed
Add multi-architecture support (AMD64 and ARM64)
1 parent 7922e1f commit 7eac053

File tree

2 files changed

+105
-13
lines changed

2 files changed

+105
-13
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,34 @@ and it will run the build step on all versions that starts with 6.0.
116116

117117
The only other optional usefull argument is `--cpu=N` and it will set how many paralell processes will be used. By default you will use n - 1 number of cpu cores that is available on your system. Commands like pull and push aare not very cpu intensive so using a higher number here might speed things up if you have good network bandwidth.
118118

119+
## Multi-architecture Support (ARM64/x86)
120+
121+
The build system now supports multi-architecture builds using Docker Buildx. You can build images for both AMD64 and ARM64 platforms:
122+
123+
### Platform Options
124+
125+
- `amd64` - Build for AMD64/x86_64 only
126+
- `arm64` - Build for ARM64 only
127+
- `both` or `multi` - Build for both platforms (default)
128+
129+
### Building for ARM64
130+
131+
```bash
132+
# Build for ARM64 only
133+
invoke build 7.2.5 --platforms=arm64
134+
135+
# Build for both AMD64 and ARM64 (default)
136+
invoke build 7.2.5 --platforms=both
137+
138+
# Push multi-arch images
139+
invoke push 7.2.5 --platforms=both
140+
141+
# Use the dedicated buildx command
142+
invoke buildx 7.2.5 --platforms=arm64
143+
```
144+
145+
The `buildx` command provides additional control over multi-architecture builds and uses Docker Buildx builder instances for cross-platform compilation.
146+
119147

120148
## Makefile (legacy)
121149

tasks.py

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@
77

88
latest_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
1128
version_config_mapping = []
1229
version_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

81100
def _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
134198
def list(c):
135199
from pprint import pprint

0 commit comments

Comments
 (0)