@@ -88,10 +88,26 @@ extension Application {
8888
8989 let builderPlatform = ContainerizationOCI . Platform ( arch: " arm64 " , os: " linux " , variant: " v8 " )
9090
91+ var targetEnvVars : [ String ] = [ ]
92+ if let buildkitColors = ProcessInfo . processInfo. environment [ " BUILDKIT_COLORS " ] {
93+ targetEnvVars. append ( " BUILDKIT_COLORS= \( buildkitColors) " )
94+ }
95+ if ProcessInfo . processInfo. environment [ " NO_COLOR " ] != nil {
96+ targetEnvVars. append ( " NO_COLOR=true " )
97+ }
98+ targetEnvVars. sort ( )
99+
91100 let existingContainer = try ? await ClientContainer . get ( id: " buildkit " )
92101 if let existingContainer {
93102 let existingImage = existingContainer. configuration. image. reference
94103 let existingResources = existingContainer. configuration. resources
104+ let existingEnv = existingContainer. configuration. initProcess. environment
105+
106+ let existingManagedEnv = existingEnv. filter { envVar in
107+ envVar. hasPrefix ( " BUILDKIT_COLORS= " ) || envVar. hasPrefix ( " NO_COLOR= " )
108+ } . sorted ( )
109+
110+ let envChanged = existingManagedEnv != targetEnvVars
95111
96112 // Check if we need to recreate the builder due to different image
97113 let imageChanged = existingImage != builderImage
@@ -115,7 +131,7 @@ extension Application {
115131
116132 switch existingContainer. status {
117133 case . running:
118- guard imageChanged || cpuChanged || memChanged else {
134+ guard imageChanged || cpuChanged || memChanged || envChanged else {
119135 // If image, mem and cpu are the same, continue using the existing builder
120136 return
121137 }
@@ -125,7 +141,7 @@ extension Application {
125141 case . stopped:
126142 // If the builder is stopped and matches our requirements, start it
127143 // Otherwise, delete it and create a new one
128- guard imageChanged || cpuChanged || memChanged else {
144+ guard imageChanged || cpuChanged || memChanged || envChanged else {
129145 try await existingContainer. startBuildKit ( progressUpdate, nil )
130146 return
131147 }
@@ -173,10 +189,13 @@ extension Application {
173189 )
174190
175191 let imageConfig = try await image. config ( for: builderPlatform) . config
192+ var environment = imageConfig? . env ?? [ ]
193+ environment. append ( contentsOf: targetEnvVars)
194+
176195 let processConfig = ProcessConfiguration (
177196 executable: " /usr/local/bin/container-builder-shim " ,
178197 arguments: shimArguments,
179- environment: imageConfig ? . env ?? [ ] ,
198+ environment: environment ,
180199 workingDirectory: " / " ,
181200 terminal: false ,
182201 user: . id( uid: 0 , gid: 0 )
0 commit comments