@@ -511,6 +511,14 @@ export class Job {
511
511
}
512
512
513
513
if ( this . services ?. length ) {
514
+ // `host` and `none` networks do not work with services because aliases only work for
515
+ // user defined networks.
516
+ for ( const network of this . argv . network ) {
517
+ if ( [ "host" , "none" ] . includes ( network ) ) {
518
+ throw new AssertionError ( { message : `Cannot add service network alias with network mode '${ network } '` } ) ;
519
+ }
520
+ }
521
+
514
522
await this . createDockerNetwork ( `gitlab-ci-local-${ this . jobId } ` ) ;
515
523
516
524
await Promise . all (
@@ -720,13 +728,25 @@ export class Job {
720
728
dockerCmd += `--cpus=${ cpuConfig } ` ;
721
729
}
722
730
723
- // host and none networks have to be specified using --network,
724
- // since they cannot be used with `docker network connect`.
731
+ // host and none networks have to be specified using --network, since they cannot be used with
732
+ // `docker network connect`.
725
733
for ( const network of this . argv . network ) {
726
734
if ( [ "host" , "none" ] . includes ( network ) ) {
727
735
dockerCmd += `--network ${ network } ` ;
728
736
}
729
737
}
738
+ // The default podman network mode is not `bridge`, which means a `podman network connect` call will fail
739
+ // when connecting user defined networks. The workaround is to use a user defined network on container
740
+ // creation.
741
+ //
742
+ // See https://github.com/containers/podman/issues/19577
743
+ //
744
+ // This should not clash with the `host` and `none` networks above, since service creation should have
745
+ // failed when using `host` or `none` networks.
746
+ if ( this . _serviceNetworkId ) {
747
+ // `build` alias: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27060
748
+ dockerCmd += `--network ${ this . _serviceNetworkId } --network-alias build ` ;
749
+ }
730
750
731
751
dockerCmd += `--volume ${ buildVolumeName } :/gcl-builds ` ;
732
752
dockerCmd += `--volume ${ tmpVolumeName } :${ this . fileVariablesDir } ` ;
@@ -784,9 +804,6 @@ export class Job {
784
804
785
805
const { stdout : containerId } = await Utils . bash ( dockerCmd , cwd ) ;
786
806
787
- if ( this . services ?. length ) {
788
- await Utils . spawn ( [ this . argv . containerExecutable , "network" , "connect" , "--alias" , "build" , `gitlab-ci-local-${ this . jobId } ` , `${ containerId } ` ] ) ;
789
- }
790
807
for ( const network of this . argv . network ) {
791
808
// Special network names that do not work with `docker network connect`
792
809
if ( [ "host" , "none" ] . includes ( network ) ) {
@@ -1218,16 +1235,19 @@ export class Job {
1218
1235
}
1219
1236
dockerCmd += `--volume ${ this . buildVolumeName } :/gcl-builds ` ;
1220
1237
dockerCmd += `--volume ${ this . tmpVolumeName } :${ this . fileVariablesDir } ` ;
1221
- dockerCmd += `${ serviceName } ` ;
1222
1238
1223
- // host and none networks have to be specified using --network,
1224
- // since they cannot be used with `docker network connect`.
1225
- for ( const network of this . argv . network ) {
1226
- if ( [ "host" , "none" ] . includes ( network ) ) {
1227
- dockerCmd += `--network ${ network } ` ;
1228
- }
1239
+ // The default podman network mode is not `bridge`, which means a `podman network connect` call will fail
1240
+ // when connecting user defined networks. The workaround is to use a user defined network on container
1241
+ // creation.
1242
+ //
1243
+ // See https://github.com/containers/podman/issues/19577
1244
+ dockerCmd += `--network ${ this . _serviceNetworkId } ` ;
1245
+ for ( const alias of aliases ) {
1246
+ dockerCmd += `--network-alias ${ alias } ` ;
1229
1247
}
1230
1248
1249
+ dockerCmd += `${ serviceName } ` ;
1250
+
1231
1251
if ( serviceEntrypoint ?. length ?? 0 > 1 ) {
1232
1252
serviceEntrypoint ?. slice ( 1 ) . forEach ( ( e ) => {
1233
1253
dockerCmd += `"${ e } " ` ;
@@ -1240,13 +1260,7 @@ export class Job {
1240
1260
const { stdout : containerId } = await Utils . bash ( dockerCmd , cwd ) ;
1241
1261
this . _containersToClean . push ( containerId ) ;
1242
1262
1243
- const aliasArgs = Array . from ( aliases . values ( ) ) . flatMap ( ( alias ) => [ "--alias" , alias ] ) ;
1244
- await Utils . spawn ( [ this . argv . containerExecutable , "network" , "connect" , ...aliasArgs , `gitlab-ci-local-${ this . jobId } ` , `${ containerId } ` ] ) ;
1245
1263
for ( const network of this . argv . network ) {
1246
- // Special network names that do not work with `docker network connect`.
1247
- if ( [ "host" , "none" ] . includes ( network ) ) {
1248
- continue ;
1249
- }
1250
1264
await Utils . spawn ( [ this . argv . containerExecutable , "network" , "connect" , network , `${ containerId } ` ] ) ;
1251
1265
}
1252
1266
@@ -1258,7 +1272,7 @@ export class Job {
1258
1272
return containerId ;
1259
1273
}
1260
1274
1261
- private async serviceHealthCheck ( writeStreams : WriteStreams , service : Service , serviceIndex : number , serviceContanerLogFile : string ) {
1275
+ private async serviceHealthCheck ( writeStreams : WriteStreams , service : Service , serviceIndex : number , serviceContainerLogFile : string ) {
1262
1276
const serviceAlias = service . alias ;
1263
1277
const serviceName = service . name ;
1264
1278
@@ -1284,7 +1298,7 @@ export class Job {
1284
1298
await Promise . any ( Object . keys ( imageInspect [ 0 ] . Config . ExposedPorts ) . map ( ( port ) => {
1285
1299
if ( ! port . endsWith ( "/tcp" ) ) return ;
1286
1300
const portNum = parseInt ( port . replace ( "/tcp" , "" ) ) ;
1287
- const spawnCmd = [ this . argv . containerExecutable , "run" , "--rm" , `--name=gcl-wait-for-it-${ this . jobId } -${ serviceIndex } -${ portNum } ` , "--network" , `gitlab-ci-local- ${ this . jobId } ` , "docker.io/sumina46/wait-for-it" , `${ uniqueAlias } :${ portNum } ` , "-t" , "30" ] ;
1301
+ const spawnCmd = [ this . argv . containerExecutable , "run" , "--rm" , `--name=gcl-wait-for-it-${ this . jobId } -${ serviceIndex } -${ portNum } ` , "--network" , `${ this . _serviceNetworkId } ` , "docker.io/sumina46/wait-for-it" , `${ uniqueAlias } :${ portNum } ` , "-t" , "30" ] ;
1288
1302
return Utils . spawn ( spawnCmd ) ;
1289
1303
} ) ) ;
1290
1304
const endTime = process . hrtime ( time ) ;
@@ -1296,7 +1310,7 @@ export class Job {
1296
1310
singleError . message . split ( / \r ? \n / g) . forEach ( ( line : string ) => {
1297
1311
writeStreams . stdout ( chalk `${ this . formattedJobName } {redBright ${ line } }\n` ) ;
1298
1312
} ) ;
1299
- writeStreams . stdout ( chalk `${ this . formattedJobName } {redBright also see (${ serviceContanerLogFile } )}\n` ) ;
1313
+ writeStreams . stdout ( chalk `${ this . formattedJobName } {redBright also see (${ serviceContainerLogFile } )}\n` ) ;
1300
1314
} ) ;
1301
1315
} finally {
1302
1316
// Kill all wait-for-it containers, when one have been successful
0 commit comments