@@ -316,14 +316,17 @@ async function selfHostedBuildImage(
316316 . filter ( ( [ key , value ] ) => value )
317317 . flatMap ( ( [ key , value ] ) => [ "--build-arg" , `${ key } =${ value } ` ] ) ;
318318
319+ const apiUrl = normalizeApiUrlForBuild ( options . apiUrl ) ;
320+ const network = getNetworkArgs ( apiUrl , options . network ) ;
321+
319322 const args = [
320323 "build" ,
321324 "-f" ,
322325 "Containerfile" ,
323326 options . noCache ? "--no-cache" : undefined ,
324327 "--platform" ,
325328 options . buildPlatform ,
326- ...( options . network ? [ "--network" , options . network ] : [ ] ) ,
329+ ...network ,
327330 "--build-arg" ,
328331 `TRIGGER_PROJECT_ID=${ options . projectId } ` ,
329332 "--build-arg" ,
@@ -335,7 +338,7 @@ async function selfHostedBuildImage(
335338 "--build-arg" ,
336339 `TRIGGER_PROJECT_REF=${ options . projectRef } ` ,
337340 "--build-arg" ,
338- `TRIGGER_API_URL=${ normalizeApiUrlForBuild ( options . apiUrl ) } ` ,
341+ `TRIGGER_API_URL=${ apiUrl } ` ,
339342 "--build-arg" ,
340343 `TRIGGER_PREVIEW_BRANCH=${ options . branchName ?? "" } ` ,
341344 "--build-arg" ,
@@ -740,10 +743,26 @@ CMD []
740743
741744// If apiUrl is something like http://localhost:3030, AND we are on macOS, we need to convert it to http://host.docker.internal:3030
742745// this way the indexing will work because the docker image can reach the local server
743- function normalizeApiUrlForBuild ( apiUrl : string ) {
746+ function normalizeApiUrlForBuild ( apiUrl : string ) : string {
744747 if ( process . platform === "darwin" ) {
745748 return apiUrl . replace ( "localhost" , "host.docker.internal" ) ;
746749 }
747750
748751 return apiUrl ;
749752}
753+
754+ function getNetworkArgs ( apiUrl : string , network ?: string ) : string [ ] {
755+ if ( network ) {
756+ return [ `--network` , network ] ;
757+ }
758+
759+ if ( process . platform === "darwin" ) {
760+ return [ ] ;
761+ }
762+
763+ if ( apiUrl . includes ( "localhost" ) || apiUrl . includes ( "127.0.0.1" ) ) {
764+ return [ "--network" , "host" ] ;
765+ }
766+
767+ return [ ] ;
768+ }
0 commit comments