Skip to content

Commit

Permalink
add registryAliases support to circleci manager
Browse files Browse the repository at this point in the history
  • Loading branch information
evilensky committed Dec 6, 2024
1 parent 27b82f8 commit 7a2b07d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -3691,6 +3691,7 @@ This feature works with the following managers:

- [`ansible`](modules/manager/ansible/index.md)
- [`bitbucket-pipelines`](modules/manager/bitbucket-pipelines/index.md)
- [`circleci`](modules/manager/circleci/index.md)
- [`docker-compose`](modules/manager/docker-compose/index.md)
- [`dockerfile`](modules/manager/dockerfile/index.md)
- [`droneci`](modules/manager/droneci/index.md)
Expand Down
25 changes: 25 additions & 0 deletions lib/modules/manager/circleci/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ describe('modules/manager/circleci/extract', () => {
expect(extractPackageFile('nothing here')).toBeNull();
});

it('handles registry alias', () => {
const res = extractPackageFile(
'executors:\n my-executor:\n docker:\n - image: quay.io/myName/myPackage:0.6.2',
'',
{
registryAliases: {
'quay.io': 'my-quay-mirror.registry.com',
'index.docker.io': 'my-docker-mirror.registry.com',
},
},
);
expect(res?.deps).toEqual([
{
autoReplaceStringTemplate:
'quay.io/myName/myPackage:{{#if newValue}}{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
currentDigest: undefined,
currentValue: '0.6.2',
datasource: 'docker',
depName: 'my-quay-mirror.registry.com/myName/myPackage',
depType: 'docker',
replaceString: 'quay.io/myName/myPackage:0.6.2',
},
]);
});

it('extracts multiple image and resolves yaml anchors', () => {
const res = extractPackageFile(file1);
expect(res?.deps).toEqual([
Expand Down
7 changes: 4 additions & 3 deletions lib/modules/manager/circleci/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { parseSingleYaml } from '../../../util/yaml';
import { OrbDatasource } from '../../datasource/orb';
import * as npmVersioning from '../../versioning/npm';
import { getDep } from '../dockerfile/extract';
import type { PackageDependency, PackageFileContent } from '../types';
import type { ExtractConfig, PackageDependency, PackageFileContent } from '../types';
import { CircleCiFile, type CircleCiJob } from './schema';

export function extractPackageFile(
content: string,
packageFile?: string,
config?: ExtractConfig,
): PackageFileContent | null {
const deps: PackageDependency[] = [];
try {
Expand Down Expand Up @@ -38,15 +39,15 @@ export function extractPackageFile(
for (const job of environments) {
for (const dockerElement of coerceArray(job.docker)) {
deps.push({
...getDep(dockerElement.image),
...getDep(dockerElement.image, true, config?.registryAliases),
depType: 'docker',
});
}
}

for (const alias of coerceArray(parsed.aliases)) {
deps.push({
...getDep(alias.image),
...getDep(alias.image, true, config?.registryAliases),
depType: 'docker',
});
}
Expand Down

0 comments on commit 7a2b07d

Please sign in to comment.