mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-25 13:15:02 +02:00
prep migration for release
This commit is contained in:
parent
bdf72662bf
commit
5ce6cb01ff
6 changed files with 107 additions and 25 deletions
|
@ -4,7 +4,13 @@ api:
|
||||||
|
|
||||||
providers:
|
providers:
|
||||||
http:
|
http:
|
||||||
endpoint: "http://pangolin:{{.INTERNAL_PORT}}/api/v1/traefik-config"
|
endpoint: "http://pangolin:3001/api/v1/traefik-config/http"
|
||||||
|
pollInterval: "5s"
|
||||||
|
udp:
|
||||||
|
endpoint: "http://pangolin:3001/api/v1/traefik-config/udp"
|
||||||
|
pollInterval: "5s"
|
||||||
|
tcp:
|
||||||
|
endpoint: "http://pangolin:3001/api/v1/traefik-config/tcp"
|
||||||
pollInterval: "5s"
|
pollInterval: "5s"
|
||||||
file:
|
file:
|
||||||
filename: "/etc/traefik/dynamic_config.yml"
|
filename: "/etc/traefik/dynamic_config.yml"
|
||||||
|
|
|
@ -19,7 +19,7 @@ experimental:
|
||||||
plugins:
|
plugins:
|
||||||
badger:
|
badger:
|
||||||
moduleName: "github.com/fosrl/badger"
|
moduleName: "github.com/fosrl/badger"
|
||||||
version: "v1.0.0-beta.2"
|
version: "v1.0.0-beta.3"
|
||||||
|
|
||||||
log:
|
log:
|
||||||
level: "INFO"
|
level: "INFO"
|
||||||
|
|
|
@ -31,31 +31,36 @@ const migrations = [
|
||||||
await runMigrations();
|
await runMigrations();
|
||||||
|
|
||||||
export async function runMigrations() {
|
export async function runMigrations() {
|
||||||
const appVersion = loadAppVersion();
|
try {
|
||||||
if (!appVersion) {
|
const appVersion = loadAppVersion();
|
||||||
throw new Error("APP_VERSION is not set in the environment");
|
if (!appVersion) {
|
||||||
}
|
throw new Error("APP_VERSION is not set in the environment");
|
||||||
|
|
||||||
if (exists) {
|
|
||||||
await executeScripts();
|
|
||||||
} else {
|
|
||||||
console.log("Running migrations...");
|
|
||||||
try {
|
|
||||||
migrate(db, {
|
|
||||||
migrationsFolder: path.join(__DIRNAME, "init") // put here during the docker build
|
|
||||||
});
|
|
||||||
console.log("Migrations completed successfully.");
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error running migrations:", error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await db
|
if (exists) {
|
||||||
|
await executeScripts();
|
||||||
|
} else {
|
||||||
|
console.log("Running migrations...");
|
||||||
|
try {
|
||||||
|
migrate(db, {
|
||||||
|
migrationsFolder: path.join(__DIRNAME, "init") // put here during the docker build
|
||||||
|
});
|
||||||
|
console.log("Migrations completed successfully.");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error running migrations:", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
await db
|
||||||
.insert(versionMigrations)
|
.insert(versionMigrations)
|
||||||
.values({
|
.values({
|
||||||
version: appVersion,
|
version: appVersion,
|
||||||
executedAt: Date.now()
|
executedAt: Date.now()
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Error running migrations:", e);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000 * 60 * 60 * 24 * 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,25 @@ import { fromZodError } from "zod-validation-error";
|
||||||
export default async function migration() {
|
export default async function migration() {
|
||||||
console.log("Running setup script 1.0.0-beta.9...");
|
console.log("Running setup script 1.0.0-beta.9...");
|
||||||
|
|
||||||
|
// make dir config/db/backups
|
||||||
|
const appPath = APP_PATH;
|
||||||
|
const dbDir = path.join(appPath, "db");
|
||||||
|
|
||||||
|
const backupsDir = path.join(dbDir, "backups");
|
||||||
|
|
||||||
|
// check if the backups directory exists and create it if it doesn't
|
||||||
|
if (!fs.existsSync(backupsDir)) {
|
||||||
|
fs.mkdirSync(backupsDir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy the db.sqlite file to backups
|
||||||
|
// add the date to the filename
|
||||||
|
const date = new Date();
|
||||||
|
const dateString = `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}_${date.getHours()}-${date.getMinutes()}-${date.getSeconds()}`;
|
||||||
|
const dbPath = path.join(dbDir, "db.sqlite");
|
||||||
|
const backupPath = path.join(backupsDir, `db_${dateString}.sqlite`);
|
||||||
|
fs.copyFileSync(dbPath, backupPath);
|
||||||
|
|
||||||
await db.transaction(async (trx) => {
|
await db.transaction(async (trx) => {
|
||||||
try {
|
try {
|
||||||
// Determine which config file exists
|
// Determine which config file exists
|
||||||
|
@ -48,6 +67,12 @@ export default async function migration() {
|
||||||
rawConfig.server.session_cookie_name = "p_session_token"; // rename to prevent conflicts
|
rawConfig.server.session_cookie_name = "p_session_token"; // rename to prevent conflicts
|
||||||
delete rawConfig.server.resource_session_cookie_name;
|
delete rawConfig.server.resource_session_cookie_name;
|
||||||
|
|
||||||
|
if (!rawConfig.flags) {
|
||||||
|
rawConfig.flags = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
rawConfig.flags.allow_raw_resources = true;
|
||||||
|
|
||||||
// Write the updated YAML back to the file
|
// Write the updated YAML back to the file
|
||||||
const updatedYaml = yaml.dump(rawConfig);
|
const updatedYaml = yaml.dump(rawConfig);
|
||||||
fs.writeFileSync(filePath, updatedYaml, "utf8");
|
fs.writeFileSync(filePath, updatedYaml, "utf8");
|
||||||
|
@ -97,7 +122,7 @@ export default async function migration() {
|
||||||
const traefikFileContents = fs.readFileSync(traefikPath, "utf8");
|
const traefikFileContents = fs.readFileSync(traefikPath, "utf8");
|
||||||
const traefikConfig = yaml.load(traefikFileContents) as any;
|
const traefikConfig = yaml.load(traefikFileContents) as any;
|
||||||
|
|
||||||
const parsedConfig = schema.safeParse(traefikConfig);
|
let parsedConfig: any = schema.safeParse(traefikConfig);
|
||||||
|
|
||||||
if (parsedConfig.success) {
|
if (parsedConfig.success) {
|
||||||
// Ensure websecure entrypoint exists
|
// Ensure websecure entrypoint exists
|
||||||
|
@ -116,9 +141,7 @@ export default async function migration() {
|
||||||
const updatedTraefikYaml = yaml.dump(traefikConfig);
|
const updatedTraefikYaml = yaml.dump(traefikConfig);
|
||||||
fs.writeFileSync(traefikPath, updatedTraefikYaml, "utf8");
|
fs.writeFileSync(traefikPath, updatedTraefikYaml, "utf8");
|
||||||
|
|
||||||
console.log(
|
console.log("Updated Badger version in Traefik config.");
|
||||||
"Updated the version of Badger in your Traefik configuration to v1.0.0-beta.3 and added readTimeout to websecure entrypoint in your Traefik configuration.."
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
console.log(fromZodError(parsedConfig.error));
|
console.log(fromZodError(parsedConfig.error));
|
||||||
console.log(
|
console.log(
|
||||||
|
@ -133,6 +156,51 @@ export default async function migration() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const traefikPath = path.join(
|
||||||
|
APP_PATH,
|
||||||
|
"traefik",
|
||||||
|
"dynamic_config.yml"
|
||||||
|
);
|
||||||
|
|
||||||
|
const schema = z.object({
|
||||||
|
http: z.object({
|
||||||
|
middlewares: z.object({
|
||||||
|
"redirect-to-https": z.object({
|
||||||
|
redirectScheme: z.object({
|
||||||
|
scheme: z.string(),
|
||||||
|
permanent: z.boolean()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const traefikFileContents = fs.readFileSync(traefikPath, "utf8");
|
||||||
|
const traefikConfig = yaml.load(traefikFileContents) as any;
|
||||||
|
|
||||||
|
let parsedConfig: any = schema.safeParse(traefikConfig);
|
||||||
|
|
||||||
|
if (parsedConfig.success) {
|
||||||
|
// delete permanent from redirect-to-https middleware
|
||||||
|
delete traefikConfig.http.middlewares["redirect-to-https"].redirectScheme.permanent;
|
||||||
|
|
||||||
|
const updatedTraefikYaml = yaml.dump(traefikConfig);
|
||||||
|
fs.writeFileSync(traefikPath, updatedTraefikYaml, "utf8");
|
||||||
|
|
||||||
|
console.log("Deleted permanent from redirect-to-https middleware.");
|
||||||
|
} else {
|
||||||
|
console.log(fromZodError(parsedConfig.error));
|
||||||
|
console.log(
|
||||||
|
"We were unable to delete the permanent field from the redirect-to-https middleware in your Traefik configuration. Please delete it manually."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(
|
||||||
|
"We were unable to delete the permanent field from the redirect-to-https middleware in your Traefik configuration. Please delete it manually. Note that this is not a critical change but recommended."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
trx.run(sql`UPDATE ${users} SET email = LOWER(email);`);
|
trx.run(sql`UPDATE ${users} SET email = LOWER(email);`);
|
||||||
trx.run(
|
trx.run(
|
||||||
sql`UPDATE ${emailVerificationCodes} SET email = LOWER(email);`
|
sql`UPDATE ${emailVerificationCodes} SET email = LOWER(email);`
|
||||||
|
|
|
@ -162,7 +162,8 @@ export default function CreateResourceForm({
|
||||||
subdomain: data.http ? data.subdomain : undefined,
|
subdomain: data.http ? data.subdomain : undefined,
|
||||||
http: data.http,
|
http: data.http,
|
||||||
protocol: data.protocol,
|
protocol: data.protocol,
|
||||||
proxyPort: data.http ? undefined : data.proxyPort
|
proxyPort: data.http ? undefined : data.proxyPort,
|
||||||
|
siteId: data.siteId
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
|
|
|
@ -153,7 +153,9 @@ export default function CreateShareLinkForm({
|
||||||
|
|
||||||
if (res?.status === 200) {
|
if (res?.status === 200) {
|
||||||
setResources(
|
setResources(
|
||||||
res.data.data.resources.map((r) => ({
|
res.data.data.resources.filter((r) => {
|
||||||
|
return r.http;
|
||||||
|
}).map((r) => ({
|
||||||
resourceId: r.resourceId,
|
resourceId: r.resourceId,
|
||||||
name: r.name,
|
name: r.name,
|
||||||
resourceUrl: `${r.ssl ? "https://" : "http://"}${r.fullDomain}/`
|
resourceUrl: `${r.ssl ? "https://" : "http://"}${r.fullDomain}/`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue