Skip to content

Commit

Permalink
chore(#9585): use docker registry in k3d e2e tests (#9693)
Browse files Browse the repository at this point in the history
Creates docker registry and enables cluster to use this registry.
Fixes cluster imported images being garbage collected sometimes.

#9091
#9585
  • Loading branch information
dianabarsan authored Dec 5, 2024
1 parent 48b410b commit 35bb802
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions tests/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ let infrastructure = 'docker';
const isDocker = () => infrastructure === 'docker';
const isK3D = () => !isDocker();
const K3D_DATA_PATH = '/data';
const K3D_REGISTRY = 'registry.localhost';
let K3D_REGISTRY_PORT;
const K3D_REPO = () => `k3d-${K3D_REGISTRY}:${K3D_REGISTRY_PORT}`;

const auth = { username: constants.USERNAME, password: constants.PASSWORD };
const SW_SUCCESSFUL_REGEX = /Service worker generated successfully/;
Expand Down Expand Up @@ -1101,7 +1104,7 @@ const getTestComposeFilePath = file => path.resolve(__dirname, `../${file}-test.

const generateK3DValuesFile = async () => {
const view = {
repo: buildVersions.getRepo(),
repo: `${K3D_REPO()}/${buildVersions.getRepo()}`,
tag: buildVersions.getImageTag(),
db_name: constants.DB_NAME,
user: constants.USERNAME,
Expand Down Expand Up @@ -1189,10 +1192,16 @@ const runCommand = (command, { verbose = true, overrideEnv = false } = {}) => {

const createCluster = async (dataDir) => {
const hostPort = process.env.NGINX_HTTPS_PORT ? `${process.env.NGINX_HTTPS_PORT}` : '443';
await runCommand(`k3d registry create ${K3D_REGISTRY}`);

const port = await runCommand(`docker container port k3d-${K3D_REGISTRY}`);
K3D_REGISTRY_PORT = port.trim().replace('5000/tcp -> 0.0.0.0:', '');

await runCommand(
`k3d cluster create ${PROJECT_NAME} ` +
`--port ${hostPort}:443@loadbalancer ` +
`--volume ${dataDir}:${K3D_DATA_PATH} --kubeconfig-switch-context=false`
`--volume ${dataDir}:${K3D_DATA_PATH} --kubeconfig-switch-context=false ` +
`--registry-use ${K3D_REPO()}`
);
};

Expand All @@ -1213,11 +1222,17 @@ const importImages = async () => {
} catch {
await runCommand(`docker pull ${image}`);
}
await runCommand(`k3d image import ${image} -c ${PROJECT_NAME}`);
await runCommand(`docker tag ${image} ${K3D_REPO()}/${image}`);
await runCommand(`docker push ${K3D_REPO()}/${image}`);
}
};

const cleanupOldCluster = async () => {
try {
await runCommand(`k3d registry delete ${K3D_REGISTRY}`);
} catch {
console.warn('No registry to clean up');
}
try {
await runCommand(`k3d cluster delete ${PROJECT_NAME}`);
} catch {
Expand Down

0 comments on commit 35bb802

Please sign in to comment.