Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting OracleLinux version for native base image #723

Merged
merged 4 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/graalvm/native-image:ol7-java17-22.3.0 AS builder
FROM ghcr.io/graalvm/native-image:ol8-java17-22.3.0 AS builder
WORKDIR /home/app

COPY classes /home/app/classes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM ghcr.io/graalvm/native-image:ol7-java17-22.3.0 AS builder
WORKDIR /home/app

COPY classes /home/app/classes
COPY dependency/* /home/app/libs/
COPY *.args /home/app/graalvm-native-image.args
ENV USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=false
RUN native-image @/home/app/graalvm-native-image.args -H:Class=io.micronaut.build.examples.Application -H:Name=application -cp "/home/app/libs/*:/home/app/classes/"

FROM frolvlad/alpine-glibc:alpine-3.12
RUN apk update && apk add libstdc++
COPY --from=builder /home/app/application /app/application

EXPOSE 8080
ENTRYPOINT ["/app/application"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = -ntp mn:dockerfile -Dpackaging=docker-native -Dmicronaut.native-image.ol.version=ol7
invoker.os.family = !windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.micronaut.build.examples</groupId>
<artifactId>dockerfile-docker-native-netty-custom-ol</artifactId>
<version>0.1</version>
<packaging>${packaging}</packaging>

<parent>
<groupId>io.micronaut.platform</groupId>
<artifactId>micronaut-parent</artifactId>
<version>@it.micronaut.version@</version>
</parent>

<properties>
<micronaut.version>@it.micronaut.version@</micronaut.version>
<micronaut-maven-plugin.version>@project.version@</micronaut-maven-plugin.version>
<exec.mainClass>io.micronaut.build.examples.Application</exec.mainClass>
<maven.native.plugin.version>@native-maven-plugin.version@</maven.native.plugin.version>
<packaging>jar</packaging>
<micronaut.runtime>netty</micronaut.runtime>
<graal.oracle.linux.version>ol7</graal.oracle.linux.version>
</properties>

<dependencies>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut.validation</groupId>
<artifactId>micronaut-validation</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-http-server-netty</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-http-client</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-runtime</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.micronaut.test</groupId>
<artifactId>micronaut-test-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.micronaut.maven</groupId>
<artifactId>micronaut-maven-plugin</artifactId>
<version>${micronaut-maven-plugin.version}</version>
<configuration>
<nativeImageBuildArgs>-Ob</nativeImageBuildArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- Uncomment to enable incremental compilation -->
<!-- <useIncrementalCompilation>false</useIncrementalCompilation> -->
<annotationProcessorPaths combine.children="append">
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-graal</artifactId>
<version>${micronaut.core.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-Amicronaut.processing.group=io.micronaut.build.examples</arg>
<arg>-Amicronaut.processing.module=${project.artifactId}</arg>
</compilerArgs>
</configuration>
</plugin>

<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<configuration>
<to>
<image>alvarosanchez/demo:${project.version}</image>
</to>
</configuration>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.micronaut.build.examples;

import io.micronaut.runtime.Micronaut;
import io.micronaut.build.examples.greeter.Greeter;

public class Application {

public static void main(String[] args) {
Greeter greeter = new Greeter();
System.out.println(greeter.greet("world!"));
Micronaut.run(Application.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.micronaut.build.examples.greeter;

public class Greeter {

public String greet(String name) {
return "HELLO " + name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
micronaut:
application:
name: dockerfile-docker-native-netty-custom-ol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<withJansi>false</withJansi>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.micronaut.build.examples;

import io.micronaut.runtime.EmbeddedApplication;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import javax.inject.Inject;

@MicronautTest
public class ApplicationTest {

@Inject
EmbeddedApplication application;

@Test
void testItWorks() {
Assertions.assertTrue(application.isRunning());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
File dockerfile = new File("$basedir/target", "Dockerfile")
File expectedDockerfile = new File(basedir, "Dockerfile")

assert dockerfile.text == expectedDockerfile.text
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/graalvm/native-image:ol7-java17-22.3.0 AS builder
FROM ghcr.io/graalvm/native-image:ol8-java17-22.3.0 AS builder
WORKDIR /home/app

COPY classes /home/app/classes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/graalvm/native-image:ol7-java17-22.3.0 AS builder
FROM ghcr.io/graalvm/native-image:ol8-java17-22.3.0 AS builder
WORKDIR /home/app

COPY classes /home/app/classes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/graalvm/graalvm-ce:ol7-java17-22.3.0 AS builder
FROM ghcr.io/graalvm/graalvm-ce:ol8-java17-22.3.0 AS builder
RUN gu install native-image

WORKDIR /
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/graalvm/graalvm-ce:ol7-java17-22.3.0 AS builder
FROM ghcr.io/graalvm/graalvm-ce:ol8-java17-22.3.0 AS builder
RUN gu install native-image
WORKDIR /home/app

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public abstract class AbstractDockerMojo extends AbstractMicronautMojo {
public static final String ARM_ARCH = "aarch64";
public static final String X86_64_ARCH = "amd64";
public static final String JAVA_17 = "java17";
public static final String DEFAULT_ORACLE_LINUX_VERSION = "ol8";

protected final MavenProject mavenProject;
protected final JibConfigurationService jibConfigurationService;
Expand Down Expand Up @@ -103,6 +104,12 @@ public abstract class AbstractDockerMojo extends AbstractMicronautMojo {
@Parameter(property = "micronaut.native-image.base-image-run", defaultValue = DEFAULT_BASE_IMAGE_GRAALVM_RUN)
protected String baseImageRun;

/**
* The version of Oracle Linux to use as a native-compile base when building a native image inside a Docker container.
*/
@Parameter(property = "micronaut.native-image.ol.version", defaultValue = DEFAULT_ORACLE_LINUX_VERSION)
protected String oracleLinuxVersion;

/**
* Networking mode for the RUN instructions during build.
*
Expand Down Expand Up @@ -161,9 +168,9 @@ protected String graalVmArch() {
protected String getFrom() {
if (Boolean.TRUE.equals(staticNativeImage)) {
// For building a static native image we need a base image with tools (cc, make,...) already installed
return getFromImage().orElse("ghcr.io/graalvm/graalvm-ce:ol7-" + graalVmJvmVersion() + "-" + graalVmVersion());
return getFromImage().orElse("ghcr.io/graalvm/graalvm-ce:" + oracleLinuxVersion + "-" + graalVmJvmVersion() + "-" + graalVmVersion());
} else {
return getFromImage().orElse("ghcr.io/graalvm/native-image:ol7-" + graalVmJvmVersion() + "-" + graalVmVersion());
return getFromImage().orElse("ghcr.io/graalvm/native-image:" + oracleLinuxVersion + "-" + graalVmJvmVersion() + "-" + graalVmVersion());
}
}

Expand Down