mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 06:28:11 +00:00
Feat: Standalone migration mode
This commit is contained in:
@@ -6,8 +6,8 @@ on:
|
|||||||
# - daniel/infisical-binary
|
# - daniel/infisical-binary
|
||||||
|
|
||||||
push:
|
push:
|
||||||
# branches:
|
branches:
|
||||||
# - daniel/infisical-binary
|
- daniel/infisical-binary
|
||||||
|
|
||||||
# run for standalone releases
|
# run for standalone releases
|
||||||
tags:
|
tags:
|
||||||
@@ -52,7 +52,7 @@ jobs:
|
|||||||
- name: Set up Node.js
|
- name: Set up Node.js
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 20
|
||||||
|
|
||||||
- name: Install pkg
|
- name: Install pkg
|
||||||
run: npm install -g @yao-pkg/pkg
|
run: npm install -g @yao-pkg/pkg
|
||||||
@@ -69,8 +69,8 @@ jobs:
|
|||||||
run: npm run binary:build
|
run: npm run binary:build
|
||||||
working-directory: ./backend
|
working-directory: ./backend
|
||||||
|
|
||||||
- name: Package into node binary
|
- name: Package into node binary # --compress Brotli (Re-add before merging to main!)
|
||||||
run: pkg --no-bytecode --public-packages "*" --public --compress Brotli --target ${{ matrix.target }}-${{ matrix.arch }} --output ./binary/infisical-${{ matrix.os }}-${{ matrix.arch }} .
|
run: pkg --no-bytecode --public-packages "*" --public --target ${{ matrix.target }}-${{ matrix.arch }} --output ./binary/infisical-${{ matrix.os }}-${{ matrix.arch }} .
|
||||||
working-directory: ./backend
|
working-directory: ./backend
|
||||||
|
|
||||||
- name: List files
|
- name: List files
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { logger } from "../logger";
|
||||||
|
|
||||||
|
export const isMigrationMode = () => {
|
||||||
|
try {
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const migrationFlag = args.find((arg) => arg.startsWith("--migration-mode"));
|
||||||
|
|
||||||
|
if (!migrationFlag) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Covers the case where the flag is --migration-mode [true|false|...]
|
||||||
|
if (migrationFlag === "--migration-mode") {
|
||||||
|
const nextArg = args[args.indexOf(migrationFlag) + 1];
|
||||||
|
if (nextArg === "false") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// --migration-mode without a value defaults to true
|
||||||
|
return nextArg === undefined || nextArg.toLowerCase() === "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Covers the case where the flag is --migration-mode=[...]
|
||||||
|
const [, value] = migrationFlag.split("=");
|
||||||
|
if (value === undefined) {
|
||||||
|
const nextArg = args[args.indexOf(migrationFlag) + 1];
|
||||||
|
return nextArg === "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.toLowerCase() === "true";
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(err, `Failed to check migration mode`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
// Some of the functions are taken from https://github.com/rayepps/radash
|
// Some of the functions are taken from https://github.com/rayepps/radash
|
||||||
// Full credits goes to https://github.com/rayapps to those functions
|
// Full credits goes to https://github.com/rayapps to those functions
|
||||||
// Code taken to keep in in house and to adjust somethings for our needs
|
// Code taken to keep in in house and to adjust somethings for our needs
|
||||||
|
export * from "./argv";
|
||||||
export * from "./array";
|
export * from "./array";
|
||||||
export * from "./dates";
|
export * from "./dates";
|
||||||
export * from "./object";
|
export * from "./object";
|
||||||
|
|||||||
+21
-1
@@ -1,8 +1,10 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
import { initDbConnection } from "./db";
|
import { initDbConnection } from "./db";
|
||||||
import { keyStoreFactory } from "./keystore/keystore";
|
import { keyStoreFactory } from "./keystore/keystore";
|
||||||
import { formatSmtpConfig, initEnvConfig } from "./lib/config/env";
|
import { formatSmtpConfig, initEnvConfig, IS_PACKAGED } from "./lib/config/env";
|
||||||
|
import { isMigrationMode } from "./lib/fn";
|
||||||
import { initLogger } from "./lib/logger";
|
import { initLogger } from "./lib/logger";
|
||||||
import { queueServiceFactory } from "./queue";
|
import { queueServiceFactory } from "./queue";
|
||||||
import { main } from "./server/app";
|
import { main } from "./server/app";
|
||||||
@@ -10,6 +12,7 @@ import { bootstrapCheck } from "./server/boot-strap-check";
|
|||||||
import { smtpServiceFactory } from "./services/smtp/smtp-service";
|
import { smtpServiceFactory } from "./services/smtp/smtp-service";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
const logger = await initLogger();
|
const logger = await initLogger();
|
||||||
const appCfg = initEnvConfig(logger);
|
const appCfg = initEnvConfig(logger);
|
||||||
@@ -22,12 +25,29 @@ const run = async () => {
|
|||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Case: App is running in packaged mode (binary), and migration mode is enabled.
|
||||||
|
// Run the migrations and exit the process after completion.
|
||||||
|
if (IS_PACKAGED && isMigrationMode()) {
|
||||||
|
try {
|
||||||
|
logger.info("Running Postgres migrations..");
|
||||||
|
await db.migrate.latest({
|
||||||
|
directory: path.join(__dirname, "./db/migrations")
|
||||||
|
});
|
||||||
|
logger.info("Postgres migrations completed");
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(err, "Failed to run migrations");
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
const smtp = smtpServiceFactory(formatSmtpConfig());
|
const smtp = smtpServiceFactory(formatSmtpConfig());
|
||||||
const queue = queueServiceFactory(appCfg.REDIS_URL);
|
const queue = queueServiceFactory(appCfg.REDIS_URL);
|
||||||
const keyStore = keyStoreFactory(appCfg.REDIS_URL);
|
const keyStore = keyStoreFactory(appCfg.REDIS_URL);
|
||||||
|
|
||||||
const server = await main({ db, smtp, logger, queue, keyStore });
|
const server = await main({ db, smtp, logger, queue, keyStore });
|
||||||
const bootstrap = await bootstrapCheck({ db });
|
const bootstrap = await bootstrapCheck({ db });
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
process.on("SIGINT", async () => {
|
process.on("SIGINT", async () => {
|
||||||
await server.close();
|
await server.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user