@@ -3,9 +3,9 @@ const { execAsyncSpawn } = require('../../../util/exec-async-command');
33
44/**
55 * @param {import('./container-api').ContainerRunOptions } options
6- * @param { import('../../../util/exec-async-command').ExecAsyncSpawnOptions<false> } execOptions
6+ * @returns { string[] }
77 */
8- const run = ( options , execOptions = { } ) => {
8+ const runCommand = ( options ) => {
99 const {
1010 addHost,
1111 ports = [ ] ,
@@ -24,32 +24,35 @@ const run = (options, execOptions = {}) => {
2424 expose = [ ] ,
2525 detach = true ,
2626 rm = false ,
27+ tty = false ,
2728 user
2829 } = options ;
2930
3031 const detachArg = detach && '-d' ;
3132 const rmArg = rm && '--rm' ;
33+ const ttyArg = tty && '-it' ;
3234 const exposeArg = expose && expose . map ( ( e ) => `--expose=${ e } ` ) ;
33- const restartArg = ! rm && restart && `--restart ${ restart } ` ;
34- const networkArg = network && `--network ${ network } ` ;
35- const portsArgs = ports . map ( ( port ) => `-p ${ port } ` ) . join ( ' ' ) ;
36- const mountsArgs = mounts . map ( ( mount ) => `--mount ${ mount } ` ) . join ( ' ' ) ;
37- const mountVolumesArgs = mountVolumes . map ( ( mount ) => `-v ${ mount } ` ) . join ( ' ' ) ;
38- const envArgs = ! env ? '' : Object . entries ( env ) . map ( ( [ key , value ] ) => `--env ${ key } ='${ value } '` ) . join ( ' ' ) ;
39- const nameArg = name && `--name ${ name } ` ;
40- const entrypointArg = entrypoint && `--entrypoint "${ entrypoint } "` ;
41- const healthCheckArg = healthCheck && Object . entries ( healthCheck ) . map ( ( [ key , value ] ) => `--health-${ key } '${ value } '` ) . join ( ' ' ) ;
42- const securityArg = securityOptions . length > 0 && securityOptions . map ( ( opt ) => `--security-opt ${ opt } ` ) . join ( ' ' ) ;
43- const tmpfsArg = tmpfs . length > 0 && tmpfs . map ( ( t ) => `--tmpfs ${ t } ` ) . join ( ' ' ) ;
35+ const restartArg = ! rm && restart && `--restart= ${ restart } ` ;
36+ const networkArg = network && `--network= ${ network } ` ;
37+ const portsArgs = ports && ports . length > 0 && ports . map ( ( port ) => `-p= ${ port } ` ) . join ( ' ' ) ;
38+ const mountsArgs = mounts && mounts . map ( ( mount ) => `--mount= ${ mount } ` ) . join ( ' ' ) ;
39+ const mountVolumesArgs = mountVolumes && mountVolumes . map ( ( mount ) => `-v= ${ mount } ` ) . join ( ' ' ) ;
40+ const envArgs = ! env ? '' : Object . entries ( env ) . map ( ( [ key , value ] ) => `--env= ${ key } ='${ value } '` ) . join ( ' ' ) ;
41+ const nameArg = name && `--name= ${ name } ` ;
42+ const entrypointArg = entrypoint && `--entrypoint= "${ entrypoint } "` ;
43+ const healthCheckArg = healthCheck && Object . entries ( healthCheck ) . map ( ( [ key , value ] ) => `--health-${ key } = '${ value } '` ) . join ( ' ' ) ;
44+ const securityArg = securityOptions . length > 0 && securityOptions . map ( ( opt ) => `--security-opt= ${ opt } ` ) . join ( ' ' ) ;
45+ const tmpfsArg = tmpfs . length > 0 && tmpfs . map ( ( t ) => `--tmpfs= ${ t } ` ) . join ( ' ' ) ;
4446 const userArg = user && `--user=${ user } ` ;
4547 const addHostArg = addHost && `--add-host=${ addHost } ` ;
4648
4749 const dockerCommand = [
4850 'docker' ,
4951 'run' ,
52+ nameArg ,
53+ ttyArg ,
5054 detachArg ,
5155 rmArg ,
52- nameArg ,
5356 networkArg ,
5457 restartArg ,
5558 portsArgs ,
@@ -65,11 +68,17 @@ const run = (options, execOptions = {}) => {
6568 addHostArg ,
6669 image ,
6770 command
68- ] . filter ( Boolean ) . join ( ' ') ;
71+ ] . filter ( Boolean ) . filter ( ( arg ) => typeof arg === 'string ') ;
6972
70- return execAsyncSpawn ( dockerCommand , execOptions ) ;
73+ return dockerCommand ;
7174} ;
7275
76+ /**
77+ * @param {import('./container-api').ContainerRunOptions } options
78+ * @param {import('../../../util/exec-async-command').ExecAsyncSpawnOptions<false> } execOptions
79+ */
80+ const run = ( options , execOptions = { } ) => execAsyncSpawn ( runCommand ( options ) . join ( ' ' ) , execOptions ) ;
81+
7382/**
7483 * @param {string } command
7584 * @param {string } container container id or name
@@ -148,6 +157,7 @@ const ls = async (options = {}, execOptions = {}) => {
148157
149158module . exports = {
150159 run,
160+ runCommand,
151161 exec,
152162 ls
153163} ;
0 commit comments