Skip to content

Commit

Permalink
improvement(maven-container): add JDK 13 support + some tweaks and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Oct 30, 2019
1 parent 59fef9f commit 8cddab8
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 105 deletions.
54 changes: 16 additions & 38 deletions docs/reference/module-types/maven-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,21 @@ tasks:
key: some-key
```

### `imageVersion`

Set this to override the default OpenJDK container image version. Make sure the image version matches the
configured `jdkVersion`. Ignored if you provide your own Dockerfile.

| Type | Required |
| -------- | -------- |
| `string` | No |

Example:

```yaml
imageVersion: "11-jdk"
```

### `jarPath`

POSIX-style path to the packaged JAR artifact, relative to the module directory.
Expand Down Expand Up @@ -1140,6 +1155,7 @@ tasks:
command:
args:
env: {}
imageVersion:
jarPath:
jdkVersion: 8
mvnOpts: []
Expand Down Expand Up @@ -1194,41 +1210,3 @@ Example:
my-variable: ${modules.my-module.version}
```

### `${modules.<module-name>.outputs}`

| Type | Required |
| -------- | -------- |
| `object` | Yes |

### `${modules.<module-name>.outputs.local-image-name}`

[outputs](#outputs) > local-image-name

The name of the image (without tag/version) that the module uses for local builds and deployments.

| Type | Required |
| -------- | -------- |
| `string` | Yes |

Example:

```yaml
my-variable: ${modules.my-module.outputs.local-image-name}
```

### `${modules.<module-name>.outputs.deployment-image-name}`

[outputs](#outputs) > deployment-image-name

The name of the image (without tag/version) that the module will use during deployment.

| Type | Required |
| -------- | -------- |
| `string` | Yes |

Example:

```yaml
my-variable: ${modules.my-module.outputs.deployment-image-name}
```

23 changes: 16 additions & 7 deletions garden-service/src/plugins/maven-container/maven-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ import { ConfigureModuleParams } from "../../types/plugin/module/configure"
import { GetBuildStatusParams } from "../../types/plugin/module/getBuildStatus"
import { BuildModuleParams } from "../../types/plugin/module/build"

const defaultDockerfilePath = resolve(STATIC_DIR, "maven-container", "Dockerfile")
const defaultDockerfileName = "maven-container.Dockerfile"
const defaultDockerfilePath = resolve(STATIC_DIR, "maven-container", defaultDockerfileName)

const buildLock = new AsyncLock()

export interface MavenContainerModuleSpec extends ContainerModuleSpec {
imageVersion?: string
jarPath: string
jdkVersion: number
mvnOpts: string[]
Expand All @@ -54,14 +57,20 @@ export interface MavenContainerModule<
> extends Module<M, S, T, W> { }

const mavenKeys = {
imageVersion: joi.string()
.description(dedent`
Set this to override the default OpenJDK container image version. Make sure the image version matches the
configured \`jdkVersion\`. Ignored if you provide your own Dockerfile.
`)
.example("11-jdk"),
jarPath: joi.string()
.required()
.posixPath({ subPathOnly: true })
.description("POSIX-style path to the packaged JAR artifact, relative to the module directory.")
.example("target/my-module.jar"),
jdkVersion: joi.number()
.integer()
.allow(8, 11)
.allow(...Object.keys(openJdks))
.default(8)
.description("The JDK version to use."),
mvnOpts: joiArray(joi.string())
Expand Down Expand Up @@ -113,8 +122,7 @@ export async function configureMavenContainerModule(params: ConfigureModuleParam
const jdkVersion = moduleConfig.spec.jdkVersion!

containerConfig.spec.buildArgs = {
JAR_PATH: "app.jar",
JDK_VERSION: jdkVersion.toString(),
IMAGE_VERSION: moduleConfig.spec.imageVersion || `${jdkVersion}-jdk`,
}

const configured = await base!({ ...params, moduleConfig: containerConfig })
Expand All @@ -128,6 +136,7 @@ export async function configureMavenContainerModule(params: ConfigureModuleParam
jarPath: moduleConfig.spec.jarPath,
jdkVersion,
mvnOpts: moduleConfig.spec.mvnOpts,
dockerfile: moduleConfig.spec.dockerfile || defaultDockerfileName,
},
},
}
Expand Down Expand Up @@ -172,7 +181,7 @@ async function build(params: BuildModuleParams<MavenContainerModule>) {
await buildLock.acquire("mvn", async () => {
await maven.exec({
args: mvnArgs,
cwd: ctx.projectRoot,
cwd: module.path,
log,
env: {
JAVA_HOME: openJdkPath,
Expand Down Expand Up @@ -200,9 +209,9 @@ async function build(params: BuildModuleParams<MavenContainerModule>) {
async function prepareBuild(module: MavenContainerModule, log: LogEntry) {
// Copy the default Dockerfile to the build directory, if the module doesn't provide one
// Note: Doing this here so that the build status check works as expected.
if (!(await containerHelpers.hasDockerfile(module))) {
if (module.spec.dockerfile === defaultDockerfileName || !(await containerHelpers.hasDockerfile(module))) {
log.debug(`Using default Dockerfile`)
await copy(defaultDockerfilePath, resolve(module.buildPath, "Dockerfile"))
await copy(defaultDockerfilePath, resolve(module.buildPath, defaultDockerfileName))
}
}

Expand Down
134 changes: 82 additions & 52 deletions garden-service/src/plugins/maven-container/openjdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,102 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { Library, LibraryPlatformSpec } from "../../util/ext-tools"
import { Library } from "../../util/ext-tools"

const jdk8Version = "jdk8u202-b08"
const jdk11Version = "jdk-11.0.2+9"
const jdk13Version = "jdk-13+33"

function jdk8Spec(filename: string, sha256: string, targetPath: string[]): LibraryPlatformSpec {
return {
url: `https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/${jdk8Version}/${filename}`,
sha256,
extract: {
format: "tar",
targetPath,
},
}
}

function jdk11Spec(filename: string, sha256: string, targetPath: string[]): LibraryPlatformSpec {
return {
url: `https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.2%2B9/${filename}`,
sha256,
extract: {
format: "tar",
targetPath,
},
}
}
const jdk8Base = `https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/${jdk8Version}/`
const jdk11Base = "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.2%2B9/"
const jdk13Base = "https://github.com/AdoptOpenJDK/openjdk13-binaries/releases/download/jdk-13%2B33/"

export const openJdks: { [version: number]: Library } = {
8: new Library({
name: "openjdk-8",
specs: {
darwin: jdk8Spec(
"OpenJDK8U-jdk_x64_mac_hotspot_8u202b08.tar.gz",
"059f7c18faa6722aa636bbd79bcdff3aee6a6da5b34940b072ea6e3af85bbe1d",
[jdk8Version, "Contents", "Home"],
),
linux: jdk8Spec(
"OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz",
"f5a1c9836beb3ca933ec3b1d39568ecbb68bd7e7ca6a9989a21ff16a74d910ab",
[jdk8Version],
),
win32: jdk8Spec(
"OpenJDK8U-jdk_x64_windows_hotspot_8u202b08.zip",
"2637dab3bc81274e19991eebc27684276b482dd71d0f84fedf703d4fba3576e5",
[jdk8Version],
),
darwin: {
url: jdk8Base + "OpenJDK8U-jdk_x64_mac_hotspot_8u202b08.tar.gz",
sha256: "059f7c18faa6722aa636bbd79bcdff3aee6a6da5b34940b072ea6e3af85bbe1d",
extract: {
format: "tar",
targetPath: [jdk8Version, "Contents", "Home"],
},
},
linux: {
url: jdk8Base + "OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz",
sha256: "f5a1c9836beb3ca933ec3b1d39568ecbb68bd7e7ca6a9989a21ff16a74d910ab",
extract: {
format: "tar",
targetPath: [jdk8Version],
},
},
win32: {
url: jdk8Base + "OpenJDK8U-jdk_x64_windows_hotspot_8u202b08.zip",
sha256: "2637dab3bc81274e19991eebc27684276b482dd71d0f84fedf703d4fba3576e5",
extract: {
format: "zip",
targetPath: [jdk8Version],
},
},
},
}),
11: new Library({
name: "openjdk-11",
specs: {
darwin: jdk11Spec(
"OpenJDK11U-jdk_x64_mac_hotspot_11.0.2_9.tar.gz",
"fffd4ed283e5cd443760a8ec8af215c8ca4d33ec5050c24c1277ba64b5b5e81a",
[jdk11Version, "Contents", "Home"],
),
linux: jdk11Spec(
"OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz",
"d02089d834f7702ac1a9776d8d0d13ee174d0656cf036c6b68b9ffb71a6f610e",
[jdk11Version],
),
win32: jdk11Spec(
"OpenJDK11U-jdk_x64_windows_hotspot_11.0.2_9.zip",
"bde1648333abaf49c7175c9ee8ba9115a55fc160838ff5091f07d10c4bb50b3a",
[jdk11Version],
),
darwin: {
url: jdk11Base + "OpenJDK11U-jdk_x64_mac_hotspot_11.0.2_9.tar.gz",
sha256: "fffd4ed283e5cd443760a8ec8af215c8ca4d33ec5050c24c1277ba64b5b5e81a",
extract: {
format: "tar",
targetPath: [jdk11Version, "Contents", "Home"],
},
},
linux: {
url: jdk11Base + "OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz",
sha256: "d02089d834f7702ac1a9776d8d0d13ee174d0656cf036c6b68b9ffb71a6f610e",
extract: {
format: "tar",
targetPath: [jdk11Version],
},
},
win32: {
url: jdk11Base + "OpenJDK11U-jdk_x64_windows_hotspot_11.0.2_9.zip",
sha256: "bde1648333abaf49c7175c9ee8ba9115a55fc160838ff5091f07d10c4bb50b3a",
extract: {
format: "zip",
targetPath: [jdk11Version],
},
},
},
}),
13: new Library({
name: "openjdk-13",
specs: {
darwin: {
url: jdk13Base + "OpenJDK13U-jdk_x64_mac_hotspot_13_33.tar.gz",
sha256: "f948be96daba250b6695e22cb51372d2ba3060e4d778dd09c89548889783099f",
extract: {
format: "tar",
targetPath: [jdk13Version, "Contents", "Home"],
},
},
linux: {
url: jdk13Base + "OpenJDK13U-jdk_x64_linux_hotspot_13_33.tar.gz",
sha256: "e562caeffa89c834a69a44242d802eae3523875e427f07c05b1902c152638368",
extract: {
format: "tar",
targetPath: [jdk13Version],
},
},
win32: {
url: jdk13Base + "OpenJDK13U-jdk_x64_windows_hotspot_13_33.zip",
sha256: "65d71a954167d538c7a260e64d9868ceffe60edd1108817a9c44fddf60d13569",
extract: {
format: "zip",
targetPath: [jdk13Version],
},
},
},
}),
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
ARG JDK_VERSION=8
FROM openjdk:${JDK_VERSION}-jdk-alpine

RUN addgroup -g 2000 app && \
adduser -D -u 2000 -G app -h /var/lib/app -s /bin/sh app
USER 2000:2000
ARG IMAGE_VERSION=8-jre
FROM openjdk:${IMAGE_VERSION}

EXPOSE 8080

Expand Down
4 changes: 2 additions & 2 deletions garden-service/test/unit/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ describe("Garden", () => {
})

it("should throw if project root is not in a git repo root", async () => {
const tmpDir = await tmp.dir({ unsafeCleanup: true })
const dir = await tmp.dir({ unsafeCleanup: true })

try {
const tmpPath = await realpath(tmpDir.path)
const tmpPath = await realpath(dir.path)
await writeFile(join(tmpPath, "garden.yml"), dedent`
kind: Project
name: foo
Expand Down

0 comments on commit 8cddab8

Please sign in to comment.