@@ -133,6 +133,35 @@ async function getRoutableHostDns(): Promise<string[]> {
133133 return publicDnsFallback ;
134134}
135135
136+ function getDockerMirrorRegistryConfig ( ) : TOML . JsonMap {
137+ return {
138+ "docker.io" : {
139+ mirrors : [ "http://192.168.127.1:5000" ] ,
140+ http : true ,
141+ insecure : true ,
142+ } ,
143+ "192.168.127.1:5000" : {
144+ http : true ,
145+ insecure : true ,
146+ } ,
147+ } ;
148+ }
149+
150+ async function writeTomlConfig (
151+ filePath : string ,
152+ jsonConfig : TOML . JsonMap ,
153+ ) : Promise < void > {
154+ const tomlString = TOML . stringify ( jsonConfig ) ;
155+
156+ try {
157+ await fs . promises . writeFile ( filePath , tomlString ) ;
158+ core . debug ( `TOML configuration is ${ tomlString } ` ) ;
159+ } catch ( err ) {
160+ core . warning ( `error writing TOML configuration: ${ ( err as Error ) . message } ` ) ;
161+ throw err ;
162+ }
163+ }
164+
136165async function writeBuildkitdTomlFile (
137166 parallelism : number ,
138167 addr : string ,
@@ -151,17 +180,7 @@ async function writeBuildkitdTomlFile(
151180 dns : {
152181 nameservers : dnsNameservers ,
153182 } ,
154- registry : {
155- "docker.io" : {
156- mirrors : [ "http://192.168.127.1:5000" ] ,
157- http : true ,
158- insecure : true ,
159- } ,
160- "192.168.127.1:5000" : {
161- http : true ,
162- insecure : true ,
163- } ,
164- } ,
183+ registry : getDockerMirrorRegistryConfig ( ) ,
165184 worker : {
166185 oci : {
167186 enabled : true ,
@@ -177,15 +196,27 @@ async function writeBuildkitdTomlFile(
177196 } ,
178197 } ;
179198
180- const tomlString = TOML . stringify ( jsonConfig ) ;
199+ await writeTomlConfig ( "buildkitd.toml" , jsonConfig ) ;
200+ }
181201
182- try {
183- await fs . promises . writeFile ( "buildkitd.toml" , tomlString ) ;
184- core . debug ( `TOML configuration is ${ tomlString } ` ) ;
185- } catch ( err ) {
186- core . warning ( `error writing TOML configuration: ${ ( err as Error ) . message } ` ) ;
187- throw err ;
188- }
202+ export async function writeDockerContainerBuildkitdTomlFile (
203+ filePath = "docker-container-buildkitd.toml" ,
204+ ) : Promise < string > {
205+ // Keep this config safe for buildx's docker-container driver: it should not
206+ // set grpc.address, which buildx owns for the containerized BuildKit daemon.
207+ await configureSystemdResolvedForBuildkit ( ) ;
208+ const dnsNameservers = await getRoutableHostDns ( ) ;
209+ const jsonConfig : TOML . JsonMap = {
210+ dns : {
211+ nameservers : dnsNameservers ,
212+ } ,
213+ registry : getDockerMirrorRegistryConfig ( ) ,
214+ } ;
215+
216+ await writeTomlConfig ( filePath , jsonConfig ) ;
217+ core . info ( `Wrote Docker container BuildKit config to ${ filePath } ` ) ;
218+
219+ return filePath ;
189220}
190221
191222export async function startBuildkitd (
0 commit comments