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

feat(helm): support binarySource=install #13719

Merged
merged 5 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 6 additions & 6 deletions lib/manager/helmv3/__snapshots__/artifacts.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -474,19 +474,19 @@ generated: \\"2022-01-20T17:48:47.610371241+01:00\\"
exports[`manager/helmv3/artifacts returns updated Chart.lock with docker 2`] = `
Array [
Object {
"cmd": "docker pull renovate/helm",
"cmd": "docker pull renovate/sidecar",
"options": Object {
"encoding": "utf-8",
},
},
Object {
"cmd": "docker ps --filter name=renovate_helm -aq",
"cmd": "docker ps --filter name=renovate_sidecar -aq",
"options": Object {
"encoding": "utf-8",
},
},
Object {
"cmd": "docker run --rm --name=renovate_helm --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e HELM_EXPERIMENTAL_OCI -w \\"/tmp/github/some/repo\\" renovate/helm bash -l -c \\"helm repo add repo-test --registry-config /tmp/renovate/cache/__renovate-private-cache/registry.json --repository-config /tmp/renovate/cache/__renovate-private-cache/repositories.yaml --repository-cache /tmp/renovate/cache/__renovate-private-cache/repositories https://gitlab.com/api/v4/projects/xxxxxxx/packages/helm/stable && helm dependency update --registry-config /tmp/renovate/cache/__renovate-private-cache/registry.json --repository-config /tmp/renovate/cache/__renovate-private-cache/repositories.yaml --repository-cache /tmp/renovate/cache/__renovate-private-cache/repositories ''\\"",
"cmd": "docker run --rm --name=renovate_sidecar --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e HELM_EXPERIMENTAL_OCI -w \\"/tmp/github/some/repo\\" renovate/sidecar bash -l -c \\"install-tool helm v3.7.2 && helm repo add repo-test --registry-config /tmp/renovate/cache/__renovate-private-cache/registry.json --repository-config /tmp/renovate/cache/__renovate-private-cache/repositories.yaml --repository-cache /tmp/renovate/cache/__renovate-private-cache/repositories https://gitlab.com/api/v4/projects/xxxxxxx/packages/helm/stable && helm dependency update --registry-config /tmp/renovate/cache/__renovate-private-cache/registry.json --repository-config /tmp/renovate/cache/__renovate-private-cache/repositories.yaml --repository-cache /tmp/renovate/cache/__renovate-private-cache/repositories ''\\"",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand Down Expand Up @@ -633,19 +633,19 @@ generated: \\"2022-01-20T17:48:47.610371241+01:00\\"
exports[`manager/helmv3/artifacts sets repositories from aliases with docker 2`] = `
Array [
Object {
"cmd": "docker pull renovate/helm",
"cmd": "docker pull renovate/sidecar",
"options": Object {
"encoding": "utf-8",
},
},
Object {
"cmd": "docker ps --filter name=renovate_helm -aq",
"cmd": "docker ps --filter name=renovate_sidecar -aq",
"options": Object {
"encoding": "utf-8",
},
},
Object {
"cmd": "docker run --rm --name=renovate_helm --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e HELM_EXPERIMENTAL_OCI -w \\"/tmp/github/some/repo\\" renovate/helm bash -l -c \\"helm repo add stable --registry-config /tmp/renovate/cache/__renovate-private-cache/registry.json --repository-config /tmp/renovate/cache/__renovate-private-cache/repositories.yaml --repository-cache /tmp/renovate/cache/__renovate-private-cache/repositories the_stable_url && helm repo add repo1 --registry-config /tmp/renovate/cache/__renovate-private-cache/registry.json --repository-config /tmp/renovate/cache/__renovate-private-cache/repositories.yaml --repository-cache /tmp/renovate/cache/__renovate-private-cache/repositories the_repo1_url && helm repo add repo-test --registry-config /tmp/renovate/cache/__renovate-private-cache/registry.json --repository-config /tmp/renovate/cache/__renovate-private-cache/repositories.yaml --repository-cache /tmp/renovate/cache/__renovate-private-cache/repositories https://gitlab.com/api/v4/projects/xxxxxxx/packages/helm/stable && helm dependency update --registry-config /tmp/renovate/cache/__renovate-private-cache/registry.json --repository-config /tmp/renovate/cache/__renovate-private-cache/repositories.yaml --repository-cache /tmp/renovate/cache/__renovate-private-cache/repositories ''\\"",
"cmd": "docker run --rm --name=renovate_sidecar --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e HELM_EXPERIMENTAL_OCI -w \\"/tmp/github/some/repo\\" renovate/sidecar bash -l -c \\"install-tool helm v3.7.2 && helm repo add stable --registry-config /tmp/renovate/cache/__renovate-private-cache/registry.json --repository-config /tmp/renovate/cache/__renovate-private-cache/repositories.yaml --repository-cache /tmp/renovate/cache/__renovate-private-cache/repositories the_stable_url && helm repo add repo1 --registry-config /tmp/renovate/cache/__renovate-private-cache/registry.json --repository-config /tmp/renovate/cache/__renovate-private-cache/repositories.yaml --repository-cache /tmp/renovate/cache/__renovate-private-cache/repositories the_repo1_url && helm repo add repo-test --registry-config /tmp/renovate/cache/__renovate-private-cache/registry.json --repository-config /tmp/renovate/cache/__renovate-private-cache/repositories.yaml --repository-cache /tmp/renovate/cache/__renovate-private-cache/repositories https://gitlab.com/api/v4/projects/xxxxxxx/packages/helm/stable && helm dependency update --registry-config /tmp/renovate/cache/__renovate-private-cache/registry.json --repository-config /tmp/renovate/cache/__renovate-private-cache/repositories.yaml --repository-cache /tmp/renovate/cache/__renovate-private-cache/repositories ''\\"",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand Down
10 changes: 10 additions & 0 deletions lib/manager/helmv3/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { envMock, mockExecAll } from '../../../test/exec-util';
import { loadFixture, mocked } from '../../../test/util';
import { GlobalConfig } from '../../config/global';
import type { RepoGlobalConfig } from '../../config/types';
import * as _datasource from '../../datasource';
import * as docker from '../../util/exec/docker';
import * as _env from '../../util/exec/env';
import * as hostRules from '../../util/host-rules';
Expand All @@ -13,9 +14,12 @@ import * as helmv3 from './artifacts';

jest.mock('fs-extra');
jest.mock('child_process');
jest.mock('../../datasource');
jest.mock('../../util/exec/env');
jest.mock('../../util/http');

const datasource = mocked(_datasource);

const fs: jest.Mocked<typeof _fs> = _fs as any;
const exec: jest.Mock<typeof _exec> = _exec as any;
const env = mocked(_env);
Expand Down Expand Up @@ -133,6 +137,9 @@ describe('manager/helmv3/artifacts', () => {
fs.readFile.mockResolvedValueOnce(ociLockFile1 as never);
const execSnapshots = mockExecAll(exec);
fs.readFile.mockResolvedValueOnce(ociLockFile2 as never);
datasource.getPkgReleases.mockResolvedValueOnce({
releases: [{ version: 'v3.7.2' }],
});
const updatedDeps = [{ depName: 'dep1' }];
expect(
await helmv3.updateArtifacts({
Expand Down Expand Up @@ -209,6 +216,9 @@ describe('manager/helmv3/artifacts', () => {
fs.readFile.mockResolvedValueOnce(ociLockFile1 as never);
const execSnapshots = mockExecAll(exec);
fs.readFile.mockResolvedValueOnce(ociLockFile2 as never);
datasource.getPkgReleases.mockResolvedValueOnce({
releases: [{ version: 'v3.7.2' }],
});
expect(
await helmv3.updateArtifacts({
packageFileName: 'Chart.yaml',
Expand Down
27 changes: 17 additions & 10 deletions lib/manager/helmv3/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TEMPORARY_ERROR } from '../../constants/error-messages';
import * as datasourceDocker from '../../datasource/docker';
import { logger } from '../../logger';
import { exec } from '../../util/exec';
import type { ExecOptions } from '../../util/exec/types';
import type { ExecOptions, ToolConstraint } from '../../util/exec/types';
import {
getSiblingFileName,
getSubDirectory,
Expand All @@ -23,17 +23,10 @@ import {
} from './utils';

async function helmCommands(
execOptions: ExecOptions,
manifestPath: string,
repositories: Repository[]
): Promise<void> {
const execOptions: ExecOptions = {
docker: {
image: 'helm',
},
extraEnv: {
HELM_EXPERIMENTAL_OCI: '1',
},
};
const cmd = [];
// set cache and config files to a path in privateCacheDir to prevent file and credential leakage
const helmConfigParameters = [
Expand Down Expand Up @@ -148,7 +141,21 @@ export async function updateArtifacts({

await writeLocalFile(packageFileName, newPackageFileContent);
logger.debug('Updating ' + lockFileName);
await helmCommands(packageFileName, repositories);
const helmToolConstraint: ToolConstraint = {
toolName: 'helm',
constraint: config.constraints?.helm,
};

const execOptions: ExecOptions = {
docker: {
image: 'sidecar',
},
extraEnv: {
HELM_EXPERIMENTAL_OCI: '1',
},
toolConstraints: [helmToolConstraint],
};
await helmCommands(execOptions, packageFileName, repositories);
logger.debug('Returning updated Chart.lock');
const newHelmLockContent = await readLocalFile(lockFileName, 'utf8');
if (existingLockFileContent === newHelmLockContent) {
Expand Down
5 changes: 5 additions & 0 deletions lib/util/exec/buildpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const allToolConfig: Record<string, ToolConfig> = {
depName: 'composer/composer',
versioning: composerVersioningId,
},
helm: {
datasource: 'github-releases',
depName: 'helm/helm',
versioning: semverVersioningId,
},
jb: {
datasource: 'github-releases',
depName: 'jsonnet-bundler/jsonnet-bundler',
Expand Down