From af98610d0d87cdba480eb34a634cbbd0820e9be2 Mon Sep 17 00:00:00 2001 From: miloschwartz Date: Wed, 4 Jun 2025 17:15:11 -0400 Subject: [PATCH 1/2] fix migration number and add allowed_headers migration --- server/setup/migrationsSqlite.ts | 4 +- server/setup/scriptsSqlite/1.4.0.ts | 29 ------------ server/setup/scriptsSqlite/1.5.0.ts | 72 +++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 31 deletions(-) delete mode 100644 server/setup/scriptsSqlite/1.4.0.ts create mode 100644 server/setup/scriptsSqlite/1.5.0.ts diff --git a/server/setup/migrationsSqlite.ts b/server/setup/migrationsSqlite.ts index 5c705e26..36b87de2 100644 --- a/server/setup/migrationsSqlite.ts +++ b/server/setup/migrationsSqlite.ts @@ -20,7 +20,7 @@ import m16 from "./scriptsSqlite/1.0.0"; import m17 from "./scriptsSqlite/1.1.0"; import m18 from "./scriptsSqlite/1.2.0"; import m19 from "./scriptsSqlite/1.3.0"; -import m20 from "./scriptsSqlite/1.3.0"; +import m20 from "./scriptsSqlite/1.5.0"; // THIS CANNOT IMPORT ANYTHING FROM THE SERVER // EXCEPT FOR THE DATABASE AND THE SCHEMA @@ -41,7 +41,7 @@ const migrations = [ { version: "1.1.0", run: m17 }, { version: "1.2.0", run: m18 }, { version: "1.3.0", run: m19 }, - { version: "1.4.0", run: m20 }, + { version: "1.5.0", run: m20 }, // Add new migrations here as they are created ] as const; diff --git a/server/setup/scriptsSqlite/1.4.0.ts b/server/setup/scriptsSqlite/1.4.0.ts deleted file mode 100644 index 24a2f2fc..00000000 --- a/server/setup/scriptsSqlite/1.4.0.ts +++ /dev/null @@ -1,29 +0,0 @@ -import Database from "better-sqlite3"; -import path from "path"; -import { encodeBase32LowerCaseNoPadding } from "@oslojs/encoding"; -import { APP_PATH, configFilePath1, configFilePath2 } from "@server/lib/consts"; - -const version = "1.4.0"; -const location = path.join(APP_PATH, "db", "db.sqlite"); - -export default async function migration() { - console.log(`Running setup script ${version}...`); - - const db = new Database(location); - - try { - db.pragma("foreign_keys = OFF"); - db.transaction(() => { - db.exec(` - ALTER TABLE 'sites' ADD 'dockerSocketEnabled' integer DEFAULT true NOT NULL; - `); - })(); // <-- executes the transaction immediately - db.pragma("foreign_keys = ON"); - console.log(`Migrated database schema`); - } catch (e) { - console.log("Unable to migrate database schema"); - throw e; - } - - console.log(`${version} migration complete`); -} \ No newline at end of file diff --git a/server/setup/scriptsSqlite/1.5.0.ts b/server/setup/scriptsSqlite/1.5.0.ts new file mode 100644 index 00000000..e362cb15 --- /dev/null +++ b/server/setup/scriptsSqlite/1.5.0.ts @@ -0,0 +1,72 @@ +import Database from "better-sqlite3"; +import path from "path"; +import { APP_PATH, configFilePath1, configFilePath2 } from "@server/lib/consts"; +import fs from "fs"; +import yaml from "js-yaml"; + +const version = "1.5.0"; +const location = path.join(APP_PATH, "db", "db.sqlite"); + +export default async function migration() { + console.log(`Running setup script ${version}...`); + + const db = new Database(location); + + try { + db.pragma("foreign_keys = OFF"); + db.transaction(() => { + db.exec(` + ALTER TABLE 'sites' ADD 'dockerSocketEnabled' integer DEFAULT true NOT NULL; + `); + })(); // <-- executes the transaction immediately + db.pragma("foreign_keys = ON"); + console.log(`Migrated database schema`); + } catch (e) { + console.log("Unable to migrate database schema"); + throw e; + } + + try { + // Determine which config file exists + const filePaths = [configFilePath1, configFilePath2]; + let filePath = ""; + for (const path of filePaths) { + if (fs.existsSync(path)) { + filePath = path; + break; + } + } + + if (!filePath) { + throw new Error( + `No config file found (expected config.yml or config.yaml).` + ); + } + + // Read and parse the YAML file + let rawConfig: any; + const fileContents = fs.readFileSync(filePath, "utf8"); + rawConfig = yaml.load(fileContents); + + if (rawConfig.cors?.headers) { + const headers = JSON.parse( + JSON.stringify(rawConfig.cors.headers) + ); + rawConfig.cors.allowed_headers = headers; + delete rawConfig.cors.headers; + } + + // Write the updated YAML back to the file + const updatedYaml = yaml.dump(rawConfig); + fs.writeFileSync(filePath, updatedYaml, "utf8"); + + console.log(`Migrated CORS headers to allowed_headers`); + } catch (e) { + console.log( + `Unable to migrate config file. Error: ${e}` + ); + throw e; + } + + console.log(`${version} migration complete`); +} From 8c5f00a4465d62119dde19e0d0feca45e93eb051 Mon Sep 17 00:00:00 2001 From: miloschwartz Date: Wed, 4 Jun 2025 17:17:18 -0400 Subject: [PATCH 2/2] remove .sqlite from Dockerfile --- Dockerfile | 37 +++++++++++++++++++++++++++++++++++++ Makefile | 4 ++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..adfe2597 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +FROM node:20-alpine AS builder + +WORKDIR /app + +# COPY package.json package-lock.json ./ +COPY package.json ./ +RUN npm install + +COPY . . + +RUN echo 'export * from "./sqlite";' > server/db/index.ts + +RUN npx drizzle-kit generate --dialect sqlite --schema ./server/db/sqlite/schema.ts --out init + +RUN npm run build:sqlite + +FROM node:20-alpine AS runner + +WORKDIR /app + +# Curl used for the health checks +RUN apk add --no-cache curl + +# COPY package.json package-lock.json ./ +COPY package.json ./ +RUN npm install --only=production && npm cache clean --force + +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static +COPY --from=builder /app/dist ./dist +COPY --from=builder /app/init ./dist/init + +COPY server/db/names.json ./dist/names.json + +COPY public ./public + +CMD ["npm", "run", "start:sqlite"] diff --git a/Makefile b/Makefile index d20bebd4..fdf5daa1 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,8 @@ build-release: echo "Error: tag is required. Usage: make build-all tag="; \ exit 1; \ fi - docker buildx build --platform linux/arm64,linux/amd64 -t fosrl/pangolin:latest -f Dockerfile.sqlite --push . - docker buildx build --platform linux/arm64,linux/amd64 -t fosrl/pangolin:$(tag) -f Dockerfile.sqlite --push . + docker buildx build --platform linux/arm64,linux/amd64 -t fosrl/pangolin:latest -f Dockerfile --push . + docker buildx build --platform linux/arm64,linux/amd64 -t fosrl/pangolin:$(tag) -f Dockerfile --push . docker buildx build --platform linux/arm64,linux/amd64 -t fosrl/pangolin:postgresql-latest -f Dockerfile.pg --push . docker buildx build --platform linux/arm64,linux/amd64 -t fosrl/pangolin:postgresql-$(tag) -f Dockerfile.pg --push .