learnhouse 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/learnhouse.js +174 -8
- package/package.json +1 -1
package/dist/bin/learnhouse.js
CHANGED
|
@@ -3613,10 +3613,10 @@ var {
|
|
|
3613
3613
|
} = import_index.default;
|
|
3614
3614
|
|
|
3615
3615
|
// bin/learnhouse.ts
|
|
3616
|
-
var
|
|
3616
|
+
var import_picocolors19 = __toESM(require_picocolors(), 1);
|
|
3617
3617
|
|
|
3618
3618
|
// src/constants.ts
|
|
3619
|
-
var VERSION = "1.
|
|
3619
|
+
var VERSION = "1.3.0";
|
|
3620
3620
|
var APP_IMAGE = "ghcr.io/learnhouse/app:latest";
|
|
3621
3621
|
var DEV_IMAGE = "ghcr.io/learnhouse/app:dev";
|
|
3622
3622
|
var POSTGRES_IMAGE = "postgres:16-alpine";
|
|
@@ -6430,8 +6430,8 @@ async function logsCommand() {
|
|
|
6430
6430
|
R2.info("Streaming logs (Ctrl+C to stop)...");
|
|
6431
6431
|
if (config?.installDir) {
|
|
6432
6432
|
try {
|
|
6433
|
-
const { execSync:
|
|
6434
|
-
const ps =
|
|
6433
|
+
const { execSync: execSync7 } = await import("child_process");
|
|
6434
|
+
const ps = execSync7("docker compose ps -q", { cwd: config.installDir, stdio: "pipe" }).toString().trim();
|
|
6435
6435
|
if (ps) {
|
|
6436
6436
|
dockerComposeLogs(config.installDir);
|
|
6437
6437
|
return;
|
|
@@ -7664,11 +7664,176 @@ async function devCommand(opts) {
|
|
|
7664
7664
|
});
|
|
7665
7665
|
}
|
|
7666
7666
|
|
|
7667
|
+
// src/commands/update.ts
|
|
7668
|
+
import { execSync as execSync6 } from "child_process";
|
|
7669
|
+
import { readFileSync as readFileSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
7670
|
+
import { join as join3 } from "path";
|
|
7671
|
+
var import_picocolors18 = __toESM(require_picocolors(), 1);
|
|
7672
|
+
var GHCR_BASE2 = "ghcr.io/learnhouse/app";
|
|
7673
|
+
async function resolveTag(version) {
|
|
7674
|
+
try {
|
|
7675
|
+
const tokenResp = await fetch(
|
|
7676
|
+
"https://ghcr.io/token?scope=repository:learnhouse/app:pull",
|
|
7677
|
+
{ signal: AbortSignal.timeout(5e3) }
|
|
7678
|
+
);
|
|
7679
|
+
if (!tokenResp.ok) return false;
|
|
7680
|
+
const { token } = await tokenResp.json();
|
|
7681
|
+
const manifestResp = await fetch(
|
|
7682
|
+
`https://ghcr.io/v2/learnhouse/app/manifests/${version}`,
|
|
7683
|
+
{
|
|
7684
|
+
signal: AbortSignal.timeout(5e3),
|
|
7685
|
+
headers: {
|
|
7686
|
+
Accept: "application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.list.v2+json",
|
|
7687
|
+
Authorization: `Bearer ${token}`
|
|
7688
|
+
}
|
|
7689
|
+
}
|
|
7690
|
+
);
|
|
7691
|
+
return manifestResp.ok;
|
|
7692
|
+
} catch {
|
|
7693
|
+
return false;
|
|
7694
|
+
}
|
|
7695
|
+
}
|
|
7696
|
+
async function updateCommand(options) {
|
|
7697
|
+
const dir = findInstallDir();
|
|
7698
|
+
const config = readConfig(dir);
|
|
7699
|
+
if (!config) {
|
|
7700
|
+
R2.error("No LearnHouse installation found in the current directory.");
|
|
7701
|
+
process.exit(1);
|
|
7702
|
+
}
|
|
7703
|
+
const targetVersion = options.version?.replace(/^v/, "");
|
|
7704
|
+
if (targetVersion) {
|
|
7705
|
+
We(import_picocolors18.default.cyan(`Updating LearnHouse to v${targetVersion}`));
|
|
7706
|
+
} else {
|
|
7707
|
+
We(import_picocolors18.default.cyan("Updating LearnHouse to latest"));
|
|
7708
|
+
}
|
|
7709
|
+
const s = bt2();
|
|
7710
|
+
try {
|
|
7711
|
+
let targetImage;
|
|
7712
|
+
if (targetVersion) {
|
|
7713
|
+
s.start(`Checking if v${targetVersion} exists`);
|
|
7714
|
+
const exists = await resolveTag(targetVersion);
|
|
7715
|
+
if (!exists) {
|
|
7716
|
+
const existsWithV = await resolveTag(`v${targetVersion}`);
|
|
7717
|
+
if (!existsWithV) {
|
|
7718
|
+
s.stop("Version not found");
|
|
7719
|
+
R2.error(
|
|
7720
|
+
`Version ${targetVersion} not found on ghcr.io/learnhouse/app`
|
|
7721
|
+
);
|
|
7722
|
+
process.exit(1);
|
|
7723
|
+
}
|
|
7724
|
+
targetImage = `${GHCR_BASE2}:v${targetVersion}`;
|
|
7725
|
+
} else {
|
|
7726
|
+
targetImage = `${GHCR_BASE2}:${targetVersion}`;
|
|
7727
|
+
}
|
|
7728
|
+
s.stop(`Found v${targetVersion}`);
|
|
7729
|
+
} else {
|
|
7730
|
+
targetImage = `${GHCR_BASE2}:latest`;
|
|
7731
|
+
}
|
|
7732
|
+
const composePath = join3(config.installDir, "docker-compose.yml");
|
|
7733
|
+
const composeContent = readFileSync2(composePath, "utf-8");
|
|
7734
|
+
const updatedCompose = composeContent.replace(
|
|
7735
|
+
/image:\s*ghcr\.io\/learnhouse\/app:\S+/,
|
|
7736
|
+
`image: ${targetImage}`
|
|
7737
|
+
);
|
|
7738
|
+
writeFileSync3(composePath, updatedCompose);
|
|
7739
|
+
s.start("Pulling image");
|
|
7740
|
+
s.stop("Image reference updated");
|
|
7741
|
+
s.start("Restarting services");
|
|
7742
|
+
dockerComposeDown(config.installDir);
|
|
7743
|
+
dockerComposeUp(config.installDir);
|
|
7744
|
+
s.stop("Services restarted");
|
|
7745
|
+
R2.info("");
|
|
7746
|
+
R2.warn(
|
|
7747
|
+
import_picocolors18.default.bold("This update may include database migrations.")
|
|
7748
|
+
);
|
|
7749
|
+
R2.info(
|
|
7750
|
+
`Before proceeding, check the release notes at ${import_picocolors18.default.cyan("https://docs.learnhouse.app")} for migration guides and breaking changes.`
|
|
7751
|
+
);
|
|
7752
|
+
R2.info("");
|
|
7753
|
+
const runMigrations = await Re({
|
|
7754
|
+
message: "Run database migrations now?",
|
|
7755
|
+
initialValue: false
|
|
7756
|
+
});
|
|
7757
|
+
if (Ct(runMigrations)) {
|
|
7758
|
+
R2.info("Skipped database migrations. You can run them later with:");
|
|
7759
|
+
R2.info(' docker exec <container> sh -c "cd /app/api && uv run alembic upgrade head"');
|
|
7760
|
+
} else if (runMigrations) {
|
|
7761
|
+
s.start("Running database migrations");
|
|
7762
|
+
try {
|
|
7763
|
+
const appContainer = getAppContainerName(config.installDir);
|
|
7764
|
+
if (appContainer) {
|
|
7765
|
+
waitForContainer(appContainer);
|
|
7766
|
+
execSync6(
|
|
7767
|
+
`docker exec ${appContainer} sh -c "cd /app/api && uv run alembic upgrade head"`,
|
|
7768
|
+
{ stdio: "pipe", timeout: 12e4 }
|
|
7769
|
+
);
|
|
7770
|
+
s.stop("Database migrations complete");
|
|
7771
|
+
} else {
|
|
7772
|
+
s.stop("Skipped migrations (container not found)");
|
|
7773
|
+
R2.warn("Could not find the app container to run migrations. Run them manually:");
|
|
7774
|
+
R2.warn(' docker exec <container> sh -c "cd /app/api && uv run alembic upgrade head"');
|
|
7775
|
+
}
|
|
7776
|
+
} catch {
|
|
7777
|
+
s.stop("Migration warning");
|
|
7778
|
+
R2.warn("Database migrations encountered an issue. Your app is running but you may need to run migrations manually:");
|
|
7779
|
+
R2.warn(' docker exec <container> sh -c "cd /app/api && uv run alembic upgrade head"');
|
|
7780
|
+
}
|
|
7781
|
+
} else {
|
|
7782
|
+
R2.info("Skipped database migrations. You can run them later with:");
|
|
7783
|
+
R2.info(' docker exec <container> sh -c "cd /app/api && uv run alembic upgrade head"');
|
|
7784
|
+
}
|
|
7785
|
+
if (targetVersion) {
|
|
7786
|
+
R2.success(`LearnHouse has been updated to v${targetVersion}!`);
|
|
7787
|
+
} else {
|
|
7788
|
+
R2.success("LearnHouse has been updated to the latest version!");
|
|
7789
|
+
}
|
|
7790
|
+
} catch {
|
|
7791
|
+
s.stop("Update failed");
|
|
7792
|
+
R2.error("Failed to update. Check Docker output above.");
|
|
7793
|
+
process.exit(1);
|
|
7794
|
+
}
|
|
7795
|
+
}
|
|
7796
|
+
function getAppContainerName(cwd) {
|
|
7797
|
+
try {
|
|
7798
|
+
const output = execSync6('docker compose ps --format "{{.Name}}"', {
|
|
7799
|
+
cwd,
|
|
7800
|
+
stdio: "pipe"
|
|
7801
|
+
}).toString().trim();
|
|
7802
|
+
const lines = output.split("\n");
|
|
7803
|
+
return lines.find((name) => name.includes("learnhouse-app-")) || null;
|
|
7804
|
+
} catch {
|
|
7805
|
+
return null;
|
|
7806
|
+
}
|
|
7807
|
+
}
|
|
7808
|
+
function waitForContainer(containerName, timeoutMs = 6e4) {
|
|
7809
|
+
const start = Date.now();
|
|
7810
|
+
while (Date.now() - start < timeoutMs) {
|
|
7811
|
+
try {
|
|
7812
|
+
const status = execSync6(
|
|
7813
|
+
`docker inspect -f '{{.State.Health.Status}}' ${containerName}`,
|
|
7814
|
+
{ stdio: "pipe" }
|
|
7815
|
+
).toString().trim();
|
|
7816
|
+
if (status === "healthy") return;
|
|
7817
|
+
} catch {
|
|
7818
|
+
try {
|
|
7819
|
+
const running = execSync6(
|
|
7820
|
+
`docker inspect -f '{{.State.Running}}' ${containerName}`,
|
|
7821
|
+
{ stdio: "pipe" }
|
|
7822
|
+
).toString().trim();
|
|
7823
|
+
if (running === "true") return;
|
|
7824
|
+
} catch {
|
|
7825
|
+
}
|
|
7826
|
+
}
|
|
7827
|
+
execSync6("sleep 2", { stdio: "pipe" });
|
|
7828
|
+
}
|
|
7829
|
+
}
|
|
7830
|
+
|
|
7667
7831
|
// bin/learnhouse.ts
|
|
7668
7832
|
var COMMANDS = [
|
|
7669
7833
|
{ name: "setup", desc: "Interactive setup wizard" },
|
|
7670
7834
|
{ name: "start", desc: "Start services" },
|
|
7671
7835
|
{ name: "stop", desc: "Stop services" },
|
|
7836
|
+
{ name: "update", desc: "Update to latest or specific version" },
|
|
7672
7837
|
{ name: "logs", desc: "Stream logs" },
|
|
7673
7838
|
{ name: "config", desc: "Show configuration" },
|
|
7674
7839
|
{ name: "backup", desc: "Backup & restore database" },
|
|
@@ -7679,13 +7844,13 @@ var COMMANDS = [
|
|
|
7679
7844
|
];
|
|
7680
7845
|
async function showWelcome() {
|
|
7681
7846
|
await printBanner();
|
|
7682
|
-
console.log(
|
|
7847
|
+
console.log(import_picocolors19.default.bold(import_picocolors19.default.white(" Available commands:\n")));
|
|
7683
7848
|
for (const cmd of COMMANDS) {
|
|
7684
|
-
console.log(` ${
|
|
7849
|
+
console.log(` ${import_picocolors19.default.cyan(cmd.name.padEnd(14))} ${import_picocolors19.default.dim(cmd.desc)}`);
|
|
7685
7850
|
}
|
|
7686
7851
|
console.log();
|
|
7687
|
-
console.log(
|
|
7688
|
-
console.log(
|
|
7852
|
+
console.log(import_picocolors19.default.dim(" Run a command with: npx learnhouse <command>"));
|
|
7853
|
+
console.log(import_picocolors19.default.dim(" Get started with: npx learnhouse setup"));
|
|
7689
7854
|
console.log();
|
|
7690
7855
|
}
|
|
7691
7856
|
var program2 = new Command();
|
|
@@ -7699,6 +7864,7 @@ program2.command("backup").description("Backup & restore LearnHouse database").a
|
|
|
7699
7864
|
program2.command("deployments").description("Manage deployments & resource limits").action(deploymentsCommand);
|
|
7700
7865
|
program2.command("doctor").description("Diagnose common issues with LearnHouse").action(doctorCommand);
|
|
7701
7866
|
program2.command("shell").description("Open a shell in a LearnHouse container").action(shellCommand);
|
|
7867
|
+
program2.command("update").description("Update LearnHouse to latest or a specific version").option("-v, --version <version>", "Target version (e.g. 1.0.0)").action(updateCommand);
|
|
7702
7868
|
program2.command("dev").description("Start development environment (DB + Redis in Docker, API + Web locally)").option("--ee", "Enable Enterprise Edition features (keeps ee/ folder)").action(devCommand);
|
|
7703
7869
|
var updateCheck = checkForUpdates();
|
|
7704
7870
|
program2.parseAsync().then(() => updateCheck.catch(() => {
|