Skip to content

Commit

Permalink
fix: Tag image after pushing to sandbox internal registry (#85)
Browse files Browse the repository at this point in the history
Local tag should match destination tag uses to push
to internal registry.

Fix #75.

Signed-off-by: Jeff MAURY <[email protected]>
Co-authored-by: Denis Golovin <[email protected]>
  • Loading branch information
jeffmaury and dgolovin authored Jul 14, 2023
1 parent 4f9c89c commit 2489917
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 217 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"dependencies": {
"@kubernetes/client-node": "^0.18.1",
"@podman-desktop/api": "^0.15.0",
"@podman-desktop/api": "^1.2.0",
"fs-extra": "^10.1.0",
"got": "^12.6.0",
"js-yaml": "^4.1.0"
Expand Down
68 changes: 42 additions & 26 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { KubeConfig } from '@kubernetes/client-node';
import * as extensionApi from '@podman-desktop/api';
import got from 'got';
import * as kubeconfig from './kubeconfig';
import { execPodman } from './podman-cli';

const ProvideDisplayName = 'Developer Sandbox';

Expand Down Expand Up @@ -125,39 +124,56 @@ export async function pushImageToOpenShiftRegistry(image: ImageInfo): Promise<vo
progress.report({ increment: 25 });
const registryInfo = await getOpenShiftInternalRegistryPublicHost(targetSb);
progress.report({ increment: 50 });
const loginOutput = await execPodman([
'login',
'-u',
registryInfo.username,
'-p',
registryInfo.token,
registryInfo.host,
]);
progress.report({ increment: 75 });
const lastIndexOfSlash = image.name.lastIndexOf('/');
const imageShortName = lastIndexOfSlash !== -1 ? image.name.substring(lastIndexOfSlash + 1) : image.name;
const imageTagSuffix = image.tag ? `:${image.tag}` : ``;
const pushOutput = await execPodman([
'image',
'push',
`${image.name}:${image.tag}`,
`${registryInfo.host}/${registryInfo.username}-dev/${imageShortName}${imageTagSuffix}`,
]);
const localImageName = `${image.name}${imageTagSuffix}`;
const remoteImageName = `${registryInfo.host}/${registryInfo.username}-dev/${imageShortName}${imageTagSuffix}`;
if (localImageName !== remoteImageName) {
await extensionApi.containerEngine.tagImage(
image.engineId,
image.name + imageTagSuffix,
`${registryInfo.host}/${registryInfo.username}-dev/${imageShortName}`,
image.tag,
);
}
progress.report({ increment: 75 });
await new Promise(async (resolve, reject) => {
try {
await extensionApi.containerEngine.pushImage(
image.engineId,
remoteImageName,
(name, data) => {
if (name === 'data') {
progress.report({ message: data });
}
if (name === 'end') {
resolve(undefined);
}
},
{ username: registryInfo.username, password: registryInfo.token, serveraddress: registryInfo.host },
);
} catch (err: unknown) {
reject(err);
}
});
progress.report({ increment: 100 });
if (localImageName !== remoteImageName) {
await extensionApi.window.showInformationMessage(
`The image '${image.name}:${image.tag}' has been successfully pushed to to Developer Sandbox cluster '${targetSb}'. A new tag '${registryInfo.host}/${registryInfo.username}-dev/${imageShortName}${imageTagSuffix}' has been created for this image; you must use this image tag when deploying to Developer Sandbox`,
);
} else {
await extensionApi.window.showInformationMessage(
`The image '${image.name}:${image.tag}' has been successfully pushed to to Developer Sandbox cluster '${targetSb}'.`,
);
}
} catch (err) {
pushError = err;
await extensionApi.window.showErrorMessage(
`An error occurred while pushing the image '${image.name}:${image.tag}' to Developer Sandbox cluster '${targetSb}'. ${err}`,
);
}
},
);
if (pushError) {
await extensionApi.window.showErrorMessage(
`An error occurred while pushing the image'${image.name}:${image.tag}' to Developer Sandbox cluster'${targetSb}'.${pushError}`,
);
} else {
await extensionApi.window.showInformationMessage(
`The image successfully pushed to to Developer Sandbox cluster '${targetSb}'.`,
);
}
}

async function deleteContext(contextName: string): Promise<void> {
Expand Down
186 changes: 0 additions & 186 deletions src/podman-cli.ts

This file was deleted.

8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@
optionalDependencies:
openid-client "^5.3.0"

"@podman-desktop/api@^0.15.0":
version "0.15.0"
resolved "https://registry.npmjs.org/@podman-desktop/api/-/api-0.15.0.tgz"
integrity sha512-ZK/nr5MUgSeG65d51oagh0WjLhatLeWjfuj6JHG+WHEjHyNT3xLtRj1033IM64p2PHHKTazh5TTOqZjQ1ijhhQ==
"@podman-desktop/api@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@podman-desktop/api/-/api-1.2.0.tgz#45bad164c176006f335be0ff265762d48202f23e"
integrity sha512-kTMGuSpGjSesQg8qw/fya9dCm6Tk9/X7nfEERPXNw0J+5UMwlsmvgB/zf1/jvzwQRfeFxI/l6QxhS0BXPb0fkA==

"@sindresorhus/is@^5.2.0":
version "5.3.0"
Expand Down

0 comments on commit 2489917

Please sign in to comment.