Skip to content

Commit

Permalink
Qualify local image for Podman (microsoft/vscode-remote-release#9748)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Apr 18, 2024
1 parent 6710d4c commit 8c44fd0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/spec-node/containerFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export async function updateRemoteUserUID(params: DockerResolverParameters, merg
'-f', destDockerfile,
'-t', fixedImageName,
...(platform ? ['--platform', platform] : []),
'--build-arg', `BASE_IMAGE=${imageName}`,
'--build-arg', `BASE_IMAGE=${params.isPodman ? 'localhost/' : ''}${imageName}`, // Podman: https://github.com/microsoft/vscode-remote-release/issues/9748
'--build-arg', `REMOTE_USER=${remoteUser}`,
'--build-arg', `NEW_UID=${await cliHost.getuid!()}`,
'--build-arg', `NEW_GID=${await cliHost.getgid!()}`,
Expand Down
3 changes: 2 additions & 1 deletion src/spec-node/devContainers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { LogLevel, LogDimensions, toErrorText, createCombinedLog, createTerminal
import { dockerComposeCLIConfig } from './dockerCompose';
import { Mount } from '../spec-configuration/containerFeaturesConfiguration';
import { getPackageConfig, PackageConfiguration } from '../spec-utils/product';
import { dockerBuildKitVersion } from '../spec-shutdown/dockerUtils';
import { dockerBuildKitVersion, isPodman } from '../spec-shutdown/dockerUtils';
import { Event } from '../spec-utils/event';


Expand Down Expand Up @@ -203,6 +203,7 @@ export async function createDockerParams(options: ProvisionOptions, disposables:
common,
parsedAuthority,
dockerCLI: dockerPath,
isPodman: await isPodman({ exec: cliHost.exec, cmd: dockerPath, env: cliHost.env, output }),
dockerComposeCLI: dockerComposeCLI,
dockerEnv: cliHost.env,
workspaceMountConsistencyDefault: workspaceMountConsistency,
Expand Down
1 change: 1 addition & 0 deletions src/spec-node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export interface DockerResolverParameters {
common: ResolverParameters;
parsedAuthority: ParsedAuthority | undefined;
dockerCLI: string;
isPodman: boolean;
dockerComposeCLI: () => Promise<DockerComposeCLI>;
dockerEnv: NodeJS.ProcessEnv;
workspaceMountConsistencyDefault: BindMountConsistency;
Expand Down
11 changes: 4 additions & 7 deletions src/spec-shutdown/dockerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface PartialPtyExecParameters {

interface DockerResolverParameters {
dockerCLI: string;
isPodman: boolean;
dockerComposeCLI: () => Promise<DockerComposeCLI>;
dockerEnv: NodeJS.ProcessEnv;
common: {
Expand Down Expand Up @@ -167,15 +168,15 @@ export async function listContainers(params: DockerCLIParameters | PartialExecPa
.filter(s => !!s);
}

export async function getEvents(params: DockerCLIParameters | DockerResolverParameters, filters?: Record<string, string[]>) {
export async function getEvents(params: DockerResolverParameters, filters?: Record<string, string[]>) {
const { exec, cmd, args, env, output } = toExecParameters(params);
const filterArgs = [];
for (const filter in filters) {
for (const value of filters[filter]) {
filterArgs.push('--filter', `${filter}=${value}`);
}
}
const format = await isPodman(params) ? 'json' : '{{json .}}'; // https://github.com/containers/libpod/issues/5981
const format = params.isPodman ? 'json' : '{{json .}}'; // https://github.com/containers/libpod/issues/5981
const combinedArgs = (args || []).concat(['events', '--format', format, ...filterArgs]);

const p = await exec({
Expand Down Expand Up @@ -228,11 +229,7 @@ export async function dockerCLI(params: DockerCLIParameters | PartialExecParamet
});
}

export async function isPodman(params: DockerCLIParameters | DockerResolverParameters) {
const cliHost = 'cliHost' in params ? params.cliHost : params.common.cliHost;
if (cliHost.platform !== 'linux') {
return false;
}
export async function isPodman(params: PartialExecParameters) {
try {
const { stdout } = await dockerCLI(params, '-v');
return stdout.toString().toLowerCase().indexOf('podman') !== -1;
Expand Down

0 comments on commit 8c44fd0

Please sign in to comment.