Skip to content

Commit

Permalink
Force dns removal action before adding aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo committed Nov 7, 2024
1 parent e4e1640 commit a164ee5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 51 deletions.
14 changes: 2 additions & 12 deletions packages/migrations/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { migrateUserActionLogs } from "./migrateUserActionLogs.js";
import { removeLegacyDockerAssets } from "./removeLegacyDockerAssets.js";
import { addAliasToRunningContainers } from "./addAliasToRunningContainers.js";
import { removeDnsAndAddAlias } from "./removeDnsAndAddAlias.js";
import { pruneUserActionLogs } from "./pruneUserActionLogs.js";
import { removeDnsFromComposeFiles } from "./removeDnsFromComposeFiles.js";
import { migrateDockerNetworkIpRange } from "./migrateDockerNetworkIpRange/index.js";
import { recreateContainersIfLegacyDns } from "./recreateContainersIfLegacyDns.js";
import { ensureCoreComposesHardcodedIpsRange } from "./ensureCoreComposesHardcodedIpsRange.js";
Expand Down Expand Up @@ -62,15 +61,6 @@ export async function executeMigrations(
})
);

await removeDnsFromComposeFiles().catch((e) =>
migrationErrors.push({
migration: "remove bind DNS from docker compose files",
coreVersion: "0.2.82",
name: "MIGRATION_ERROR",
message: e
})
);

await ensureCoreComposesHardcodedIpsRange().catch((e) =>
migrationErrors.push({
migration: "ensure core composes files has correct hardcoded IPs in range",
Expand Down Expand Up @@ -106,7 +96,7 @@ export async function executeMigrations(
})
);

await addAliasToRunningContainers().catch((e) =>
await removeDnsAndAddAlias().catch((e) =>
migrationErrors.push({
migration: "add docker alias to running containers",
coreVersion: "0.2.80",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
dockerComposeUp,
dockerNetworkReconnect,
listPackageContainers,
getNetworkContainerConfig
getNetworkContainerConfig,
listPackages
} from "@dappnode/dockerapi";
import { gte, lt, clean } from "semver";
import { getDockerComposePath, getIsMonoService, getPrivateNetworkAliases, shell } from "@dappnode/utils";
Expand All @@ -26,11 +27,36 @@ const dncoreNetworkName = params.DOCKER_PRIVATE_NETWORK_NAME;
* "service1.example.dappnode" if the package is multiservice
* "service1.example.dappnode" and "example.dappnode" if the package is multiservice and has in manifest mainservice
*/
export async function addAliasToRunningContainers(): Promise<void> {
export async function removeDnsAndAddAlias(): Promise<void> {
const packages = await listPackages();
for (const pkg of packages) removeDnsFromPackageComposeFile(pkg.dnpName, pkg.isCore);

const containers = await listPackageContainers();
await addAliasToGivenContainers(containers);
}

export function removeDnsFromPackageComposeFile(dnpName: string, isCore: boolean): void {
const compose = new ComposeFileEditor(dnpName, isCore);
const services = compose.services();

for (const serviceName of Object.keys(services)) {
try {
const composeService = services[serviceName].get();
// check composeService has the key dns

if (Object.prototype.hasOwnProperty.call(composeService, "dns")) {
logs.info(`Removing DNS from ${serviceName} in ${dnpName} compose file`);
// setting undefined a yaml property might result into an error afterwards making js-yaml
// adding the following value to the undefined `Error parsing YAML: unknown tag !<tag:yaml.org,2002:js/undefined>`
delete composeService.dns;
compose.write();
}
} catch (e) {
logs.error(`Error removing DNS from ${serviceName} in ${dnpName} compose file`, e);
}
}
}

export async function addAliasToGivenContainers(containers: PackageContainer[]): Promise<void> {
for (const container of containers) {
try {
Expand Down
37 changes: 0 additions & 37 deletions packages/migrations/src/removeDnsFromComposeFiles.ts

This file was deleted.

0 comments on commit a164ee5

Please sign in to comment.