diff --git a/docs/reference/action-types/Build/jib-container.md b/docs/reference/action-types/Build/jib-container.md index 87f3ec38bc4..16707de23ee 100644 --- a/docs/reference/action-types/Build/jib-container.md +++ b/docs/reference/action-types/Build/jib-container.md @@ -268,6 +268,9 @@ spec: # To ensure a system JDK usage, please set `jdkPath` to `${local.env.JAVA_HOME}`. mavendPath: + # Enable/disable concurrent Maven and Maven Daemon builds + lockAcquire: true + # Specify extra flags to pass to maven/gradle when building the container image. extraFlags: ``` @@ -726,6 +729,16 @@ To ensure a system JDK usage, please set `jdkPath` to `${local.env.JAVA_HOME}`. | -------- | -------- | | `string` | No | +### `spec.lockAcquire` + +[spec](#spec) > lockAcquire + +Enable/disable concurrent Maven and Maven Daemon builds + +| Type | Default | Required | +| --------- | ------- | -------- | +| `boolean` | `true` | No | + ### `spec.extraFlags[]` [spec](#spec) > extraFlags diff --git a/docs/reference/module-types/jib-container.md b/docs/reference/module-types/jib-container.md index 422bfd40d3d..963c85cea49 100644 --- a/docs/reference/module-types/jib-container.md +++ b/docs/reference/module-types/jib-container.md @@ -119,6 +119,9 @@ build: # To ensure a system JDK usage, please set `jdkPath` to `${local.env.JAVA_HOME}`. mavendPath: + # Enable/disable concurrent Maven and Maven Daemon builds + lockAcquire: true + # Specify extra flags to pass to maven/gradle when building the container image. extraFlags: @@ -1022,6 +1025,16 @@ To ensure a system JDK usage, please set `jdkPath` to `${local.env.JAVA_HOME}`. | -------- | -------- | | `string` | No | +### `build.lockAcquire` + +[build](#build) > lockAcquire + +Enable/disable concurrent Maven and Maven Daemon builds + +| Type | Default | Required | +| --------- | ------- | -------- | +| `boolean` | `true` | No | + ### `build.extraFlags[]` [build](#build) > extraFlags diff --git a/plugins/jib/index.ts b/plugins/jib/index.ts index 04ca525a3db..cf23ca92b2d 100644 --- a/plugins/jib/index.ts +++ b/plugins/jib/index.ts @@ -119,6 +119,11 @@ const jibBuildSchemaKeys = () => ({ **Note!** Either \`jdkVersion\` or \`jdkPath\` will be used to define \`JAVA_HOME\` environment variable for the custom Maven Daemon. To ensure a system JDK usage, please set \`jdkPath\` to \`${systemJdkGardenEnvVar}\`. `), + lockAcquire: joi + .boolean() + .optional() + .default(true) + .description("Enable/disable concurrent Maven and Maven Daemon builds"), extraFlags: joi .sparseArray() .items(joi.string()) @@ -173,7 +178,7 @@ export const gardenPlugin = () => build: async (params) => { const { ctx, log, action } = params const spec = action.getSpec() as JibBuildActionSpec - const { jdkVersion, jdkPath, mavenPhases, mavenPath, mavendPath, gradlePath } = spec + const { jdkVersion, jdkPath, mavenPhases, mavenPath, mavendPath, mavenLock, gradlePath } = spec let openJdkPath: string if (!!jdkPath) { @@ -224,6 +229,7 @@ export const gardenPlugin = () => args: [...mavenPhases, ...args], openJdkPath, mavenPath, + mavenLock, outputStream, }) } else if (projectType === "mavend") { @@ -234,6 +240,7 @@ export const gardenPlugin = () => args: [...mavenPhases, ...args], openJdkPath, mavendPath, + mavenLock, outputStream, }) } else { diff --git a/plugins/jib/maven.ts b/plugins/jib/maven.ts index 8c20e396bc1..1cce61fee79 100644 --- a/plugins/jib/maven.ts +++ b/plugins/jib/maven.ts @@ -123,6 +123,7 @@ export async function mvn({ openJdkPath, mavenPath, outputStream, + mavenLock, }: { ctx: PluginContext args: string[] @@ -131,6 +132,7 @@ export async function mvn({ openJdkPath: string mavenPath?: string outputStream?: Writable + mavenLock?: boolean }) { let mvnPath: string if (!!mavenPath) { @@ -143,11 +145,26 @@ export async function mvn({ mvnPath = await tool.ensurePath(log) } - // Maven has issues when running concurrent processes, so we're working around that with a lock. - // TODO: http://takari.io/book/30-team-maven.html would be a more robust solution. - return buildLock.acquire("mvn", async () => { - log.debug(`Execing ${mvnPath} ${args.join(" ")}`) + log.debug(`Execing ${mvnPath} ${args.join(" ")}`) + if (mavenLock) { + // Maven has issues when running concurrent processes, so we're working around that with a lock. + // TODO: http://takari.io/book/30-team-maven.html would be a more robust solution. + return buildLock.acquire("mvn", async () => { + const res = execa(mvnPath, args, { + cwd, + env: { + JAVA_HOME: openJdkPath, + }, + }) + + if (outputStream) { + res.stdout?.pipe(outputStream) + res.stderr?.pipe(outputStream) + } + return res + }) + } else { const res = execa(mvnPath, args, { cwd, env: { @@ -161,5 +178,5 @@ export async function mvn({ } return res - }) + } } diff --git a/plugins/jib/mavend.ts b/plugins/jib/mavend.ts index 24f277f75c8..122b38ad096 100644 --- a/plugins/jib/mavend.ts +++ b/plugins/jib/mavend.ts @@ -153,6 +153,7 @@ export async function mvnd({ openJdkPath, mavendPath, outputStream, + mavenLock, }: { ctx: PluginContext args: string[] @@ -161,6 +162,7 @@ export async function mvnd({ openJdkPath: string mavendPath?: string outputStream?: Writable + mavenLock?: boolean }) { let mvndPath: string if (!!mavendPath) { @@ -168,13 +170,31 @@ export async function mvnd({ mvndPath = mavendPath await verifyMavendPath(mvndPath) } else { - log.verbose(`The Maven Daemon binary hasn't been specified explicitly. Maven ${mvndVersion} will be used by default.`) + log.verbose( + `The Maven Daemon binary hasn't been specified explicitly. Maven ${mvndVersion} will be used by default.` + ) const tool = getMvndTool(ctx) mvndPath = await tool.ensurePath(log) } - return buildLock.acquire("mvnd", async () => { - log.debug(`Execing ${mvndPath} ${args.join(" ")}`) + log.debug(`Execing ${mvndPath} ${args.join(" ")}`) + if (mavenLock) { + return buildLock.acquire("mvnd", async () => { + const res = execa(mvndPath, args, { + cwd, + env: { + JAVA_HOME: openJdkPath, + }, + }) + + if (outputStream) { + res.stdout?.pipe(outputStream) + res.stderr?.pipe(outputStream) + } + + return res + }) + } else { const res = execa(mvndPath, args, { cwd, env: { @@ -188,5 +208,5 @@ export async function mvnd({ } return res - }) + } } diff --git a/plugins/jib/util.ts b/plugins/jib/util.ts index d6c9706edb0..52485b461ab 100644 --- a/plugins/jib/util.ts +++ b/plugins/jib/util.ts @@ -29,6 +29,7 @@ interface JibBuildSpec { mavenPath?: string mavendPath?: string mavenPhases: string[] + mavenLock?: boolean gradlePath?: string }