Skip to content

Commit a53aab7

Browse files
authored
Adding feedback to the "start" command when required images are not available (#2)
1 parent e8ce789 commit a53aab7

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/index.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ import packageInfo from '../package.json';
88

99
let PACKAGE_INSTALLATION_PATH = `${__dirname}/../..`;
1010

11+
interface DockerImagesCommandResult {
12+
images: {
13+
repository: string;
14+
tag: string;
15+
'image id': string;
16+
created: string;
17+
size: string;
18+
}[];
19+
}
20+
1121
const dockerCompose: typeof dockerCommand = async (command, options) => {
1222
try {
1323
return await dockerCommand(
@@ -65,12 +75,32 @@ program.name('ldd').description(packageInfo.description).version(packageInfo.ver
6575
program
6676
.command('start')
6777
.description('Starts your local DB server')
68-
.action(async (str, options) => {
78+
.action(async () => {
6979
console.info('Starting local database containers...');
7080

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+
71100
await dockerCompose('up -d');
72101

73102
console.info('');
103+
console.info('Done!');
74104
console.info(`A PhpMyAdmin instance is running on: http://127.0.0.1:${process.env.LDD_PMA_PORT ?? 8010}`);
75105
});
76106

0 commit comments

Comments
 (0)