Skip to content

Record JRE version details in Java image metadata - #291

Merged
briandealwis merged 10 commits into
masterfrom
i276-jre
Feb 14, 2019
Merged

briandealwis merged 10 commits into
masterfrom
i276-jre

Conversation

@briandealwis

@briandealwis briandealwis commented Feb 6, 2019 •

Copy link
Copy Markdown
Member

#276 requests that the java images provide information as to the JRE version. This PR follows on from #290 and adds the following metadata to the distroless/java images:

  • it sets a JAVA_VERSION environment variable to the JRE version, currently 8u181 for the Java 8 image and 11.0.1 for the Java 11 image
  • it sets three labels:
    • jdk.vendor is hard-coded to openjdk since we explicitly select the openjdk-*-jre-headless packages
    • jdk.version is the same release number reported in JAVA_VERSION
    • jdk.source records soe provenance information listing the Debian package name and version: currently openjdk-8-jre-headless 8u181-b13-2~deb9u1 and openjdk-11-jre-headless 11.0.1+13-2~bpo9+1

Update: I'm not convinced of these label keys, and since environment variables are as easy to access as labels, the JAVA_VERSION will do for now.

It adds some metadata tests too though the jdk.source tests are commented out as they require container-structure-test v1.7.0 (bazelbuild/rules_docker#685).

I'm not particularly enamoured by the label names. My priority is the JAVA_VERSION environment variable.

  - a JAVA_VERSION environment variable in keeping with the
    OpenJDK Official Docker Images
  - labels for the JDK version, vendor, and source (debian package
    name and version)
@chanseokoh

Copy link
Copy Markdown
Member

There are formatting errors. You need to use the same buildifier version being used in Travis: wget https://github.com/bazelbuild/buildtools/releases/download/0.11.1/buildifier

Once #290 is merged, I expect the updated dpkg_parser.par will become available soon. You can then update the URL in package_manager.bzl to pull in the new binary, I think.

@briandealwis

Copy link
Copy Markdown
Member Author

Ok will do — thanks for the pointer.

@loosebazooka

Copy link
Copy Markdown
Member

Is the problem with the label keys that we're not choosing standard ones?

@chanseokoh chanseokoh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically LGTM.

Comment thread java/jre_ver.bzl Outdated
openjdk-11-jre*: 11.0.1+13-2~bpo9+1
"""
if version.startswith("8u"): return version.split("-",2)[0]
if version.startswith("11."): return version.split("+",2)[0]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I believe version.split("+")[0] (no optional second parameter) will work and look simpler. I don't think we need this kind of optimization.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Perhaps the consumer can handle this on their own.

Comment thread java/jre_ver.bzl Outdated
"""
if version.startswith("8u"): return version.split("-",2)[0]
if version.startswith("11."): return version.split("+",2)[0]
return "unknown: " + version

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... would it be difficult to not set JAVA_VERSION if unknown?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually like to trigger a build error. Thinking to the day that we pull in Java 15 and end up with a broken version string.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that should use the fail() function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I like that idea.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fail() does the trick:

ERROR: /Users/bsd/Manumitting/Projects/GooglePluginEclipse/repo-distroless/java/BUILD:13:1: Traceback (most recent call last):
	File "/Users/bsd/Manumitting/Projects/GooglePluginEclipse/repo-distroless/java/BUILD", line 13
		container_image(name = rule_name, base = "//cc" if...", <5 more arguments>)
	File "/Users/bsd/Manumitting/Projects/GooglePluginEclipse/repo-distroless/java/BUILD", line 27, in container_image
		jre_ver(versions[jre_deb])
	File "/Users/bsd/Manumitting/Projects/GooglePluginEclipse/repo-distroless/java/jre_ver.bzl", line 10, in jre_ver
		fail(("unrecognized openjdk package v...))
unrecognized openjdk package version: 15.0.2
ERROR: error loading package 'java': Package 'java' contains errors
INFO: Elapsed time: 0.093s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded)

@briandealwis

Copy link
Copy Markdown
Member Author

@loosebazooka: Is the problem with the label keys that we're not choosing standard ones?

Yeah. Both Docker and OCI recommend namespacing labels/annotations using reverse-DNS prefixes.

@chanseokoh chanseokoh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. We can add labels in a later PR.

Comment thread package_manager/dpkg_parser.py Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants