-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Cloud Native Buildpacks project descriptor manager
- Loading branch information
Showing
10 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ export const Categories = [ | |
'ansible', | ||
'batect', | ||
'bazel', | ||
'buildpacks', | ||
'c', | ||
'cd', | ||
'ci', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
lib/modules/manager/cnb-project-descriptor/__fixtures__/project.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[_] | ||
schema-version = "0.2" | ||
|
||
[io.buildpacks] | ||
builder = "registry.corp/builder/noble:1.1.1" | ||
|
||
[[io.buildpacks.group]] | ||
uri = "docker://buildpacks/java:2.2.2" | ||
|
||
[[io.buildpacks.group]] | ||
uri = "buildpacks/nodejs:3.3.3" | ||
|
||
[[io.buildpacks.group]] | ||
uri = "file://local.oci" |
30 changes: 30 additions & 0 deletions
30
lib/modules/manager/cnb-project-descriptor/__snapshots__/extract.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`modules/manager/cnb-project-descriptor/extract extractPackageFile() extracts builder and buildpack images 1`] = ` | ||
[ | ||
{ | ||
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", | ||
"currentDigest": undefined, | ||
"currentValue": "1.1.1", | ||
"datasource": "docker", | ||
"depName": "registry.corp/builder/noble", | ||
"replaceString": "registry.corp/builder/noble:1.1.1", | ||
}, | ||
{ | ||
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", | ||
"currentDigest": undefined, | ||
"currentValue": "2.2.2", | ||
"datasource": "docker", | ||
"depName": "buildpacks/java", | ||
"replaceString": "buildpacks/java:2.2.2", | ||
}, | ||
{ | ||
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", | ||
"currentDigest": undefined, | ||
"currentValue": "3.3.3", | ||
"datasource": "docker", | ||
"depName": "buildpacks/nodejs", | ||
"replaceString": "buildpacks/nodejs:3.3.3", | ||
}, | ||
] | ||
`; |
21 changes: 21 additions & 0 deletions
21
lib/modules/manager/cnb-project-descriptor/extract.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Fixtures } from '../../../../test/fixtures'; | ||
|
||
import { extractPackageFile } from '.'; | ||
|
||
describe('modules/manager/cnb-project-descriptor/extract', () => { | ||
describe('extractPackageFile()', () => { | ||
it('returns null for empty', () => { | ||
expect(extractPackageFile('not a project toml', '', {})).toBeNull(); | ||
}); | ||
|
||
it('extracts builder and buildpack images', () => { | ||
const res = extractPackageFile( | ||
Fixtures.get('project.toml'), | ||
'project.toml', | ||
{}, | ||
); | ||
expect(res?.deps).toMatchSnapshot(); | ||
expect(res?.deps).toHaveLength(3); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import is from '@sindresorhus/is'; | ||
import { logger } from '../../../logger'; | ||
import { parse as parseToml } from '../../../util/toml'; | ||
import { getDep } from '../dockerfile/extract'; | ||
import type { | ||
ExtractConfig, | ||
PackageDependency, | ||
PackageFileContent, | ||
} from '../types'; | ||
import type { ProjectDescriptor } from './types'; | ||
|
||
const dockerPrefix = /^docker:\/\//; | ||
|
||
export function extractPackageFile( | ||
content: string, | ||
packageFile: string, | ||
config: ExtractConfig, | ||
): PackageFileContent | null { | ||
const deps: PackageDependency[] = []; | ||
try { | ||
const descriptor = parseToml(content) as ProjectDescriptor; | ||
if ( | ||
descriptor.io.buildpacks?.builder && | ||
!descriptor.io.buildpacks.builder.startsWith('file://') | ||
) { | ||
const dep = getDep( | ||
descriptor.io.buildpacks.builder.replace(dockerPrefix, ''), | ||
true, | ||
config.registryAliases, | ||
); | ||
logger.trace( | ||
{ | ||
depName: dep.depName, | ||
currentValue: dep.currentValue, | ||
currentDigest: dep.currentDigest, | ||
}, | ||
'Cloud Native Buildpacks builder', | ||
); | ||
|
||
deps.push(dep); | ||
} | ||
|
||
if ( | ||
descriptor.io.buildpacks?.group && | ||
is.array(descriptor.io.buildpacks.group) | ||
) { | ||
for (const group of descriptor.io.buildpacks.group) { | ||
if (group.uri && !group.uri.startsWith('file://')) { | ||
const dep = getDep( | ||
group.uri.replace(dockerPrefix, ''), | ||
true, | ||
config.registryAliases, | ||
); | ||
logger.trace( | ||
{ | ||
depName: dep.depName, | ||
currentValue: dep.currentValue, | ||
currentDigest: dep.currentDigest, | ||
}, | ||
'Cloud Native Buildpack', | ||
); | ||
|
||
deps.push(dep); | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
logger.debug( | ||
{ err, packageFile }, | ||
'Failed to parse buildpacks project descriptor TOML', | ||
); | ||
return null; | ||
} | ||
|
||
if (!deps.length) { | ||
return null; | ||
} | ||
return { deps }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { Category } from '../../../constants'; | ||
import { DockerDatasource } from '../../datasource/docker'; | ||
export { extractPackageFile } from './extract'; | ||
|
||
export const defaultConfig = { | ||
commitMessageTopic: 'buildpacks project descriptor {{depName}}', | ||
fileMatch: ['(^|/)project\\.toml$'], | ||
pinDigests: false, | ||
}; | ||
|
||
export const categories: Category[] = ['docker', 'buildpacks']; | ||
export const supportedDatasources = [DockerDatasource.id]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The `cnb-project-descriptor` manager updates Cloud Native Buildpacks project descriptor file (`project.toml`), which references builder and/or buildpack images by URIs. | ||
Updates are performed if the `project.toml` file is found and it conforms to the [project descriptor](https://github.com/buildpacks/spec/blob/main/extensions/project-descriptor.md) specification. | ||
|
||
__Note__: buildpacks in the `io.buildpacks.group` array must be configured with the docker reference (`uri`) for this manager to work. | ||
|
||
```toml | ||
[_] | ||
schema-version = "0.2" | ||
|
||
[io.buildpacks] | ||
builder = "registry.corp/builder/noble:1.1.1" | ||
|
||
[[io.buildpacks.group]] | ||
uri = "docker://buildpacks/java:2.2.2" | ||
|
||
[[io.buildpacks.group]] | ||
uri = "buildpacks/nodejs:3.3.3" | ||
|
||
[[io.buildpacks.group]] | ||
uri = "file://local.oci" # will be ignored | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export interface BuildpackGroup { | ||
uri?: string; | ||
} | ||
|
||
export interface IoBuildpacks { | ||
builder?: string; | ||
group?: BuildpackGroup[]; | ||
} | ||
|
||
export interface ProjectDescriptor { | ||
'schema-version'?: string; | ||
io: { | ||
buildpacks?: IoBuildpacks; | ||
}; | ||
} |