@@ -2,7 +2,7 @@ import * as k8s from '@kubernetes/client-node'
2
2
import * as fs from 'fs'
3
3
import * as yaml from 'js-yaml'
4
4
import * as core from '@actions/core'
5
- import { Mount } from 'hooklib'
5
+ import { ServiceContainerInfo , Mount } from 'hooklib'
6
6
import * as path from 'path'
7
7
import { v1 as uuidv4 } from 'uuid'
8
8
import { POD_VOLUME_NAME } from './index'
@@ -160,14 +160,28 @@ exec ${environmentPrefix} ${entryPoint} ${
160
160
}
161
161
}
162
162
163
- export function generateContainerName ( image : string ) : string {
163
+ export function generateContainerName ( service : ServiceContainerInfo ) : string {
164
+ const image = service . image
164
165
const nameWithTag = image . split ( '/' ) . pop ( )
165
- const name = nameWithTag ?. split ( ':' ) . at ( 0 )
166
+ let name = nameWithTag ?. split ( ':' ) . at ( 0 )
166
167
167
168
if ( ! name ) {
168
169
throw new Error ( `Image definition '${ image } ' is invalid` )
169
170
}
170
171
172
+ if ( service . createOptions ) {
173
+ const optionsArr = service . createOptions . split ( / [ ] + / )
174
+ for ( let i = 0 ; i < optionsArr . length ; i ++ ) {
175
+ if ( optionsArr [ i ] === '--name' ) {
176
+ if ( i + 1 >= optionsArr . length ) {
177
+ throw new Error ( `Invalid create options: ${ service . createOptions } (missing a value after --name)` )
178
+ }
179
+ name = optionsArr [ ++ i ]
180
+ core . debug ( `Overriding service container name with: ${ name } ` )
181
+ }
182
+ }
183
+ }
184
+
171
185
return name
172
186
}
173
187
0 commit comments