@@ -11,15 +11,14 @@ import {
11
11
} from '../../services' ;
12
12
import {
13
13
DEFAULT_CONFIGURATION_ID ,
14
- FLAGS ,
15
14
PRO_IMAGE ,
16
15
COMMUNITY_IMAGE ,
16
+ FLAGS_AS_STRING ,
17
17
} from '../../constants' ;
18
18
import { LongMenu } from './Menu' ;
19
19
import { DockerContainer , DockerImage } from '../../types' ;
20
20
import { DownloadProgressDialog } from '../Feedback/DownloadProgressDialog' ;
21
21
import { ProgressButton } from '../Feedback' ;
22
- import { generateCLIArgs } from '../../services/util/cli' ;
23
22
24
23
const EXCLUDED_ERROR_TOAST = [ 'INFO' , 'WARN' , 'DEBUG' ] ;
25
24
@@ -31,7 +30,7 @@ export const Controller = (): ReactElement => {
31
30
const [ downloadProps , setDownloadProps ] = useState ( { open : false , image : COMMUNITY_IMAGE } ) ;
32
31
const [ isStarting , setIsStarting ] = useState < boolean > ( false ) ;
33
32
const [ isStopping , setIsStopping ] = useState < boolean > ( false ) ;
34
- const ddClient = useDDClient ( ) ;
33
+ const { client : ddClient , getBinary } = useDDClient ( ) ;
35
34
const isRunning = data && data . State === 'running' ;
36
35
const isUnhealthy = data && data . Status . includes ( 'unhealthy' ) ;
37
36
const tooltipLabel = isUnhealthy ? 'Unhealthy' : 'Healthy' ;
@@ -48,52 +47,44 @@ export const Controller = (): ReactElement => {
48
47
}
49
48
} , [ isLoading ] ) ;
50
49
51
- const buildHostArgs = ( ) => {
52
- let location = 'LOCALSTACK_VOLUME_DIR=/tmp/localstack/volume' ;
53
- let homeDir = `HOME=/home/${ user } ` ;
50
+ const buildHostArgs = ( ) : NodeJS . ProcessEnv => {
51
+ let location = '/tmp/localstack/volume' ;
54
52
55
53
if ( ! hasSkippedConfiguration ) {
56
54
switch ( ddClient . host . platform ) {
57
55
case 'win32' :
58
- location = `LOCALSTACK_VOLUME_DIR=\\\\wsl$\\${ os } \\home\\${ user } \\.cache\\localstack\\volume` ;
59
- homeDir = `HOME=\\\\wsl$\\${ os } \\home\\${ user } ` ;
56
+ location = `\\\\wsl$\\${ os } \\home\\${ user } \\.cache\\localstack\\volume` ;
60
57
break ;
61
58
case 'darwin' :
62
- location = `LOCALSTACK_VOLUME_DIR=/Users/${ user } /Library/Caches/localstack/volume` ;
63
- homeDir = `HOME=/Users/${ user } ` ;
59
+ location = `/Users/${ user } /Library/Caches/localstack/volume` ;
64
60
break ;
65
61
default :
66
- location = `LOCALSTACK_VOLUME_DIR=/home/${ user } /.cache/localstack/volume` ;
67
- homeDir = `HOME=/home/${ user } ` ;
62
+ location = `/home/${ user } /.cache/localstack/volume` ;
68
63
}
69
64
}
70
- return [ '-e' , location , '-e' , homeDir ] ;
65
+ return { LOCALSTACK_VOLUME_DIR : location } ;
71
66
} ;
72
67
73
- const normalizeArguments = async ( ) => {
74
- const extendedFlag = FLAGS . map ( x => x ) ; // clone
75
- let isPro = false ;
68
+ const normalizeArguments = ( ) : NodeJS . ProcessEnv => {
76
69
const addedArgs = configData . configs . find ( config => config . id === runningConfig )
77
70
. vars . map ( item => {
78
71
if ( item . variable === 'DOCKER_FLAGS' ) {
79
- extendedFlag [ 1 ] = FLAGS . at ( 1 ) . slice ( 0 , - 1 ) . concat ( ` ${ item . value } '` ) ;
80
- }
81
- if ( item . variable === 'LOCALSTACK_AUTH_TOKEN' ) {
82
- isPro = true ;
72
+ return { [ item . variable ] : `${ FLAGS_AS_STRING } ${ item . value } ` } ;
83
73
}
84
74
85
- return [ '-e' , ` ${ item . variable } = ${ item . value } ` ] ;
86
- } ) . flat ( ) ;
75
+ return { [ item . variable ] : item . value } ;
76
+ } ) ;
87
77
88
- return [
89
- ...extendedFlag ,
90
- ...buildHostArgs ( ) ,
91
- ...addedArgs ,
92
- ...generateCLIArgs ( { call : 'start' , pro : isPro } ) ,
93
- ] ;
78
+ return [ ...addedArgs , buildHostArgs ( ) ] . reduce ( ( acc , obj ) => {
79
+ const [ key , value ] = Object . entries ( obj ) [ 0 ] ;
80
+ acc [ key ] = value ;
81
+ return acc ;
82
+ } , { } as NodeJS . ProcessEnv ) ;
94
83
} ;
95
84
96
85
const start = async ( ) => {
86
+ setIsStarting ( true ) ;
87
+
97
88
const images = await ddClient . docker . listImages ( ) as [ DockerImage ] ;
98
89
99
90
const isPro = configData . configs . find ( config => config . id === runningConfig )
@@ -112,10 +103,16 @@ export const Controller = (): ReactElement => {
112
103
return ;
113
104
}
114
105
115
- const args = await normalizeArguments ( ) ;
106
+ const args = normalizeArguments ( ) ;
107
+
108
+ const binary = getBinary ( ) ;
109
+ if ( ! binary ) {
110
+ setIsStarting ( false ) ;
111
+ return ;
112
+ }
116
113
117
- setIsStarting ( true ) ;
118
- ddClient . docker . cli . exec ( 'run' , args , {
114
+ ddClient . extension . host ?. cli . exec ( binary , [ 'start' , '--no-banner' , '-d' ] , {
115
+ env : args ,
119
116
stream : {
120
117
onOutput ( data ) : void {
121
118
const shouldDisplayError = ! EXCLUDED_ERROR_TOAST . some ( item => data . stderr ?. includes ( item ) ) && data . stderr ;
0 commit comments