Skip to content

Commit

Permalink
migrate user settings for geth
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo committed Nov 5, 2024
1 parent 5ac50a7 commit 09755b6
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/installer/src/installer/getInstallerPackageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
ContainersStatus
} from "@dappnode/types";
import { getBackupPath, getDockerComposePath, getImagePath, getManifestPath } from "@dappnode/utils";
import { gt } from "semver";
import { logs } from "@dappnode/logger";

interface GetInstallerPackageDataArg {
releases: PackageRelease[];
Expand Down Expand Up @@ -74,6 +76,7 @@ function getInstallerPackageData(

// If composePath does not exist, or is invalid: returns {}
const prevUserSet = ComposeFileEditor.getUserSettingsIfExist(dnpName, isCore);
migrateGethUserSettingsIfNeeded(prevUserSet, dnpName, semVersion);
const nextUserSet = deepmerge(prevUserSet, userSettings || {});

// Append to compose
Expand All @@ -99,3 +102,32 @@ function getInstallerPackageData(
containersStatus
};
}

/**
* Migrates the user settings from the old service name to the new service name
*
* Edge case for dnpName "geth.dnp.dappnode.eth" and serviceName "geth.dnp.dappnode.eth"
* The service name of the geth package has migrated to "geth" and the user settings should be applied to the new service name
* This edge case is implemented in core release 0.3.0 and should be safe to remove in the future
*/
function migrateGethUserSettingsIfNeeded(prevUserSet: UserSettings, dnpName: string, semVersion: string) {
const gethDnpName = "geth.dnp.dappnode.eth";
const legacyGethServiceName = gethDnpName;
// migrate networks
if (dnpName === gethDnpName && gt(semVersion, "0.1.43")) {
logs.info(`Version ${semVersion} is greater than 0.1.43. Using service name "geth"`);
if (prevUserSet.networks) {
logs.info(`Migrating user settings networks from geth.dnp.dappnode.eth to geth`);

prevUserSet.networks.serviceNetworks.geth = prevUserSet.networks.serviceNetworks[legacyGethServiceName];
delete prevUserSet.networks.serviceNetworks[legacyGethServiceName];
}

// migrate envs
if (prevUserSet.environment) {
logs.info(`Migrating user settings environment from geth.dnp.dappnode.eth to geth`);
prevUserSet.environment.geth = prevUserSet.environment[legacyGethServiceName];
delete prevUserSet.environment[legacyGethServiceName];
}
}
}

0 comments on commit 09755b6

Please sign in to comment.