11#!/usr/bin/env python3
2+ import datetime
23from plumbum import FG , local
34from plumbum .cmd import docker
45
@@ -7,6 +8,11 @@ REPO = local.env["DOCKER_REPO"]
78SUFFIX = local .env .get ("DOCKER_REPO_SUFFIX" , "" )
89VERSION = local .env ["DOCKER_TAG" ]
910
11+ # Multi-arch configuration
12+ PLATFORMS = local .env .get ("DOCKER_PLATFORM" )
13+ PG_VERSION = local .env .get ("PG_VERSION" , VERSION .split ("-" )[0 ])
14+ GIT_SHA1 = local .env .get ("GIT_SHA1" , "" )
15+
1016# Log all locally available images; will help to pin images
1117docker ["image" , "ls" , "--digests" , REPO ] & FG
1218
@@ -20,13 +26,41 @@ docker(
2026 REGISTRY ,
2127)
2228
23- # Push built images
24- local_image = "%s:%s" % (REPO , VERSION )
25- public_image = "%s/%s%s:%s" % (REGISTRY , REPO , SUFFIX , VERSION )
26- docker ["image" , "tag" , local_image , public_image ] & FG
27- docker ["image" , "push" , public_image ] & FG
29+
30+ def push_image (tag ):
31+ public_image = "%s/%s%s:%s" % (REGISTRY , REPO , SUFFIX , tag )
32+ if PLATFORMS :
33+ print (f"Building and pushing multi-arch image: { public_image } " )
34+ # Re-build for all platforms and push directly
35+ # We use VERSION as the BASE_TAG for the Dockerfile
36+ (
37+ docker [
38+ "buildx" ,
39+ "build" ,
40+ "--platform" ,
41+ PLATFORMS ,
42+ "--build-arg" ,
43+ f"BASE_TAG={ PG_VERSION } -alpine" ,
44+ "--build-arg" ,
45+ f"VCS_REF={ GIT_SHA1 } " ,
46+ "--build-arg" ,
47+ f"BUILD_DATE={ datetime .datetime .now ().isoformat ()} " ,
48+ "--tag" ,
49+ public_image ,
50+ "--push" ,
51+ "." ,
52+ ]
53+ & FG
54+ )
55+ else :
56+ # Fallback to standard push for single architecture
57+ local_image = "%s:%s" % (REPO , VERSION )
58+ docker ["image" , "tag" , local_image , public_image ] & FG
59+ docker ["image" , "push" , public_image ] & FG
60+
61+
62+ push_image (VERSION )
63+
2864if VERSION == local .env .get ("LATEST_RELEASE" ):
2965 latest_version = "alpine" if VERSION .endswith ("-alpine" ) else "latest"
30- public_image = "%s/%s%s:%s" % (REGISTRY , REPO , SUFFIX , latest_version )
31- docker ["image" , "tag" , local_image , public_image ] & FG
32- docker ["image" , "push" , public_image ] & FG
66+ push_image (latest_version )
0 commit comments