Skip to content

Commit

Permalink
feat(core): centralize sidecar image usage (#19545)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Dec 23, 2022
1 parent f5548af commit 73be295
Show file tree
Hide file tree
Showing 28 changed files with 70 additions and 165 deletions.
2 changes: 1 addition & 1 deletion lib/modules/manager/bundler/artifacts.ts
Expand Up @@ -166,7 +166,7 @@ export async function updateArtifacts(
...bundlerHostRulesVariables,
GEM_HOME: await ensureCacheDir('bundler'),
},
docker: { image: 'sidecar' },
docker: {},
toolConstraints: [
{
toolName: 'ruby',
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/cargo/artifacts.ts
Expand Up @@ -23,9 +23,7 @@ async function cargoUpdate(
}

const execOptions: ExecOptions = {
docker: {
image: 'sidecar',
},
docker: {},
toolConstraints: [{ toolName: 'rust', constraint }],
};
await exec(cmd, execOptions);
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/cocoapods/artifacts.ts
Expand Up @@ -75,7 +75,7 @@ export async function updateArtifacts({
extraEnv: {
CP_HOME_DIR: await ensureCacheDir('cocoapods'),
},
docker: { image: 'sidecar' },
docker: {},
toolConstraints: [
{
toolName: 'ruby',
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/composer/artifacts.ts
Expand Up @@ -117,9 +117,7 @@ export async function updateArtifacts({
COMPOSER_AUTH: getAuthJson(),
},
toolConstraints: [phpToolConstraint, composerToolConstraint],
docker: {
image: 'sidecar',
},
docker: {},
};

const commands: string[] = [];
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/flux/artifacts.ts
Expand Up @@ -24,9 +24,7 @@ export async function updateArtifacts({
}
const cmd = `flux install ${args.join(' ')} > ${quote(packageFileName)}`;
const execOptions: ExecOptions = {
docker: {
image: 'sidecar',
},
docker: {},
toolConstraints: [
{
toolName: 'flux',
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/gomod/artifacts.ts
Expand Up @@ -259,9 +259,7 @@ export async function updateArtifacts({
CGO_ENABLED: GlobalConfig.get('binarySource') === 'docker' ? '0' : null,
...getGitEnvironmentVariables(),
},
docker: {
image: 'sidecar',
},
docker: {},
toolConstraints: [
{
toolName: 'golang',
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/gradle-wrapper/artifacts.ts
Expand Up @@ -147,9 +147,7 @@ export async function updateArtifacts({
logger.debug(`Updating gradle wrapper: "${cmd}"`);
const execOptions: ExecOptions = {
cwdFile: gradlewFile,
docker: {
image: 'sidecar',
},
docker: {},
extraEnv,
toolConstraints: [
{
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/gradle/artifacts.ts
Expand Up @@ -136,9 +136,7 @@ export async function updateArtifacts({
let cmd = `${gradlewName} --console=plain -q`;
const execOptions: ExecOptions = {
cwdFile: gradlewFile,
docker: {
image: 'sidecar',
},
docker: {},
extraEnv,
toolConstraints: [
{
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/helmv3/artifacts.ts
Expand Up @@ -157,9 +157,7 @@ export async function updateArtifacts({
};

const execOptions: ExecOptions = {
docker: {
image: 'sidecar',
},
docker: {},
extraEnv: {
HELM_EXPERIMENTAL_OCI: '1',
},
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/hermit/artifacts.ts
Expand Up @@ -205,9 +205,7 @@ async function updateHermitPackage(update: UpdateArtifact): Promise<void> {
}

const execOptions: ExecOptions = {
docker: {
image: 'sidecar',
},
docker: {},
cwdFile: update.packageFileName,
};

Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/jsonnet-bundler/artifacts.ts
Expand Up @@ -41,9 +41,7 @@ export async function updateArtifacts(

const execOptions: ExecOptions = {
cwdFile: packageFileName,
docker: {
image: 'sidecar',
},
docker: {},
toolConstraints: [jsonnetBundlerToolConstraint],
};

Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/mix/artifacts.ts
Expand Up @@ -75,9 +75,7 @@ export async function updateArtifacts({

const execOptions: ExecOptions = {
cwdFile: packageFileName,
docker: {
image: 'sidecar',
},
docker: {},
toolConstraints: [
{
toolName: 'erlang',
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/nix/artifacts.ts
Expand Up @@ -46,9 +46,7 @@ export async function updateArtifacts({
constraint: config.constraints?.nix,
},
],
docker: {
image: 'sidecar',
},
docker: {},
};

try {
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/npm/post-update/lerna.ts
Expand Up @@ -91,9 +91,7 @@ export async function generateLockFiles(
const execOptions: ExecOptions = {
cwdFile: upath.join(lockFileDir, 'package.json'),
extraEnv,
docker: {
image: 'sidecar',
},
docker: {},
toolConstraints,
};
// istanbul ignore if
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/npm/post-update/npm.ts
Expand Up @@ -66,9 +66,7 @@ export async function generateLockFile(
await getNodeToolConstraint(config, upgrades, lockFileDir),
npmToolConstraint,
],
docker: {
image: 'sidecar',
},
docker: {},
};
// istanbul ignore if
if (GlobalConfig.get('exposeAllEnv')) {
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/npm/post-update/pnpm.ts
Expand Up @@ -42,9 +42,7 @@ export async function generateLockFile(
const execOptions: ExecOptions = {
cwdFile: lockFileName,
extraEnv,
docker: {
image: 'sidecar',
},
docker: {},
toolConstraints: [
await getNodeToolConstraint(config, upgrades, lockFileDir),
pnpmToolConstraint,
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/npm/post-update/yarn.ts
Expand Up @@ -187,9 +187,7 @@ export async function generateLockFile(
const execOptions: ExecOptions = {
cwdFile: lockFileName,
extraEnv,
docker: {
image: 'sidecar',
},
docker: {},
toolConstraints,
};
// istanbul ignore if
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/nuget/artifacts.ts
Expand Up @@ -68,9 +68,7 @@ async function runDotnetRestore(
const nugetCacheDir = join(privateCacheDir(), 'nuget');

const execOptions: ExecOptions = {
docker: {
image: 'sidecar',
},
docker: {},
extraEnv: {
NUGET_PACKAGES: join(nugetCacheDir, 'packages'),
MSBUILDDISABLENODEREUSE: '1',
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/pip-compile/artifacts.ts
Expand Up @@ -125,9 +125,7 @@ export async function updateArtifacts({
const pipToolsConstraint = getPipToolsConstraint(config);
const execOptions: ExecOptions = {
cwdFile: inputFileName,
docker: {
image: 'sidecar',
},
docker: {},
preCommands: [
`pip install --user ${quote(`pip-tools${pipToolsConstraint}`)}`,
],
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/pip_requirements/artifacts.ts
Expand Up @@ -68,9 +68,7 @@ export async function updateArtifacts({
}
const execOptions: ExecOptions = {
cwdFile: '.',
docker: {
image: 'sidecar',
},
docker: {},
preCommands: ['pip install --user hashin'],
toolConstraints: [
{ toolName: 'python', constraint: config.constraints?.python },
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/pipenv/artifacts.ts
Expand Up @@ -101,9 +101,7 @@ export async function updateArtifacts({
PIPENV_CACHE_DIR: await ensureCacheDir('pipenv'),
PIP_CACHE_DIR: await ensureCacheDir('pip'),
},
docker: {
image: 'sidecar',
},
docker: {},
preCommands: [`pip install --user ${quote(`pipenv${pipenvConstraint}`)}`],
toolConstraints: [
{
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/poetry/artifacts.ts
Expand Up @@ -184,9 +184,7 @@ export async function updateArtifacts({
const execOptions: ExecOptions = {
cwdFile: packageFileName,
extraEnv,
docker: {
image: 'sidecar',
},
docker: {},
toolConstraints: [{ toolName: 'python', constraint }],
preCommands: [
`pip install --user ${quote(`poetry${poetryVersion ?? ''}`)}`,
Expand Down
41 changes: 13 additions & 28 deletions lib/util/exec/docker/index.spec.ts
Expand Up @@ -11,6 +11,7 @@ import {
removeDanglingContainers,
removeDockerContainer,
resetPrefetchedImages,
sideCarImage,
} from '.';

const getPkgReleases: jest.Mock<typeof _getPkgReleases> =
Expand Down Expand Up @@ -202,15 +203,14 @@ describe('util/exec/docker/index', () => {
const preCommands = [null as never, 'foo', undefined as never];
const commands = ['bar'];
const envVars = ['FOO', 'BAR'];
const image = 'sample_image';
const image = sideCarImage;
const dockerOptions = {
image,
cwd: '/tmp/foobar',
envVars,
};
const command = (img: string, vol?: string): string =>
`docker run --rm ` +
`--name=renovate_sample_image ` +
`--name=renovate_${img} ` +
`--label=renovate_child ` +
`--user=some-user ` +
(vol ? `${vol} ` : '') +
Expand Down Expand Up @@ -289,30 +289,15 @@ describe('util/exec/docker/index', () => {
);
});

it('handles tag parameter', async () => {
mockExecAll();
const res = await generateDockerCommand(commands, preCommands, {
...dockerOptions,
tag: '1.2.3',
});
expect(res).toBe(command(`${image}:1.2.3`));
});

it('handles tag constraint', async () => {
mockExecAll();
getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: '1.2.3' },
{ version: '1.2.4' },
{ version: '2.0.0' },
],
} as never);
const res = await generateDockerCommand(commands, preCommands, {
...dockerOptions,
tagScheme: 'npm',
tagConstraint: '^1.2.3',
});
expect(res).toBe(command(`${image}:1.2.4`));
});
// TODO: it('handles tag constraint', async () => {
// mockExecAll();
// getPkgReleases.mockResolvedValueOnce({
// releases: [{ version: '5.5.5' }, { version: '6.0.0' }],
// } as never);
// const res = await generateDockerCommand(commands, preCommands, {
// ...dockerOptions,
// });
// expect(res).toBe(command(`${image}:5.5.5`));
// });
});
});
26 changes: 10 additions & 16 deletions lib/util/exec/docker/index.ts
Expand Up @@ -13,6 +13,8 @@ const prefetchedImages = new Map<string, string>();

const digestRegex = regEx('Digest: (.*?)\n');

export const sideCarImage = 'sidecar';

export async function prefetchDockerImage(taggedImage: string): Promise<void> {
if (prefetchedImages.has(taggedImage)) {
logger.debug(
Expand Down Expand Up @@ -211,8 +213,8 @@ export async function generateDockerCommand(
preCommands: string[],
options: DockerOptions
): Promise<string> {
const { envVars, cwd, tagScheme, tagConstraint } = options;
let image = options.image;
const { envVars, cwd } = options;
let image = sideCarImage;
const volumes = options.volumes ?? [];
const {
localDir,
Expand Down Expand Up @@ -259,21 +261,13 @@ export async function generateDockerCommand(

image = `${ensureTrailingSlash(dockerImagePrefix ?? 'renovate')}${image}`;

let tag: string | null = null;
if (options.tag) {
tag = options.tag;
} else if (tagConstraint) {
const tagVersioning = tagScheme ?? 'semver';
tag = await getDockerTag(image, tagConstraint, tagVersioning);
logger.debug(
{ image, tagConstraint, tagVersioning, tag },
'Resolved tag constraint'
);
} else {
logger.debug(`No tag or tagConstraint specified for image: ${image}`);
}
// TODO: add constraint: const tag = getDockerTag(image, sideCarImageVersion, 'semver');
logger.debug(
{ image /*, tagConstraint: sideCarImageVersion, tag */ },
'Resolved tag constraint'
);

const taggedImage = tag ? `${image}:${tag}` : `${image}`;
const taggedImage = image; // TODO: tag ? `${image}:${tag}` : `${image}`;
await prefetchDockerImage(taggedImage);
result.push(taggedImage);

Expand Down

0 comments on commit 73be295

Please sign in to comment.