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(bazel): Support for rules_oci / oci_pull #21216

Merged
merged 3 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion docs/usage/bazel.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Renovate supports upgrading dependencies in Bazel `WORKSPACE` files.

1. Bazel support is enabled automatically
2. Renovate will search repositories for any `WORKSPACE` files in the repository
3. Existing dependencies will be extracted from `container_pull`, `git_repository`, `go_repository`, `maven_install`, and `http_archive`/`http_file` declarations
3. Existing dependencies will be extracted from `container_pull`, `oci_pull`, `git_repository`, `go_repository`, `maven_install`, and `http_archive`/`http_file` declarations
4. Renovate will replace any old versions with the latest version available

## git_repository
Expand Down
7 changes: 7 additions & 0 deletions lib/modules/manager/bazel/__fixtures__/WORKSPACE1
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ container_pull(
tag = "latest",
)

oci_pull(
name = "py3_image_base",
digest = "sha256:d5a717649fd93ea5b9c430d7f84e4c37ba219eb53bd73ed1d4a5a98e9edd84a7",
repository = "gcr.io/distroless/python3-debian10",
tag = "latest",
)

http_file(
name="distroless",
sha256="f7a6ecfb8174a1dd4713ea3b21621072996ada7e8f1a69e6ae7581be137c6dd6",
Expand Down
7 changes: 7 additions & 0 deletions lib/modules/manager/bazel/__fixtures__/oci_pull
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
oci_pull(
name="hasura",
image="index.docker.io/hasura/graphql-engine",
# v1.0.0-alpha31.cli-migrations 11/28
digest="sha256:a4e8d8c444ca04fe706649e82263c9f4c2a4229bc30d2a64561b5e1d20cc8548",
tag="v1.0.0-alpha31.cli-migrations"
)
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ exports[`modules/manager/bazel/extract extractPackageFile() extracts multiple ty
"depName": "distroless",
"depType": "http_file",
"managerData": {
"idx": 17,
"idx": 18,
},
"packageName": "GoogleContainerTools/distroless",
},
Expand Down
23 changes: 23 additions & 0 deletions lib/modules/manager/bazel/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,29 @@ describe('modules/manager/bazel/extract', () => {
]);
});

it('extracts dependencies for oci_pull deptype', () => {
const res = extractPackageFile(
codeBlock`
oci_pull(
name="hasura",
image="index.docker.io/hasura/graphql-engine",
# v1.0.0-alpha31.cli-migrations 11/28
digest="sha256:a4e8d8c444ca04fe706649e82263c9f4c2a4229bc30d2a64561b5e1d20cc8548",
tag="v1.0.0-alpha31.cli-migrations"
)
`
);
expect(res?.deps).toMatchObject([
{
currentDigest:
'sha256:a4e8d8c444ca04fe706649e82263c9f4c2a4229bc30d2a64561b5e1d20cc8548',
currentValue: 'v1.0.0-alpha31.cli-migrations',
depType: 'oci_pull',
packageName: 'index.docker.io/hasura/graphql-engine',
},
]);
});

it('check remote option in go_repository', () => {
const successStory = extractPackageFile(
codeBlock`
Expand Down
1 change: 1 addition & 0 deletions lib/modules/manager/bazel/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function extractPackageFile(
const replaceString = fragment.value;
if (
replaceString.startsWith('container_pull') ||
replaceString.startsWith('oci_pull') ||
replaceString.startsWith('git_repository') ||
replaceString.startsWith('go_repository')
) {
Expand Down
28 changes: 28 additions & 0 deletions lib/modules/manager/bazel/rules/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,34 @@ describe('modules/manager/bazel/rules/index', () => {
});
});

describe('oci', () => {
it('extracts oci dependencies', () => {
expect(
extractDepsFromFragmentData({ rule: 'foo_bar', name: 'foo_bar' })
).toBeEmptyArray();

expect(
extractDepsFromFragmentData({
rule: 'oci_pull',
name: 'foo_bar',
tag: '1.2.3',
digest: 'abcdef0123abcdef0123abcdef0123abcdef0123',
image: 'example.com/foo/bar',
})
).toEqual([
{
currentDigest: 'abcdef0123abcdef0123abcdef0123abcdef0123',
currentValue: '1.2.3',
datasource: 'docker',
depName: 'foo_bar',
depType: 'oci_pull',
packageName: 'example.com/foo/bar',
versioning: 'docker',
},
]);
});
});

describe('maven', () => {
it('extracts maven dependencies', () => {
expect(
Expand Down
3 changes: 3 additions & 0 deletions lib/modules/manager/bazel/rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { GitTarget, gitRules } from './git';
import { GoTarget, goRules } from './go';
import { HttpTarget, httpRules } from './http';
import { MavenTarget, mavenRules } from './maven';
import { OciTarget, ociRules } from './oci';

const Target = z.union([
DockerTarget,
OciTarget,
GitTarget,
GoTarget,
HttpTarget,
Expand All @@ -22,6 +24,7 @@ const Target = z.union([
*/
const supportedRules = [
...dockerRules,
...ociRules,
...gitRules,
...goRules,
...httpRules,
Expand Down
26 changes: 26 additions & 0 deletions lib/modules/manager/bazel/rules/oci.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { z } from 'zod';
import { DockerDatasource } from '../../../datasource/docker';
import { id as dockerVersioning } from '../../../versioning/docker';
import type { PackageDependency } from '../../types';

export const ociRules = ['oci_pull'] as const;

export const OciTarget = z
.object({
rule: z.enum(ociRules),
name: z.string(),
image: z.string(),
tag: z.string().optional(),
digest: z.string().optional(),
})
.transform(({ rule, name, image, tag, digest }): PackageDependency[] => [
{
datasource: DockerDatasource.id,
versioning: dockerVersioning,
depType: rule,
depName: name,
packageName: image,
currentValue: tag,
currentDigest: digest,
},
]);