diff --git a/package.json b/package.json index 12f7444..70911f2 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "next dev", - "build": "next build", + "build": "next experimental-compile", "build:image": "docker buildx build -t getashell:testing .", "clean:containers": "docker rm -f $(docker ps -aq)", "clean:keys": "ssh-keygen -f ~/.ssh/known_hosts -R [localhost]:2222", diff --git a/src/app/components/render-shell/render-shell.tsx b/src/app/components/render-shell/render-shell.tsx index e3facc3..cf734b0 100644 --- a/src/app/components/render-shell/render-shell.tsx +++ b/src/app/components/render-shell/render-shell.tsx @@ -1,6 +1,6 @@ "use client"; -import { remove } from "@/server/actions/remove-actions"; +import { remove } from "@/server/actions/remove-action"; import { containerData } from "@/server/types/types"; import { Card, Flex, Text, Button } from "@radix-ui/themes"; import { toast } from "react-toastify"; diff --git a/src/server/actions/remove-actions.ts b/src/server/actions/remove-action.ts similarity index 100% rename from src/server/actions/remove-actions.ts rename to src/server/actions/remove-action.ts diff --git a/src/server/config/config.ts b/src/server/config/config.ts new file mode 100644 index 0000000..1a0473c --- /dev/null +++ b/src/server/config/config.ts @@ -0,0 +1,22 @@ +const env = process.env.NODE_ENV; + +export const getConfig = () => { + let migrationDir = ""; + let dataDir = ""; + let databasePath = ""; + let ncHost = ""; + + if (env == "development") { + migrationDir = "migrations"; + dataDir = "data"; + databasePath = "data/sqlite.db"; + ncHost = "127.0.0.1"; + } else if (env == "production") { + migrationDir = "/app/migrations"; + dataDir = "/app/data"; + databasePath = "/app/data/sqlite.db"; + ncHost = "host.docker.internal"; + } + + return { migrationDir, dataDir, databasePath, ncHost }; +}; diff --git a/src/server/db/db.ts b/src/server/db/db.ts index d7410ca..3ab29ba 100644 --- a/src/server/db/db.ts +++ b/src/server/db/db.ts @@ -6,9 +6,12 @@ import Database from "better-sqlite3"; import * as schema from "./schema"; import * as fs from "fs"; import { migrateDb } from "./migrator"; +import { getConfig } from "../config/config"; -if (!fs.existsSync("/app/data")) { - fs.mkdirSync("/app/data"); +const { databasePath, dataDir } = getConfig(); + +if (!fs.existsSync(dataDir)) { + fs.mkdirSync(dataDir); } console.log("Running database migrations..."); @@ -17,7 +20,7 @@ migrateDb(); console.log("Migrations finished! Connecting to databse..."); -const sqlite = new Database("/app/data/sqlite.db"); +const sqlite = new Database(databasePath); export const db: BetterSQLite3Database = drizzle(sqlite, { schema, diff --git a/src/server/db/migrator.ts b/src/server/db/migrator.ts index d4790bc..0281e31 100644 --- a/src/server/db/migrator.ts +++ b/src/server/db/migrator.ts @@ -1,12 +1,15 @@ import { drizzle } from "drizzle-orm/better-sqlite3"; import { migrate } from "drizzle-orm/better-sqlite3/migrator"; import Database from "better-sqlite3"; +import { getConfig } from "../config/config"; export const migrateDb = () => { - const betterSqlite = new Database("/app/data/sqlite.db"); + const { databasePath, migrationDir } = getConfig(); + + const betterSqlite = new Database(databasePath); const db = drizzle(betterSqlite); - migrate(db, { migrationsFolder: "/app/migrations" }); + migrate(db, { migrationsFolder: migrationDir }); betterSqlite.close(); }; diff --git a/src/server/utils/port-checker.ts b/src/server/utils/port-checker.ts index e8daa12..33d2a25 100644 --- a/src/server/utils/port-checker.ts +++ b/src/server/utils/port-checker.ts @@ -1,15 +1,17 @@ import { exec as execCallback } from "child_process"; import * as util from "util"; +import { getConfig } from "../config/config"; const exec = util.promisify(execCallback); export const availablePortChecker = async (port: number) => { try { + const { ncHost } = getConfig(); const { stdout: tcpStdout, stderr: tcpStderr } = await exec( - `nc -zv host.docker.internal ${port}`, + `nc -zv ${ncHost} ${port}`, ); const { stdout: udpStdout, stderr: udpStderr } = await exec( - `nc -zuv host.docker.internal ${port}`, + `nc -zuv ${ncHost} ${port}`, ); return { success: false,