@@ -55,6 +55,7 @@ const CliUi = () => {
5555 const db_pass = process . env [ 'DB_PASS' ] ;
5656 const redis_port = process . env [ 'REDIS_PORT' ] ;
5757 const redis_host = process . env [ 'REDIS_HOST' ] ;
58+ const services_started = process . env [ 'SERVICES_STARTED' ] ;
5859
5960 const preCheck = usePreCheck ( {
6061 db : Number ( db_port ) ,
@@ -106,21 +107,22 @@ const CliUi = () => {
106107 exit ( ) ;
107108 }
108109 await dispatch ( appSlice . actions . setAppState ( AppStates . TEARDOWN ) ) ;
109- setTimeout ( ( ) => {
110- if ( ! processRef . current ) return ;
111-
110+ if ( processRef . current ) {
112111 processRef . current . kill ( ) ;
113112 processRef . current . stdout . destroy ( ) ;
114113 processRef . current . stderr . destroy ( ) ;
114+ await new Promise ( ( r ) => setTimeout ( r , 50 ) ) ;
115+ }
116+ // dont depend on processRef.current here, as it might be null
117+ // so always do a docker compose down irrespective of processRef.current
118+ try {
119+ await runCommand ( 'docker' , [ 'compose' , 'down' ] , runCommandOpts ) . promise ;
120+ } catch {
121+ await runCommand ( 'docker-compose' , [ 'down' ] , runCommandOpts ) . promise ;
122+ }
115123
116- runCommand ( 'docker' , [ 'compose' , 'down' ] , runCommandOpts )
117- . promise . catch ( async ( err : any ) => {
118- await runCommand ( 'docker-compose' , [ 'down' ] ) . promise ;
119- } )
120- . finally ( async ( ) => {
121- await dispatch ( appSlice . actions . setAppState ( AppStates . TERMINATED ) ) ;
122- } ) ;
123- } , 200 ) ;
124+ await dispatch ( appSlice . actions . setAppState ( AppStates . TERMINATED ) ) ;
125+ exit ( ) ;
124126 } , [ appState , dispatch , runCommandOpts ] ) ;
125127
126128 const handleVersionUpdates = useCallback ( async ( ) => {
@@ -169,11 +171,32 @@ const CliUi = () => {
169171 useEffect ( ( ) => {
170172 if ( Object . values ( preCheck ) . includes ( PreCheckStates . RUNNING ) ) {
171173 return ;
172- } else {
173- if ( Object . values ( preCheck ) . includes ( PreCheckStates . FAILED ) ) {
174- handleExit ( ) ;
175- return ;
176- }
174+ }
175+ /*
176+ just a reminder that we make the ports check for optimizing hot reloading
177+ so a FAILED port check shall imply that some ports are already in use
178+ if the ports are already in use, we will not start the services
179+ FAILING the ports check will not stop the app from starting, because the assumption is that
180+ the user has already started the services and they are running
181+ */
182+
183+ if (
184+ preCheck . ports === PreCheckStates . FAILED &&
185+ services_started === 'true'
186+ ) {
187+ dispatch ( appSlice . actions . setAppState ( AppStates . DOCKER_READY ) ) ;
188+ dispatch ( appSlice . actions . updateReadyServices ( LogSource . WebServer ) ) ;
189+ dispatch ( appSlice . actions . updateReadyServices ( LogSource . ApiServer ) ) ;
190+ dispatch ( appSlice . actions . updateReadyServices ( LogSource . SyncServer ) ) ;
191+ dispatch ( appSlice . actions . updateReadyServices ( LogSource . Postgres ) ) ;
192+ dispatch ( appSlice . actions . updateReadyServices ( LogSource . InitDb ) ) ;
193+ dispatch ( appSlice . actions . updateReadyServices ( LogSource . Redis ) ) ;
194+ return ;
195+ }
196+
197+ if ( Object . values ( preCheck ) . includes ( PreCheckStates . FAILED ) ) {
198+ handleExit ( ) ;
199+ return ;
177200 }
178201
179202 dispatch ( appSlice . actions . setAppState ( AppStates . INIT ) ) ;
@@ -197,6 +220,8 @@ const CliUi = () => {
197220 } )
198221 ) ;
199222 } ) ;
223+ // set the env variable APP_STARTED to true
224+ globalThis . process . env [ 'SERVICES_STARTED' ] = 'true' ;
200225 } )
201226 . catch ( async ( err : any ) => {
202227 await runCommand ( 'docker-compose' , [ 'down' ] ) . promise ;
@@ -406,13 +431,6 @@ const CliUi = () => {
406431 'Docker daemon is not running, please ensure it is running. To check if your docker daemon is running, use the command: \ndocker info'
407432 }
408433 />
409- < PreCheckDisplayElement
410- value = { preCheck . ports }
411- property = { PreCheckProperties . PORTS }
412- errHelp = {
413- 'One of the ports is not free. Please ensure that all the specified ports in dockerfile.dev are free.'
414- }
415- />
416434 < PreCheckDisplayElement
417435 value = { preCheck . composeFile }
418436 property = { PreCheckProperties . COMPOSE_FILE }
0 commit comments