shell: add explicit bash() function

This commit is contained in:
Girish Ramakrishnan
2024-10-16 10:25:07 +02:00
parent d66db8ca40
commit df5ba25010
10 changed files with 46 additions and 63 deletions
+7 -3
View File
@@ -50,7 +50,7 @@ async function pruneInfraImages() {
// cannot blindly remove all unused images since redis image may not be used
const imageNames = Object.keys(infra.images).map(addon => infra.images[addon]);
const [error, output] = await safe(shell.exec('docker images --digests --format "{{.ID}} {{.Repository}} {{.Tag}} {{.Digest}}"', { shell: '/bin/bash' }));
const [error, output] = await safe(shell.bash('docker images --digests --format "{{.ID}} {{.Repository}} {{.Tag}} {{.Digest}}"', { encoding: 'utf8' }));
if (error) {
debug(`Failed to list images ${error.message}`);
throw error;
@@ -95,8 +95,12 @@ async function createDockerNetwork() {
async function removeAllContainers() {
debug('removeAllContainers: removing all containers for infra upgrade');
await shell.exec('docker ps -qa --filter \'label=isCloudronManaged\' | xargs --no-run-if-empty docker stop', { shell: '/bin/bash' });
await shell.exec('docker ps -qa --filter \'label=isCloudronManaged\' | xargs --no-run-if-empty docker rm -f', { shell: '/bin/bash' });
const output = await shell.spawn('docker', ['ps', '-qa', '--filter', 'label=isCloudronManaged'], { encoding: 'utf8' });
for (const containerId of output.trim().split('\n')) {
debug(`removeAllContainers: stopping and removing ${containerId}`);
await shell.spawn('docker', ['stop', containerId], {});
await shell.spawn('docker', ['rm', '-f', containerId], {});
}
}
async function markApps(existingInfra, restoreOptions) {