Skip to content

Commit

Permalink
use docker registry
Browse files Browse the repository at this point in the history
  • Loading branch information
dianabarsan committed Dec 4, 2024
1 parent fd83165 commit b454d3f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 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';
const K3D_REGISTRY_PORT = 12345;
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,12 @@ 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} --port ${K3D_REGISTRY_PORT}`);
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-${K3D_REGISTRY}:${K3D_REGISTRY_PORT}`
);
};

Expand All @@ -1213,11 +1218,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 Expand Up @@ -1510,9 +1521,9 @@ const getUpdatedPermissions = async (roles, addPermissions, removePermissions) =
return settings.permissions;
};

const updatePermissions = async (roles, addPermissions, removePermissions, ignoreReload) => {
const updatePermissions = async (roles, addPermissions, removePermissions) => {
const permissions = await getUpdatedPermissions(roles, addPermissions, removePermissions);
await updateSettings({permissions}, { ignoreReload: ignoreReload });
await updateSettings({ permissions }, { ignoreReload: true });
};

const getSentinelDate = () => getContainerDate('sentinel');
Expand Down

0 comments on commit b454d3f

Please sign in to comment.