Skip to content

Commit

Permalink
Optimize mandrel/graalvm modules
Browse files Browse the repository at this point in the history
Avoid persisting temporary tar.gz files in builder images by using bind type mount
  • Loading branch information
MrLuje committed Jun 24, 2023
1 parent 2f9958c commit e131f58
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
19 changes: 9 additions & 10 deletions jdock/src/main/java/io/quarkus/images/modules/GraalVMModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public class GraalVMModule extends AbstractModule {
private final boolean isLegacyGraalVm;

private static final String TEMPLATE = """
--mount=type=bind,source=%s,target=/tmp/%s \\
tar xzf %s -C /opt \\
&& mv /opt/graalvm-ce-*-%s* /opt/graalvm \\
&& %s/bin/gu --auto-yes install native-image \\
&& rm -Rf %s""";
&& %s/bin/gu --auto-yes install native-image""";

private static final String NEW_TEMPLATE = """
--mount=type=bind,source=%s,target=/tmp/%s \\
tar xzf %s -C /opt \\
&& mv /opt/graalvm-community-openjdk-%s* /opt/graalvm \\
&& rm -Rf %s""";
&& mv /opt/graalvm-community-openjdk-%s* /opt/graalvm""";
private final String graalvmVersion;

public GraalVMModule(String version, String arch, String javaVersion, String sha) {
Expand Down Expand Up @@ -71,21 +71,20 @@ public List<Command> commands(BuildContext bc) {
String script;
if (isLegacyGraalVm) {
script = TEMPLATE.formatted(
artifact.path, artifact.name, // mount bind
"/tmp/" + artifact.name, // tar
graalvmVersion,
GRAALVM_HOME, // gu
"/tmp/" + artifact.name); // rm
graalvmVersion, // mv
GRAALVM_HOME); // gu
} else {
script = NEW_TEMPLATE.formatted(
artifact.path, artifact.name, // mount bind
"/tmp/" + artifact.name, // tar
graalvmVersion,
"/tmp/" + artifact.name); // rm
graalvmVersion);
}

return List.of(
new EnvCommand("JAVA_HOME", GRAALVM_HOME, "GRAALVM_HOME", GRAALVM_HOME),
new MicrodnfCommand("fontconfig", "freetype-devel"),
new CopyCommand(artifact, "/tmp/" + artifact.name),
new RunCommand(script));
}
}
11 changes: 7 additions & 4 deletions jdock/src/main/java/io/quarkus/images/modules/MandrelModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class MandrelModule extends AbstractModule {
private final String filename;

private static final String TEMPLATE = """
--mount=type=bind,source=%s,target=/tmp/%s \\
mkdir -p %s \\
&& tar xzf %s -C %s --strip-components=1 \\
&& rm -Rf %s""";
&& tar xzf %s -C %s --strip-components=1""";

public MandrelModule(String version, String arch, String javaVersion, String sha) {
super("mandrel",
Expand All @@ -39,11 +39,14 @@ public MandrelModule(String version, String arch, String javaVersion, String sha
public List<Command> commands(BuildContext bc) {
Artifact artifact = bc.addArtifact(new Artifact(filename, url, sha));
String script = TEMPLATE.formatted(
MANDREL_HOME, "/tmp/" + artifact.name, MANDREL_HOME, "/tmp/" + artifact.name);
artifact.path, artifact.name, // mount bind
MANDREL_HOME, // mkdir
"/tmp/" + artifact.name, MANDREL_HOME, //tar
"/tmp/" + artifact.name); //rm

return List.of(
new EnvCommand("JAVA_HOME", MANDREL_HOME, "GRAALVM_HOME", MANDREL_HOME),
new MicrodnfCommand("fontconfig", "freetype-devel"),
new CopyCommand(artifact, "/tmp/" + artifact.name),
new RunCommand(script));
}
}

0 comments on commit e131f58

Please sign in to comment.