-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove bind as DNS server from compose files #1646
Changes from 9 commits
54a873c
569f15e
058460f
d11de4d
5b0a330
5e651e7
6b272e8
6ab7a3b
6bede6d
8f9dd3b
a214f6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { listPackages } from "@dappnode/dockerapi"; | ||
import { ComposeFileEditor } from "@dappnode/dockercompose"; | ||
import { logs } from "@dappnode/logger"; | ||
|
||
/** | ||
* Migration to allow removal of current Bind functionality | ||
* | ||
* DNS resolution should be handled by the Docker DNS, not by Bind package | ||
* | ||
* For every service in every compose file, we must make sure it does not include | ||
* the dns configuration | ||
*/ | ||
export async function removeDnsFromComposeFiles(): Promise<void> { | ||
const packages = await listPackages(); | ||
|
||
for (const pkg of packages) { | ||
removeDnsFromPackageComposeFile(pkg.dnpName, pkg.isCore); | ||
} | ||
} | ||
|
||
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)) { | ||
const composeService = services[serviceName].get(); | ||
if (composeService.dns) { | ||
logs.info(`Removing DNS from ${serviceName} in ${dnpName} compose file`); | ||
composeService.dns = undefined; | ||
compose.write(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,103 +2,127 @@ import { expect } from "chai"; | |
import fs from "fs"; | ||
import { PackageContainer } from "@dappnode/common"; | ||
import { migrateCoreNetworkAndAliasInCompose } from "../../../src/modules/migrations/addAliasToRunningContainers.js"; | ||
import { removeDnsFromPackageComposeFile } from "../../../src/modules/migrations/removeDnsFromComposeFiles.js"; | ||
import { params } from "@dappnode/params"; | ||
import { mockContainer, shellSafe } from "../../testUtils.js"; | ||
|
||
describe("Migration", () => { | ||
const dncoreNetwork = params.DNP_PRIVATE_NETWORK_NAME; | ||
const serviceName = "test"; | ||
const containerName = "DAppNodePackage-test.dnp.dappnode.eth"; | ||
const randomImage = "chentex/random-logger"; | ||
const dnpName = "test-migration.dnp.dappnode.eth"; | ||
const testPackagePath = `${params.REPO_DIR}/test-migration.dnp.dappnode.eth`; | ||
|
||
const container: PackageContainer = { | ||
...mockContainer, | ||
containerName: "DAppNodeCore-dappmanager.dnp.dappnode.eth", | ||
dnpName: "test-migration", | ||
serviceName: "dappmanager.dnp.dappnode.eth", | ||
containerName, | ||
dnpName, | ||
serviceName, | ||
networks: [ | ||
{ name: "random", ip: "10.0.1.1" }, | ||
{ name: "dncore_network", ip: "172.33.1.7" } | ||
] | ||
}; | ||
|
||
const composeNoDns = ` | ||
version: '3.5' | ||
networks: | ||
${dncoreNetwork}: | ||
name: ${dncoreNetwork} | ||
external: true | ||
services: | ||
${serviceName}: | ||
image: ${randomImage} | ||
container_name: ${containerName} | ||
restart: always | ||
networks: | ||
${dncoreNetwork}: | ||
ipv4_address: 172.33.1.7 | ||
aliases: | ||
- ${serviceName}.test-migration.dappnode | ||
- ${serviceName}.dappnode`; | ||
|
||
const composeAlreadyMigrated = ` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that this file has alias migration and dns migration tests, I would rename: Or something like that, so we know that these are used for alias migration and not DNS |
||
version: '3.5' | ||
networks: | ||
dncore_network: | ||
name: dncore_network | ||
${dncoreNetwork}: | ||
name: ${dncoreNetwork} | ||
external: true | ||
services: | ||
dappmanager.dnp.dappnode.eth: | ||
image: chentex/random-logger | ||
container_name: DAppNodeCore-dappmanager.dnp.dappnode.eth | ||
${serviceName}: | ||
image: ${randomImage} | ||
container_name: ${containerName} | ||
restart: always | ||
dns: 172.33.1.2 | ||
networks: | ||
dncore_network: | ||
${dncoreNetwork}: | ||
ipv4_address: 172.33.1.7 | ||
aliases: | ||
- dappmanager.dnp.dappnode.eth.test-migration.dappnode | ||
- dappmanager.dappnode`; | ||
- ${serviceName}.test-migration.dappnode | ||
- ${serviceName}.dappnode`; | ||
|
||
const composeToBeMigratedBefore = ` | ||
version: '3.4' | ||
networks: | ||
dncore_network: | ||
name: dncore_network | ||
${dncoreNetwork}: | ||
name: ${dncoreNetwork} | ||
external: true | ||
services: | ||
dappmanager.dnp.dappnode.eth: | ||
image: "chentex/random-logger" | ||
container_name: DAppNodeCore-dappmanager.dnp.dappnode.eth | ||
${serviceName}: | ||
image: ${randomImage} | ||
container_name: ${containerName} | ||
restart: always | ||
dns: 172.33.1.2 | ||
networks: | ||
dncore_network: | ||
${dncoreNetwork}: | ||
ipv4_address: 172.33.1.7`; | ||
|
||
const dncoreNetwork = params.DNP_PRIVATE_NETWORK_NAME; | ||
const containerName = "DAppNodeCore-dappmanager.dnp.dappnode.eth"; | ||
const randomImage = "chentex/random-logger"; | ||
const testMigrationPath = process.cwd() + "/test/integration/migrations"; | ||
|
||
before("Run random container", async () => { | ||
// Create compose | ||
await shellSafe(`mkdir ${testMigrationPath}/test-migration`); | ||
await shellSafe(`mkdir -p ${testPackagePath}`); | ||
// Compose to be migrated | ||
fs.writeFileSync( | ||
`${testMigrationPath}/test-migration/docker-compose.yml`, | ||
`${testPackagePath}/docker-compose.yml`, | ||
composeToBeMigratedBefore | ||
); | ||
// Compose already migrated | ||
fs.writeFileSync( | ||
`${testMigrationPath}/test-migration/docker-compose-migrated.yml`, | ||
composeAlreadyMigrated | ||
); | ||
// Redeclare global variables | ||
params.DNCORE_DIR = testMigrationPath; | ||
params.REPO_DIR = testMigrationPath; | ||
|
||
// Startup container | ||
await shellSafe( | ||
`docker-compose -f ${testMigrationPath}/test-migration/docker-compose.yml -p DNCORE up -d` | ||
`docker-compose -f ${testPackagePath}/docker-compose.yml -p DNCORE up -d` | ||
); | ||
const containerkExists = await shellSafe( | ||
const containerExists = await shellSafe( | ||
`docker container ls --filter name=${containerName}` | ||
); | ||
|
||
const networkExists = await shellSafe( | ||
`docker network ls --filter name=${dncoreNetwork}` | ||
); | ||
|
||
if (!containerkExists || !networkExists) | ||
if (!containerExists || !networkExists) | ||
throw Error("Error creating container or/and dncore_network"); | ||
}); | ||
|
||
it("Should do alias migration in compose", async () => { | ||
const aliases = ["dappmanager.dnp.dappnode.eth.test-migration.dappnode", "dappmanager.dappnode"]; | ||
const aliases = ["test.test-migration.dappnode", "test.dappnode"]; | ||
migrateCoreNetworkAndAliasInCompose(container, aliases); | ||
|
||
const composeAfter = fs.readFileSync( | ||
`${testMigrationPath}/test-migration/docker-compose.yml`, | ||
`${testPackagePath}/docker-compose.yml`, | ||
{ encoding: "utf8" } | ||
); | ||
expect(composeAfter.trim()).to.equal(composeAlreadyMigrated.trim()); | ||
}); | ||
}); | ||
|
||
it("Should remove DNS from compose file", async () => { | ||
removeDnsFromPackageComposeFile(container.dnpName, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we test also the |
||
|
||
const composeAfter = fs.readFileSync( | ||
`${testPackagePath}/docker-compose.yml`, | ||
{ encoding: "utf8" } | ||
); | ||
expect(composeAfter.trim()).to.equal(composeNoDns.trim()); | ||
}); | ||
|
||
after("Remove test setup", async () => { | ||
// Disconnect from network | ||
|
@@ -112,10 +136,6 @@ services: | |
// Remove image | ||
await shellSafe(`docker image rm ${randomImage}`); | ||
// Remove dir | ||
await shellSafe(`rm -rf ${testMigrationPath}/test-migration`); | ||
|
||
// Return global vars to tests normal values | ||
params.DNCORE_DIR = "./DNCORE"; | ||
params.REPO_DIR = "./dnp_repo"; | ||
await shellSafe(`rm -rf ${testPackagePath}`); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this instructions completely removes the
dns
field?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! This will remove the
dns
field from everydocker-compose.yml
file that still includes it