Skip to content
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

Change ACA contract to support registryName instead of loginServer #3818

Merged
merged 2 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/commands/registries/azure/deployImageToAca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as semver from 'semver';
import * as vscode from 'vscode';
import { DialogResponses, IActionContext, UserCancelledError } from '@microsoft/vscode-azext-utils';
import { DialogResponses, IActionContext, nonNullProp, UserCancelledError } from '@microsoft/vscode-azext-utils';
import { RemoteTagTreeItem } from '../../../tree/registries/RemoteTagTreeItem';
import { localize } from '../../../localize';
import { ext } from '../../../extensionVariables';
Expand All @@ -15,14 +15,15 @@ import { AzureRegistryTreeItem } from '../../../tree/registries/azure/AzureRegis
import { DockerHubNamespaceTreeItem } from '../../../tree/registries/dockerHub/DockerHubNamespaceTreeItem';
import { DockerV2RegistryTreeItemBase } from '../../../tree/registries/dockerV2/DockerV2RegistryTreeItemBase';
import { addImageTaggingTelemetry } from '../../images/tagImage';
import { parseDockerLikeImageName } from '../../../runtimes/docker/clients/DockerClientBase/parseDockerLikeImageName';

const acaExtensionId = 'ms-azuretools.vscode-azurecontainerapps';
const minimumAcaExtensionVersion = '0.4.0'; // TODO: get the exact minimum version that is needed

// The interface of the command options passed to the Azure Container Apps extension's deployImageToAca command
interface DeployImageToAcaOptionsContract {
image: string;
loginServer?: string;
registryName: string;
username?: string;
secret?: string;
}
Expand All @@ -39,7 +40,7 @@ export async function deployImageToAca(context: IActionContext, node?: RemoteTag
node = await ext.registriesTree.showTreeItemPicker<RemoteTagTreeItem>([registryExpectedContextValues.dockerHub.tag, registryExpectedContextValues.dockerV2.tag], context);
}

const commandOptions: DeployImageToAcaOptionsContract = {
const commandOptions: Partial<DeployImageToAcaOptionsContract> = {
image: node.fullTag,
};

Expand All @@ -49,24 +50,25 @@ export async function deployImageToAca(context: IActionContext, node?: RemoteTag
if (registry instanceof AzureRegistryTreeItem) {
// No additional work to do; ACA can handle this on its own
} else {
const { auth, registryPath } = await registry.getDockerCliCredentials() as { auth?: { username?: string, password?: string }, registryPath: string };
const { auth } = await registry.getDockerCliCredentials() as { auth?: { username?: string, password?: string } };

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

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)) {
// Ensure Docker Hub images are prefixed with 'docker.io/...'
if (!/^docker\.io\//i.test(commandOptions.image)) {
commandOptions.image = 'docker.io/' + commandOptions.image;
}
}

commandOptions.loginServer = registryPath;
commandOptions.username = auth.username;
commandOptions.secret = auth.password;
}

commandOptions.registryName = nonNullProp(parseDockerLikeImageName(commandOptions.image), 'registry');

// Don't wait
void vscode.commands.executeCommand('containerApps.deployImageApi', commandOptions);
}
Expand Down
4 changes: 1 addition & 3 deletions src/tree/registries/dockerHub/DockerHubNamespaceTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ 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 @@ -59,7 +57,7 @@ export class DockerHubNamespaceTreeItem extends RegistryTreeItemBase {

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