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): Add repo alias support #4844

Merged
merged 13 commits into from
Nov 24, 2019
3 changes: 3 additions & 0 deletions bin/create-json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ function createSingleConfig(option) {
if (option.default !== undefined) {
temp.default = option.default;
}
if (option.additionalProperties !== undefined) {
temp.additionalProperties = option.additionalProperties;
rarkins marked this conversation as resolved.
Show resolved Hide resolved
}
if (temp.type === 'object' && !option.freeChoice) {
temp.$ref = '#';
}
Expand Down
16 changes: 16 additions & 0 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ Also, be sure to check out Renovate's [shareable config presets](/config-presets

If you have any questions about the below config options, or would like to get help/feedback about a config, please post it as an issue in [renovatebot/config-help](https://github.com/renovatebot/config-help) where it will be promptly answered.

## aliases

Package managers that support repo aliases can be configured here.

Currently only helm is supported:

The default is:

```
{
"aliases": {
"stable": "https://kubernetes-charts.storage.googleapis.com/",
}
}
```

## ansible

Add configuration here if you want to enable or disable something in particular for Ansible files and override the default Docker settings.
Expand Down
13 changes: 13 additions & 0 deletions lib/config/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface RenovateStringOption extends RenovateOptionBase {

export interface RenovateObjectOption extends RenovateOptionBase {
default?: any;
additionalProperties?: {} | boolean;
mergeable?: boolean;
type: 'object';
}
Expand Down Expand Up @@ -525,6 +526,18 @@ const options: RenovateOptions[] = [
mergeable: true,
cli: false,
},
{
name: 'aliases',
description: 'Aliases for registries, package manager specific',
type: 'object',
default: {
stable: 'https://kubernetes-charts.storage.googleapis.com/',
timja marked this conversation as resolved.
Show resolved Hide resolved
},
additionalProperties: {
type: 'string',
format: 'uri',
},
},
{
name: 'registryUrls',
description:
Expand Down
1 change: 1 addition & 0 deletions lib/manager/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ExtractConfig extends ManagerConfig {
endpoint?: string;
global?: any;
gradle?: { timeout?: number };
aliases?: Record<string, string>;
ignoreNpmrcFile?: boolean;

skipInstalls?: boolean;
Expand Down
11 changes: 9 additions & 2 deletions lib/manager/helm-requirements/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import upath from 'upath';
import yaml from 'js-yaml';

import { logger } from '../../logger';
import { PackageFile, PackageDependency } from '../common';
import { PackageFile, PackageDependency, ExtractConfig } from '../common';
import { platform } from '../../platform';

export async function extractPackageFile(
content: string,
fileName: string
fileName: string,
config: ExtractConfig
): Promise<PackageFile> {
try {
const baseDir = upath.parse(fileName).dir;
Expand Down Expand Up @@ -50,6 +51,12 @@ export async function extractPackageFile(
if (dep.repository) {
res.registryUrls = [dep.repository];
if (dep.repository.startsWith('@')) {
const alias = config.aliases[dep.repository.slice(1)];
timja marked this conversation as resolved.
Show resolved Hide resolved
if (alias) {
res.registryUrls = [alias];
return res;
}

res.skipReason = 'placeholder-url';
} else {
try {
Expand Down
12 changes: 12 additions & 0 deletions renovate-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,18 @@
"default": {},
"$ref": "#"
},
"aliases": {
"description": "Aliases for registries, package manager specific",
"type": "object",
"default": {
"stable": "https://kubernetes-charts.storage.googleapis.com/"
},
"additionalProperties": {
"type": "string",
"format": "uri"
},
"$ref": "#"
},
"registryUrls": {
"description": "List of URLs to try for dependency lookup. Package manager-specific",
"type": "array",
Expand Down
15 changes: 15 additions & 0 deletions test/manager/helm-requirements/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ Object {
}
`;

exports[`lib/manager/helm/extract extractPackageFile() resolves aliased registry urls 1`] = `
Object {
"datasource": "helm",
"deps": Array [
Object {
"currentValue": "0.9.0",
"depName": "redis",
"registryUrls": Array [
"https://my-registry.gcr.io/",
],
},
],
}
`;

exports[`lib/manager/helm/extract extractPackageFile() skips invalid registry urls 1`] = `
Object {
"datasource": "helm",
Expand Down
72 changes: 64 additions & 8 deletions test/manager/helm-requirements/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ describe('lib/manager/helm/extract', () => {
version: 0.8.1
`;
const fileName = 'requirements.yaml';
const result = await extractPackageFile(content, fileName);
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://kubernetes-charts.storage.googleapis.com/',
},
});
expect(result).not.toBeNull();
expect(result).toMatchSnapshot();
expect(result.deps.every(dep => dep.skipReason));
Expand All @@ -51,7 +55,11 @@ describe('lib/manager/helm/extract', () => {
repository: https://kubernetes-charts.storage.googleapis.com/
`;
const fileName = 'requirements.yaml';
const result = await extractPackageFile(content, fileName);
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://kubernetes-charts.storage.googleapis.com/',
},
});
expect(result).not.toBeNull();
expect(result).toMatchSnapshot();
});
Expand All @@ -63,9 +71,37 @@ describe('lib/manager/helm/extract', () => {
name: example
`);
const fileName = 'requirements.yaml';
const result = await extractPackageFile('', fileName);
const result = await extractPackageFile('', fileName, {
aliases: {
stable: 'https://kubernetes-charts.storage.googleapis.com/',
},
});
expect(result).toBeNull();
});
it('resolves aliased registry urls', async () => {
platform.getFile.mockReturnValueOnce(`
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: example
version: 0.1.0
`);
const content = `
dependencies:
- name: redis
version: 0.9.0
repository: '@placeholder'
`;
const fileName = 'requirements.yaml';
const result = await extractPackageFile(content, fileName, {
aliases: {
placeholder: 'https://my-registry.gcr.io/',
},
});
expect(result).not.toBeNull();
expect(result).toMatchSnapshot();
expect(result.deps.every(dep => dep.skipReason));
});
it("doesn't fail if Chart.yaml is invalid", async () => {
platform.getFile.mockReturnValueOnce(`
Invalid Chart.yaml content.
Expand All @@ -82,7 +118,11 @@ describe('lib/manager/helm/extract', () => {
repository: https://kubernetes-charts.storage.googleapis.com/
`;
const fileName = 'requirements.yaml';
const result = await extractPackageFile(content, fileName);
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://kubernetes-charts.storage.googleapis.com/',
},
});
expect(result).toBeNull();
});
it('skips local dependencies', async () => {
Expand All @@ -103,7 +143,11 @@ describe('lib/manager/helm/extract', () => {
repository: file:///some/local/path/
`;
const fileName = 'requirements.yaml';
const result = await extractPackageFile(content, fileName);
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://kubernetes-charts.storage.googleapis.com/',
},
});
expect(result).not.toBeNull();
expect(result).toMatchSnapshot();
});
Expand All @@ -119,7 +163,11 @@ describe('lib/manager/helm/extract', () => {
hello: world
`;
const fileName = 'requirements.yaml';
const result = await extractPackageFile(content, fileName);
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://kubernetes-charts.storage.googleapis.com/',
},
});
expect(result).toBeNull();
});
it('returns null if requirements.yaml is invalid', async () => {
Expand All @@ -136,13 +184,21 @@ describe('lib/manager/helm/extract', () => {
[
`;
const fileName = 'requirements.yaml';
const result = await extractPackageFile(content, fileName);
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://kubernetes-charts.storage.googleapis.com/',
},
});
expect(result).toBeNull();
});
it('returns null if Chart.yaml is empty', async () => {
const content = '';
const fileName = 'requirements.yaml';
const result = await extractPackageFile(content, fileName);
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://kubernetes-charts.storage.googleapis.com/',
},
});
expect(result).toBeNull();
});
});
Expand Down