Skip to content

Commit

Permalink
feat(helm): Add repo alias support (#4844)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Jacomb authored and rarkins committed Nov 24, 2019
1 parent 8d0aa39 commit cc07563
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 10 deletions.
3 changes: 3 additions & 0 deletions bin/create-json-schema.js
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;
}
if (temp.type === 'object' && !option.freeChoice) {
temp.$ref = '#';
}
Expand Down
16 changes: 16 additions & 0 deletions docs/usage/configuration-options.md
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, which contains this default repository alias:

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

Alias values must be properly formatted URIs.

## 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
14 changes: 14 additions & 0 deletions lib/config/definitions.ts
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,16 @@ const options: RenovateOptions[] = [
mergeable: true,
cli: false,
},
{
name: 'aliases',
description: 'Aliases for registries, package manager specific',
type: 'object',
default: {},
additionalProperties: {
type: 'string',
format: 'uri',
},
},
{
name: 'registryUrls',
description:
Expand Down Expand Up @@ -1604,6 +1615,9 @@ const options: RenovateOptions[] = [
stage: 'package',
type: 'object',
default: {
aliases: {
stable: 'https://kubernetes-charts.storage.googleapis.com/',
},
commitMessageTopic: 'helm chart {{depName}}',
fileMatch: ['(^|/)requirements.yaml$'],
},
Expand Down
1 change: 1 addition & 0 deletions lib/manager/common.ts
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
12 changes: 10 additions & 2 deletions lib/manager/helm-requirements/extract.ts
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,13 @@ export async function extractPackageFile(
if (dep.repository) {
res.registryUrls = [dep.repository];
if (dep.repository.startsWith('@')) {
const repoWithAtRemoved = dep.repository.slice(1);
const alias = config.aliases[repoWithAtRemoved];
if (alias) {
res.registryUrls = [alias];
return res;
}

res.skipReason = 'placeholder-url';
} else {
try {
Expand Down
13 changes: 13 additions & 0 deletions renovate-schema.json
Expand Up @@ -290,6 +290,16 @@
"default": {},
"$ref": "#"
},
"aliases": {
"description": "Aliases for registries, package manager specific",
"type": "object",
"default": {},
"additionalProperties": {
"type": "string",
"format": "uri"
},
"$ref": "#"
},
"registryUrls": {
"description": "List of URLs to try for dependency lookup. Package manager-specific",
"type": "array",
Expand Down Expand Up @@ -1058,6 +1068,9 @@
"description": "Configuration object for helm requirements.yaml files.",
"type": "object",
"default": {
"aliases": {
"stable": "https://kubernetes-charts.storage.googleapis.com/"
},
"commitMessageTopic": "helm chart {{depName}}",
"fileMatch": ["(^|/)requirements.yaml$"]
},
Expand Down
15 changes: 15 additions & 0 deletions test/manager/helm-requirements/__snapshots__/extract.spec.ts.snap
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
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

0 comments on commit cc07563

Please sign in to comment.