11#!/usr/bin/env python3
2+ import datetime
3+
24from plumbum import FG , local
35from plumbum .cmd import docker
46
@@ -7,6 +9,11 @@ REPO = local.env["DOCKER_REPO"]
79SUFFIX = local .env .get ("DOCKER_REPO_SUFFIX" , "" )
810VERSION = local .env ["DOCKER_TAG" ]
911
12+ # Multi-arch configuration
13+ PLATFORMS = local .env .get ("DOCKER_PLATFORM" )
14+ PG_VERSION = local .env .get ("PG_VERSION" , VERSION .split ("-" )[0 ])
15+ GIT_SHA1 = local .env .get ("GIT_SHA1" , "" )
16+
1017# Log all locally available images; will help to pin images
1118docker ["image" , "ls" , "--digests" , REPO ] & FG
1219
@@ -20,13 +27,41 @@ docker(
2027 REGISTRY ,
2128)
2229
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
30+
31+ def push_image (tag ):
32+ public_image = "%s/%s%s:%s" % (REGISTRY , REPO , SUFFIX , tag )
33+ if PLATFORMS :
34+ print (f"Building and pushing multi-arch image: { public_image } " )
35+ # Re-build for all platforms and push directly
36+ # We use VERSION as the BASE_TAG for the Dockerfile
37+ (
38+ docker [
39+ "buildx" ,
40+ "build" ,
41+ "--platform" ,
42+ PLATFORMS ,
43+ "--build-arg" ,
44+ f"BASE_TAG={ PG_VERSION } -alpine" ,
45+ "--build-arg" ,
46+ f"VCS_REF={ GIT_SHA1 } " ,
47+ "--build-arg" ,
48+ f"BUILD_DATE={ datetime .datetime .now ().isoformat ()} " ,
49+ "--tag" ,
50+ public_image ,
51+ "--push" ,
52+ "." ,
53+ ]
54+ & FG
55+ )
56+ else :
57+ # Fallback to standard push for single architecture
58+ local_image = "%s:%s" % (REPO , VERSION )
59+ docker ["image" , "tag" , local_image , public_image ] & FG
60+ docker ["image" , "push" , public_image ] & FG
61+
62+
63+ push_image (VERSION )
64+
2865if VERSION == local .env .get ("LATEST_RELEASE" ):
2966 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
67+ push_image (latest_version )
0 commit comments