From 9449f5558db65323042d1e7c40dd78c432c8cc2c Mon Sep 17 00:00:00 2001 From: Michael Vitz Date: Mon, 2 Sep 2024 19:27:41 +0200 Subject: [PATCH] feat(presets/workarounds): Support bellsoft/liberica-runtime-container Image (#31082) --- .../presets/internal/workarounds.spec.ts | 166 ++++++++++++++++-- lib/config/presets/internal/workarounds.ts | 40 +++++ 2 files changed, 195 insertions(+), 11 deletions(-) diff --git a/lib/config/presets/internal/workarounds.spec.ts b/lib/config/presets/internal/workarounds.spec.ts index f0d8440bbb9917..3be4fcca93e2e4 100644 --- a/lib/config/presets/internal/workarounds.spec.ts +++ b/lib/config/presets/internal/workarounds.spec.ts @@ -1,16 +1,14 @@ -import { regEx } from '../../../util/regex'; +import * as versionings from '../../../modules/versioning'; +import { matchRegexOrGlob } from '../../../util/string-match'; import { presets } from './workarounds'; describe('config/presets/internal/workarounds', () => { describe('bitnamiDockerImageVersioning', () => { - const versioning = presets.bitnamiDockerImageVersioning.packageRules![0] - .versioning as string; - const versioningRe = regEx(versioning.substring(6)); - const matchCurrentValue = presets.bitnamiDockerImageVersioning - .packageRules![0].matchCurrentValue as string; - const matchCurrentValueRe = regEx( - matchCurrentValue.substring(1, matchCurrentValue.length - 1), - ); + const preset = presets.bitnamiDockerImageVersioning; + const packageRule = preset.packageRules![0]; + + const versioning = versionings.get(packageRule.versioning as string); + const matchCurrentValue = packageRule.matchCurrentValue!; it.each` input | expected @@ -24,7 +22,7 @@ describe('config/presets/internal/workarounds', () => { ${'1.24.0-debian-12'} | ${true} ${'1.24.0-debian-12-r24'} | ${true} `('versioning("$input") == "$expected"', ({ input, expected }) => { - expect(versioningRe.test(input)).toEqual(expected); + expect(versioning.isValid(input)).toEqual(expected); }); it.each` @@ -39,7 +37,153 @@ describe('config/presets/internal/workarounds', () => { ${'1.24.0-debian-12'} | ${true} ${'1.24.0-debian-12-r24'} | ${true} `('matchCurrentValue("$input") == "$expected"', ({ input, expected }) => { - expect(matchCurrentValueRe.test(input)).toEqual(expected); + expect(matchRegexOrGlob(input, matchCurrentValue)).toEqual(expected); + }); + }); + + describe('libericaJdkDockerVersioning', () => { + const preset = presets.libericaJdkDockerVersioning; + + describe('Liberica JDK Lite', () => { + const packageRule = preset.packageRules![0]; + + const versioning = versionings.get(packageRule.versioning as string); + + const matchCurrentValue = packageRule.matchCurrentValue!; + + it.each` + input | expected + ${'jdk-17-glibc'} | ${true} + ${'jdk-all-17-glibc'} | ${false} + ${'jre-17-glibc'} | ${false} + ${'jdk-21-crac-slim-glibc'} | ${true} + ${'jdk-all-21-crac-slim-glibc'} | ${false} + ${'jre-21-crac-slim-glibc'} | ${false} + ${'jdk-11-slim-musl'} | ${true} + ${'jdk-all-11-slim-musl'} | ${false} + ${'jre-11-slim-musl'} | ${false} + `('versioning("$input") == "$expected"', ({ input, expected }) => { + expect(versioning.isValid(input)).toEqual(expected); + }); + + it.each` + input | expected + ${'jdk-17-glibc'} | ${true} + ${'jdk-all-17-glibc'} | ${false} + ${'jre-17-glibc'} | ${false} + ${'jdk-21-crac-slim-glibc'} | ${true} + ${'jdk-all-21-crac-slim-glibc'} | ${false} + ${'jre-21-crac-slim-glibc'} | ${false} + ${'jdk-11-slim-musl'} | ${true} + ${'jdk-all-11-slim-musl'} | ${false} + ${'jre-11-slim-musl'} | ${false} + `('matchCurrentValue("$input") == "$expected"', ({ input, expected }) => { + expect(matchRegexOrGlob(input, matchCurrentValue)).toEqual(expected); + }); + }); + + describe('Liberica JDK', () => { + const packageRule = preset.packageRules![1]; + + const versioning = versionings.get(packageRule.versioning as string); + + const matchCurrentValue = packageRule.matchCurrentValue!; + + it.each` + input | expected + ${'jdk-17-glibc'} | ${false} + ${'jdk-all-17-glibc'} | ${true} + ${'jre-17-glibc'} | ${false} + ${'jdk-21-crac-slim-glibc'} | ${false} + ${'jdk-all-21-crac-slim-glibc'} | ${true} + ${'jre-21-crac-slim-glibc'} | ${false} + ${'jdk-11-slim-musl'} | ${false} + ${'jdk-all-11-slim-musl'} | ${true} + ${'jre-11-slim-musl'} | ${false} + `('versioning("$input") == "$expected"', ({ input, expected }) => { + expect(versioning.isValid(input)).toEqual(expected); + }); + + it.each` + input | expected + ${'jdk-17-glibc'} | ${false} + ${'jdk-all-17-glibc'} | ${true} + ${'jre-17-glibc'} | ${false} + ${'jdk-21-crac-slim-glibc'} | ${false} + ${'jdk-all-21-crac-slim-glibc'} | ${true} + ${'jre-21-crac-slim-glibc'} | ${false} + ${'jdk-11-slim-musl'} | ${false} + ${'jdk-all-11-slim-musl'} | ${true} + ${'jre-11-slim-musl'} | ${false} + `('matchCurrentValue("$input") == "$expected"', ({ input, expected }) => { + expect(matchRegexOrGlob(input, matchCurrentValue)).toEqual(expected); + }); + }); + + describe('Liberica JRE', () => { + const packageRule = preset.packageRules![2]; + + const versioning = versionings.get(packageRule.versioning as string); + + const matchCurrentValue = packageRule.matchCurrentValue!; + + it.each` + input | expected + ${'jdk-17-glibc'} | ${false} + ${'jdk-all-17-glibc'} | ${false} + ${'jre-17-glibc'} | ${true} + ${'jdk-21-crac-slim-glibc'} | ${false} + ${'jdk-all-21-crac-slim-glibc'} | ${false} + ${'jre-21-crac-slim-glibc'} | ${true} + ${'jdk-11-slim-musl'} | ${false} + ${'jdk-all-11-slim-musl'} | ${false} + ${'jre-11-slim-musl'} | ${true} + `('versioning("$input") == "$expected"', ({ input, expected }) => { + expect(versioning.isValid(input)).toEqual(expected); + }); + + it.each` + input | expected + ${'jdk-17-glibc'} | ${false} + ${'jdk-all-17-glibc'} | ${false} + ${'jre-17-glibc'} | ${true} + ${'jdk-21-crac-slim-glibc'} | ${false} + ${'jdk-all-21-crac-slim-glibc'} | ${false} + ${'jre-21-crac-slim-glibc'} | ${true} + ${'jdk-11-slim-musl'} | ${false} + ${'jdk-all-11-slim-musl'} | ${false} + ${'jre-11-slim-musl'} | ${true} + `('matchCurrentValue("$input") == "$expected"', ({ input, expected }) => { + expect(matchRegexOrGlob(input, matchCurrentValue)).toEqual(expected); + }); + }); + }); + + describe('javaLTSVersions', () => { + const preset = presets.javaLTSVersions; + + describe('bellsoft/liberica-runtime-container', () => { + const packageRule = preset.packageRules![2]; + + const allowedVersions = packageRule.allowedVersions as string; + + it.each` + input | expected + ${'jdk-11-slim-musl'} | ${true} + ${'jdk-all-11-slim-musl'} | ${true} + ${'jre-11-slim-musl'} | ${true} + ${'jdk-17-glibc'} | ${true} + ${'jdk-all-17-glibc'} | ${true} + ${'jre-17-glibc'} | ${true} + ${'jdk-21-crac-slim-glibc'} | ${true} + ${'jdk-all-21-crac-slim-glibc'} | ${true} + ${'jre-21-crac-slim-glibc'} | ${true} + ${'jdk-22-crac-slim-glibc'} | ${false} + ${'jdk-all-22-crac-slim-glibc'} | ${false} + ${'jre-22-crac-slim-glibc'} | ${false} + `('allowedVersisons("$input") == "$expected"', ({ input, expected }) => { + expect(matchRegexOrGlob(input, allowedVersions)).toEqual(expected); + }); }); }); }); diff --git a/lib/config/presets/internal/workarounds.ts b/lib/config/presets/internal/workarounds.ts index 8b17b6ccedf375..8f6cabced7a62a 100644 --- a/lib/config/presets/internal/workarounds.ts +++ b/lib/config/presets/internal/workarounds.ts @@ -23,6 +23,7 @@ export const presets: Record = { 'workarounds:bitnamiDockerImageVersioning', 'workarounds:k3sKubernetesVersioning', 'workarounds:rke2KubernetesVersioning', + 'workarounds:libericaJdkDockerVersioning', ], ignoreDeps: [], // Hack to improve onboarding PR description }, @@ -167,6 +168,13 @@ export const presets: Record = { versioning: 'regex:^(?\\d+)?(\\.(?\\d+))?(\\.(?\\d+))?([\\._+](?(\\d\\.?)+)(LTS)?)?(-(?.*))?$', }, + { + allowedVersions: '/^(?:jdk|jdk-all|jre)-(?:8|11|17|21)(?:\\.|-|$)/', + description: + 'Limit Java runtime versions to LTS releases. To receive all major releases add `workarounds:javaLTSVersions` to the `ignorePresets` array.', + matchDatasources: ['docker'], + matchPackageNames: ['bellsoft/liberica-runtime-container'], + }, ], }, k3sKubernetesVersioning: { @@ -180,6 +188,38 @@ export const presets: Record = { }, ], }, + libericaJdkDockerVersioning: { + description: + 'Use custom regex versioning for bellsoft/liberica-runtime-container', + packageRules: [ + { + description: 'Liberica JDK Lite version optimized for the Cloud', + matchCurrentValue: '/^jdk-[^a][^l]{2}/', + matchDatasources: ['docker'], + matchPackageNames: ['bellsoft/liberica-runtime-container'], + versioning: + 'regex:^jdk-(?\\d+)?(\\.(?\\d+))?(\\.(?\\d+))?([\\._+](?(\\d\\.?)+))?(-(?.*))?$', + }, + { + description: + 'Liberica JDK that can be used to create a custom runtime with a help of jlink tool', + matchCurrentValue: '/^jdk-all/', + matchDatasources: ['docker'], + matchPackageNames: ['bellsoft/liberica-runtime-container'], + versioning: + 'regex:^jdk-all-(?\\d+)?(\\.(?\\d+))?(\\.(?\\d+))?([\\._+](?(\\d\\.?)+))?(-(?.*))?$', + }, + { + description: + 'Liberica JRE (only the runtime without the rest of JDK tools) for running Java applications', + matchCurrentValue: '/^jre-/', + matchDatasources: ['docker'], + matchPackageNames: ['bellsoft/liberica-runtime-container'], + versioning: + 'regex:^jre-(?\\d+)?(\\.(?\\d+))?(\\.(?\\d+))?([\\._+](?(\\d\\.?)+))?(-(?.*))?$', + }, + ], + }, mavenCommonsAncientVersion: { description: 'Fix some problems with very old Maven commons versions.', packageRules: [