fix(worker): docker not throwing an error when failing to start

This commit is contained in:
Nicolas Meienberger 2023-11-15 18:48:08 +01:00 committed by Nicolas Meienberger
parent af8509aacc
commit bdfb019df2
7 changed files with 11 additions and 57 deletions

5
.gitignore vendored
View file

@ -54,9 +54,7 @@ node_modules/
/data/ /data/
/repos/ /repos/
/apps/ /apps/
traefik/shared /traefik/
traefik/tls
./traefik/
# media folder # media folder
media media
@ -68,3 +66,4 @@ media
temp temp
./traefik/ ./traefik/
/user-config/

View file

@ -11,7 +11,7 @@
"test:client": "jest --colors --selectProjects client --", "test:client": "jest --colors --selectProjects client --",
"test:server": "jest --colors --selectProjects server --", "test:server": "jest --colors --selectProjects server --",
"test:vite": "dotenv -e .env.test -- vitest run --coverage", "test:vite": "dotenv -e .env.test -- vitest run --coverage",
"dev": "npm run db:migrate && next dev", "dev": "next dev",
"dev:watcher": "pnpm -r --filter cli dev", "dev:watcher": "pnpm -r --filter cli dev",
"db:migrate": "NODE_ENV=development dotenv -e .env.local -- tsx ./src/server/run-migrations-dev.ts", "db:migrate": "NODE_ENV=development dotenv -e .env.local -- tsx ./src/server/run-migrations-dev.ts",
"lint": "next lint", "lint": "next lint",

View file

@ -41,47 +41,6 @@ export class SystemExecutors {
return { success: false, message: `An error occurred: ${err}` }; return { success: false, message: `An error occurred: ${err}` };
}; };
// private ensureFilePermissions = async (rootFolderHost: string) => {
// const logger = new TerminalSpinner('');
// const filesAndFolders = [
// path.join(rootFolderHost, 'apps'),
// path.join(rootFolderHost, 'logs'),
// path.join(rootFolderHost, 'repos'),
// path.join(rootFolderHost, 'state'),
// path.join(rootFolderHost, 'traefik'),
// path.join(rootFolderHost, '.env'),
// path.join(rootFolderHost, 'VERSION'),
// path.join(rootFolderHost, 'docker-compose.yml'),
// ];
// const files600 = [path.join(rootFolderHost, 'traefik', 'shared', 'acme.json')];
// this.logger.info('Setting file permissions a+rwx on required files');
// // Give permission to read and write to all files and folders for the current user
// for (const fileOrFolder of filesAndFolders) {
// if (await pathExists(fileOrFolder)) {
// this.logger.info(`Setting permissions on ${fileOrFolder}`);
// await execAsync(`chmod -R a+rwx ${fileOrFolder}`).catch(() => {
// logger.fail(`Failed to set permissions on ${fileOrFolder}`);
// });
// this.logger.info(`Successfully set permissions on ${fileOrFolder}`);
// }
// }
// this.logger.info('Setting file permissions 600 on required files');
// for (const fileOrFolder of files600) {
// if (await pathExists(fileOrFolder)) {
// this.logger.info(`Setting permissions on ${fileOrFolder}`);
// await execAsync(`chmod 600 ${fileOrFolder}`).catch(() => {
// logger.fail(`Failed to set permissions on ${fileOrFolder}`);
// });
// this.logger.info(`Successfully set permissions on ${fileOrFolder}`);
// }
// }
// };
public cleanLogs = async () => { public cleanLogs = async () => {
try { try {
await this.logger.flush(); await this.logger.flush();

View file

@ -9,7 +9,8 @@
"build": "node build.js", "build": "node build.js",
"tsc": "tsc", "tsc": "tsc",
"dev": "dotenv -e ../../.env nodemon", "dev": "dotenv -e ../../.env nodemon",
"knip": "knip" "knip": "knip",
"lint": "eslint . --ext .ts"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",

View file

@ -8,6 +8,10 @@ const composeUp = async (args: string[]) => {
logger.info(`Running docker compose with args ${args.join(' ')}`); logger.info(`Running docker compose with args ${args.join(' ')}`);
const { stdout, stderr } = await execAsync(`docker compose ${args.join(' ')}`); const { stdout, stderr } = await execAsync(`docker compose ${args.join(' ')}`);
if (stderr && stderr.includes('Command failed:')) {
throw new Error(stderr);
}
return { stdout, stderr }; return { stdout, stderr };
}; };

View file

@ -130,12 +130,7 @@ export class AppExecutors {
// run docker-compose up // run docker-compose up
this.logger.info(`Running docker-compose up for app ${appId}`); this.logger.info(`Running docker-compose up for app ${appId}`);
const { stderr } = await compose(appId, 'up -d'); await compose(appId, 'up -d');
if (stderr) {
this.logger.error(`Error running docker-compose up for app ${appId}: ${stderr}`);
return { success: false, message: `Error running docker-compose up for app ${appId}: ${stderr}` };
}
this.logger.info(`Docker-compose up for app ${appId} finished`); this.logger.info(`Docker-compose up for app ${appId} finished`);

View file

@ -87,11 +87,7 @@ export class RepoExecutors {
}); });
this.logger.info(`Executing: git -C ${repoPath} fetch origin && git -C ${repoPath} reset --hard origin/${currentBranch}`); this.logger.info(`Executing: git -C ${repoPath} fetch origin && git -C ${repoPath} reset --hard origin/${currentBranch}`);
await execAsync(`git -C ${repoPath} fetch origin && git -C ${repoPath} reset --hard origin/${currentBranch}`).then(({ stderr }) => { await execAsync(`git -C ${repoPath} fetch origin && git -C ${repoPath} reset --hard origin/${currentBranch}`);
if (stderr) {
this.logger.error(`stderr: ${stderr}`);
}
});
this.logger.info(`Pulled repo ${repoUrl} to ${repoPath}`); this.logger.info(`Pulled repo ${repoUrl} to ${repoPath}`);
return { success: true, message: '' }; return { success: true, message: '' };