From bdfb019df27906c07f0bec180dc52e0a9dfe89dc Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Wed, 15 Nov 2023 18:48:08 +0100 Subject: [PATCH] fix(worker): docker not throwing an error when failing to start --- .gitignore | 5 +-- package.json | 2 +- .../src/executors/system/system.executors.ts | 41 ------------------- packages/worker/package.json | 3 +- .../worker/src/lib/docker/docker-helpers.ts | 4 ++ .../worker/src/services/app/app.executors.ts | 7 +--- .../src/services/repo/repo.executors.ts | 6 +-- 7 files changed, 11 insertions(+), 57 deletions(-) diff --git a/.gitignore b/.gitignore index 6133b114..6765c17b 100644 --- a/.gitignore +++ b/.gitignore @@ -54,9 +54,7 @@ node_modules/ /data/ /repos/ /apps/ -traefik/shared -traefik/tls -./traefik/ +/traefik/ # media folder media @@ -68,3 +66,4 @@ media temp ./traefik/ +/user-config/ diff --git a/package.json b/package.json index f8c87bf3..c516d57d 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "test:client": "jest --colors --selectProjects client --", "test:server": "jest --colors --selectProjects server --", "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", "db:migrate": "NODE_ENV=development dotenv -e .env.local -- tsx ./src/server/run-migrations-dev.ts", "lint": "next lint", diff --git a/packages/cli/src/executors/system/system.executors.ts b/packages/cli/src/executors/system/system.executors.ts index 65f26a22..5dffeda1 100644 --- a/packages/cli/src/executors/system/system.executors.ts +++ b/packages/cli/src/executors/system/system.executors.ts @@ -41,47 +41,6 @@ export class SystemExecutors { 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 () => { try { await this.logger.flush(); diff --git a/packages/worker/package.json b/packages/worker/package.json index 66fe4ae6..e6f8d464 100644 --- a/packages/worker/package.json +++ b/packages/worker/package.json @@ -9,7 +9,8 @@ "build": "node build.js", "tsc": "tsc", "dev": "dotenv -e ../../.env nodemon", - "knip": "knip" + "knip": "knip", + "lint": "eslint . --ext .ts" }, "keywords": [], "author": "", diff --git a/packages/worker/src/lib/docker/docker-helpers.ts b/packages/worker/src/lib/docker/docker-helpers.ts index 437e29c5..cacba19f 100644 --- a/packages/worker/src/lib/docker/docker-helpers.ts +++ b/packages/worker/src/lib/docker/docker-helpers.ts @@ -8,6 +8,10 @@ const composeUp = async (args: string[]) => { logger.info(`Running docker compose with args ${args.join(' ')}`); const { stdout, stderr } = await execAsync(`docker compose ${args.join(' ')}`); + if (stderr && stderr.includes('Command failed:')) { + throw new Error(stderr); + } + return { stdout, stderr }; }; diff --git a/packages/worker/src/services/app/app.executors.ts b/packages/worker/src/services/app/app.executors.ts index 09d7efdb..4cc609bf 100644 --- a/packages/worker/src/services/app/app.executors.ts +++ b/packages/worker/src/services/app/app.executors.ts @@ -130,12 +130,7 @@ export class AppExecutors { // run docker-compose up this.logger.info(`Running docker-compose up for app ${appId}`); - const { stderr } = 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}` }; - } + await compose(appId, 'up -d'); this.logger.info(`Docker-compose up for app ${appId} finished`); diff --git a/packages/worker/src/services/repo/repo.executors.ts b/packages/worker/src/services/repo/repo.executors.ts index bb9fc60b..c5287fc7 100644 --- a/packages/worker/src/services/repo/repo.executors.ts +++ b/packages/worker/src/services/repo/repo.executors.ts @@ -87,11 +87,7 @@ export class RepoExecutors { }); 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 }) => { - if (stderr) { - this.logger.error(`stderr: ${stderr}`); - } - }); + await execAsync(`git -C ${repoPath} fetch origin && git -C ${repoPath} reset --hard origin/${currentBranch}`); this.logger.info(`Pulled repo ${repoUrl} to ${repoPath}`); return { success: true, message: '' };