Skip to content

Commit

Permalink
Update ACA deployment contract & use registryPath as loginServer (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroFish91 authored Jan 17, 2023
1 parent c73855f commit dcfee82
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@
},
{
"command": "vscode-docker.registries.deployImageToAca",
"when": "view == dockerRegistries && viewItem =~ /(DockerV2|DockerHubV2);Tag;/ && isAzureAccountInstalled",
"when": "view == dockerRegistries && viewItem =~ /(DockerV2|DockerHubV2|GitLabV4);Tag;/ && isAzureAccountInstalled",
"group": "regs_tag_1_general@6"
},
{
Expand Down
24 changes: 14 additions & 10 deletions src/commands/registries/azure/deployImageToAca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const minimumAcaExtensionVersion = '0.4.0'; // TODO: get the exact minimum versi

// The interface of the command options passed to the Azure Container Apps extension's deployImageToAca command
interface DeployImageToAcaOptionsContract {
imageName: string;
image: string;
loginServer?: string;
username?: string;
secret?: string;
Expand All @@ -38,27 +38,31 @@ export async function deployImageToAca(context: IActionContext, node?: RemoteTag
}

const commandOptions: DeployImageToAcaOptionsContract = {
imageName: node.fullTag,
image: node.fullTag,
};

addImageTaggingTelemetry(context, commandOptions.imageName, '');
addImageTaggingTelemetry(context, commandOptions.image, '');

const registry: RegistryTreeItemBase = node.parent.parent;
if (registry instanceof AzureRegistryTreeItem) {
// No additional work to do; ACA can handle this on its own
} else if (registry instanceof DockerHubNamespaceTreeItem || registry instanceof DockerV2RegistryTreeItemBase) {
const { auth } = await registry.getDockerCliCredentials() as { auth?: { username?: string, password?: string } };
} else {
const { auth, registryPath } = await registry.getDockerCliCredentials() as { auth?: { username?: string, password?: string }, registryPath: string };

if (!auth?.username || !auth?.password) {
if (!auth?.username || !auth?.password || !registryPath) {
throw new Error(localize('vscode-docker.commands.registries.azure.deployImageToAca.noCredentials', 'No credentials found for registry "{0}".', registry.label));
}

commandOptions.loginServer = registry.baseUrl;
if (registry instanceof DockerHubNamespaceTreeItem || registry instanceof DockerV2RegistryTreeItemBase) {
// ACA preference for Docker Hub images to be prefixed with 'docker.io/...'
if (!/^docker.io\//.test(commandOptions.image)) {
commandOptions.image = 'docker.io/' + commandOptions.image;
}
}

commandOptions.loginServer = registryPath;
commandOptions.username = auth.username;
commandOptions.secret = auth.password;
} else {
context.errorHandling.suppressReportIssue = true;
throw new Error(localize('vscode-docker.commands.registries.azure.deployImageToAca.unsupportedRegistry', 'Unsupported registry type'));
}

// Don't wait
Expand Down
4 changes: 3 additions & 1 deletion src/tree/registries/dockerHub/DockerHubNamespaceTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { IDockerCliCredentials, RegistryTreeItemBase } from "../RegistryTreeItem
import { DockerHubAccountTreeItem } from "./DockerHubAccountTreeItem";
import { DockerHubRepositoryTreeItem } from "./DockerHubRepositoryTreeItem";

const dockerHubRegistryUrl: string = 'https://index.docker.io/v1/';

export class DockerHubNamespaceTreeItem extends RegistryTreeItemBase {
public parent: DockerHubAccountTreeItem;
public baseUrl: string = dockerHubUrl;
Expand Down Expand Up @@ -57,7 +59,7 @@ export class DockerHubNamespaceTreeItem extends RegistryTreeItemBase {

public async getDockerCliCredentials(): Promise<IDockerCliCredentials> {
return {
registryPath: '',
registryPath: dockerHubRegistryUrl,
auth: {
username: this.parent.username,
password: await this.parent.getPassword()
Expand Down

0 comments on commit dcfee82

Please sign in to comment.