Skip to content

Commit 8d74e7f

Browse files
LevevTibixDev
andauthored
feat: Better auto migrations, feat: Added migration for pre-0.9.0 (#512)
chore: Add 'stopped' podman status chore: remove 'performedComposeMigrations' from WinboatConfigObj Co-authored-by: Tibix <[email protected]>
1 parent 9d656eb commit 8d74e7f

File tree

5 files changed

+70
-32
lines changed

5 files changed

+70
-32
lines changed

src/renderer/App.vue

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,13 @@ import { routes } from "./router";
158158
import { Icon } from "@iconify/vue";
159159
import { onMounted, onUnmounted, ref, useTemplateRef, watch } from "vue";
160160
import { isInstalled } from "./lib/install";
161-
import { Winboat, logger } from "./lib/winboat";
161+
import { Winboat } from "./lib/winboat";
162162
import { openAnchorLink } from "./utils/openLink";
163163
import { WinboatConfig } from "./lib/config";
164164
import { USBManager } from "./lib/usbmanager";
165165
import { setIntervalImmediately } from "./utils/interval";
166-
import { CommonPorts, ContainerRuntimes, getActiveHostPort } from "./lib/containers/common";
166+
import { CommonPorts, getActiveHostPort } from "./lib/containers/common";
167+
import { performAutoMigrations } from "./lib/migrate";
167168
const { BrowserWindow }: typeof import("@electron/remote") = require("@electron/remote");
168169
const os: typeof import("os") = require("node:os");
169170
@@ -191,35 +192,11 @@ onMounted(async () => {
191192
winboat = Winboat.getInstance(); // Instantiate singleton class
192193
USBManager.getInstance(); // Instantiate singleton class
193194
194-
// Avoid performing migrations under podman
195-
if(wbConfig.config.containerRuntime === ContainerRuntimes.PODMAN) {
196-
wbConfig.config.performedComposeMigrations = true;
197-
}
198-
199-
// Perform migrations under docker
200-
if (!wbConfig.config.performedComposeMigrations) {
201-
$router.push("/migration");
202-
logger.info("Performing migrations for 0.9.0");
203-
204-
// Compose migration
205-
if (await winboat.containerMgr!.exists()) {
206-
logger.info("Composing down current WinBoat container");
207-
await winboat.containerMgr!.compose("down");
208-
}
209-
210-
const currentCompose = Winboat.readCompose(winboat.containerMgr!.composeFilePath);
211-
const defaultCompose = winboat.containerMgr!.defaultCompose;
212-
213-
currentCompose.services.windows.ports = defaultCompose.services.windows.ports;
214-
215-
winboat.containerMgr!.writeCompose(currentCompose);
216-
217-
logger.info("Composing up WinBoat container");
218-
await winboat.containerMgr!.compose("up", ["--no-start"]);
219-
220-
wbConfig!.config.performedComposeMigrations = true;
221-
}
195+
// Migrations
196+
$router.push("/migration");
197+
await performAutoMigrations();
222198
199+
// After migrations, go to home
223200
$router.push("/home");
224201
} else {
225202
console.log("Not installed, redirecting to setup...");

src/renderer/lib/config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export type WinboatConfigObj = {
6363
rdpArgs: RdpArg[];
6464
disableAnimations: boolean;
6565
containerRuntime: ContainerRuntimes;
66-
performedComposeMigrations: boolean;
6766
versionData: WinboatVersionData;
6867
};
6968

@@ -83,7 +82,6 @@ const defaultConfig: WinboatConfigObj = {
8382
disableAnimations: false,
8483
// TODO: Ideally should be podman once we flesh out everything
8584
containerRuntime: ContainerRuntimes.DOCKER,
86-
performedComposeMigrations: false,
8785
versionData: {
8886
previous: currentVersion, // As of 0.9.0 this won't exist on the filesystem, so we just set it to the current version
8987
current: currentVersion

src/renderer/lib/containers/podman.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export class PodmanContainer extends ContainerManager {
142142
initialized: ContainerStatus.UNKNOWN,
143143
removing: ContainerStatus.UNKNOWN,
144144
stopping: ContainerStatus.EXITED,
145+
stopped: ContainerStatus.EXITED,
145146
running: ContainerStatus.RUNNING,
146147
paused: ContainerStatus.PAUSED,
147148
exited: ContainerStatus.EXITED,

src/renderer/lib/install.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ export class InstallManager {
309309
} catch (e) {
310310
this.changeState(InstallStates.INSTALL_ERROR);
311311
logger.error("Errors encountered, could not complete the installation steps.");
312+
logger.error(e);
312313
return;
313314
}
314315
this.changeState(InstallStates.COMPLETED);

src/renderer/lib/migrate.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { createLogger } from "../utils/log";
2+
import { WinboatConfig } from "./config";
3+
import { WINBOAT_DIR } from "./constants";
4+
import { CommonPorts, createContainer, getActiveHostPort } from "./containers/common";
5+
import { ContainerManager } from "./containers/container";
6+
import { Winboat } from "./winboat";
7+
8+
const path: typeof import("path") = require("path");
9+
const logger = createLogger(path.join(WINBOAT_DIR, "migrations.log"));
10+
11+
/**
12+
* This function performs the necessary automatic migrations
13+
* when updating to newer versions of WinBoat
14+
*/
15+
export async function performAutoMigrations(): Promise<void> {
16+
logger.info("[performAutoMigrations]: Starting automatic migrations");
17+
18+
const wbConfig = WinboatConfig.getInstance(); // Get WinboatConfig instance
19+
const containerManager = createContainer(wbConfig.config.containerRuntime);
20+
21+
try {
22+
// In case of a version prior to 0.9.0, the NoVNC port will be set to the default 8006
23+
// which is how we know we need to perform the migration, because from 0.9.0 we can rely
24+
// on the stored version strings
25+
if (getActiveHostPort(containerManager, CommonPorts.NOVNC) === CommonPorts.NOVNC) {
26+
await migrateComposePorts_Pre090(containerManager);
27+
}
28+
}
29+
catch (e: any) {
30+
logger.error("[performAutoMigrations]: Automatic migrations failed");
31+
logger.error(e.message ?? e);
32+
return;
33+
}
34+
35+
logger.info("[performAutoMigrations]: Finished automatic migrations");
36+
}
37+
38+
/**
39+
* Perform compose port migrations for pre-0.9.0 installations
40+
*/
41+
async function migrateComposePorts_Pre090(containerManager: ContainerManager): Promise<void> {
42+
logger.info("[migrateComposePorts_Pre090]: Performing migrations for 0.9.0");
43+
44+
// Compose migration
45+
if (await containerManager.exists()) {
46+
logger.info("[migrateComposePorts_Pre090]: Composing down current WinBoat container");
47+
await containerManager.compose("down");
48+
}
49+
50+
const currentCompose = Winboat.readCompose(containerManager.composeFilePath);
51+
const defaultCompose = containerManager.defaultCompose;
52+
53+
currentCompose.services.windows.ports = defaultCompose.services.windows.ports;
54+
currentCompose.services.windows.image = defaultCompose.services.windows.image;
55+
currentCompose.services.windows.environment["USER_PORTS"] = defaultCompose.services.windows.environment["USER_PORTS"];
56+
57+
containerManager.writeCompose(currentCompose);
58+
59+
logger.info("[migrateComposePorts_Pre090]: Composing up WinBoat container");
60+
await containerManager.compose("up", ["--no-start"]);
61+
}

0 commit comments

Comments
 (0)