@@ -8,6 +8,16 @@ import packageInfo from '../package.json';
8
8
9
9
let PACKAGE_INSTALLATION_PATH = `${ __dirname } /../..` ;
10
10
11
+ interface DockerImagesCommandResult {
12
+ images : {
13
+ repository : string ;
14
+ tag : string ;
15
+ 'image id' : string ;
16
+ created : string ;
17
+ size : string ;
18
+ } [ ] ;
19
+ }
20
+
11
21
const dockerCompose : typeof dockerCommand = async ( command , options ) => {
12
22
try {
13
23
return await dockerCommand (
@@ -65,12 +75,32 @@ program.name('ldd').description(packageInfo.description).version(packageInfo.ver
65
75
program
66
76
. command ( 'start' )
67
77
. description ( 'Starts your local DB server' )
68
- . action ( async ( str , options ) => {
78
+ . action ( async ( ) => {
69
79
console . info ( 'Starting local database containers...' ) ;
70
80
81
+ const requiredImages = [
82
+ `mariadb:${ process . env . LDD_DB_IMAGE_TAG ?? 'latest' } ` ,
83
+ `phpmyadmin:${ process . env . LDD_PMA_IMAGE_TAG ?? 'latest' } ` ,
84
+ ] ;
85
+
86
+ const availableImagesImages = ( ( await dockerCommand ( 'images' , { echo : false } ) ) as DockerImagesCommandResult ) . images
87
+ . map ( ( imageData ) => `${ imageData . repository } :${ imageData . tag } ` )
88
+ . filter ( ( imageName ) => requiredImages . includes ( imageName ) ) ;
89
+
90
+ const missingImages = requiredImages . filter ( ( requiredImage ) => ! availableImagesImages . includes ( requiredImage ) ) ;
91
+
92
+ if ( missingImages . length > 0 ) {
93
+ console . info ( '' ) ;
94
+ console . info ( 'The following images will be downloaded as they are required but not available:' ) ;
95
+ missingImages . map ( ( image ) => console . info ( ` - ${ image } ` ) ) ;
96
+ console . info ( '' ) ;
97
+ console . info ( 'This may take some time, please wait...' ) ;
98
+ }
99
+
71
100
await dockerCompose ( 'up -d' ) ;
72
101
73
102
console . info ( '' ) ;
103
+ console . info ( 'Done!' ) ;
74
104
console . info ( `A PhpMyAdmin instance is running on: http://127.0.0.1:${ process . env . LDD_PMA_PORT ?? 8010 } ` ) ;
75
105
} ) ;
76
106
0 commit comments