From 3537b842ec6dd830d9f8618904809a67973cb28c Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Mon, 4 Dec 2023 15:59:01 +0800 Subject: [PATCH] Update --- backend/dockge-server.ts | 2 ++ backend/stack.ts | 9 +++++++++ package.json | 1 + pnpm-lock.yaml | 8 ++++++++ 4 files changed, 20 insertions(+) diff --git a/backend/dockge-server.ts b/backend/dockge-server.ts index 9d06782..93061f3 100644 --- a/backend/dockge-server.ts +++ b/backend/dockge-server.ts @@ -32,6 +32,8 @@ import User from "./models/user"; import childProcessAsync from "promisify-child-process"; import { Terminal } from "./terminal"; +import "dotenv/config"; + export class DockgeServer { app : Express; httpServer : http.Server; diff --git a/backend/stack.ts b/backend/stack.ts index f592fcc..38466f5 100644 --- a/backend/stack.ts +++ b/backend/stack.ts @@ -99,6 +99,15 @@ export class Stack { // Check YAML format yaml.parse(this.composeYAML); + + let lines = this.composeENV.split("\n"); + + // Check if the .env is able to pass docker-compose + // Prevent "setenv: The parameter is incorrect" + // It only happens when there is one line and it doesn't contain "=" + if (lines.length === 1 && !lines[0].includes("=")) { + throw new ValidationError("Invalid .env format"); + } } get composeYAML() : string { diff --git a/package.json b/package.json index 69c29f2..73b10ed 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "composerize": "~1.4.1", "croner": "~7.0.5", "dayjs": "~1.11.10", + "dotenv": "~16.3.1", "express": "~4.18.2", "express-static-gzip": "~2.1.7", "http-graceful-shutdown": "~3.1.13", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c25b72e..c11d267 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,6 +32,9 @@ dependencies: dayjs: specifier: ~1.11.10 version: 1.11.10 + dotenv: + specifier: ~16.3.1 + version: 16.3.1 express: specifier: ~4.18.2 version: 4.18.2 @@ -2154,6 +2157,11 @@ packages: esutils: 2.0.3 dev: true + /dotenv@16.3.1: + resolution: {integrity: sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==} + engines: {node: '>=12'} + dev: false + /eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} dev: false