Skip to content
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
30 changes: 30 additions & 0 deletions docker/graalvm-native-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM ubuntu:18.04

ARG GRAAL_VERSION
ENV GRAAL_VERSION=${GRAAL_VERSION:-1.0.0-rc4}
ENV GRAAL_CE_URL=https://github.com/oracle/graal/releases/download/vm-${GRAAL_VERSION}/graalvm-ce-${GRAAL_VERSION}-linux-amd64.tar.gz

# Update system and install tools
RUN apt-get update && \
apt-get install -y wget tar gzip gcc libc6-dev zlib1g-dev

# Download and extract graalvm in tmp dir
RUN cd /tmp
RUN wget -q $GRAAL_CE_URL -O graalvm-ce-linux-amd64.tar.gz
RUN tar -xvzf graalvm-ce-linux-amd64.tar.gz

# Move extracted graalvm to /opt and cleanup
RUN mkdir -p /opt/graalvm
RUN mv graalvm-ce-${GRAAL_VERSION} /opt/graalvm
RUN rm graalvm-ce-linux-amd64.tar.gz

RUN apt-get clean

ENV JAVA_HOME=/opt/graalvm/graalvm-ce-${GRAAL_VERSION}
ENV PATH=$PATH:$JAVA_HOME/bin
ENV GRAALVM_HOME=/opt/graalvm/graalvm-ce-${GRAAL_VERSION}

VOLUME /project
WORKDIR /project

ENTRYPOINT ["native-image"]
11 changes: 11 additions & 0 deletions docker/graalvm-native-image/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Build

```bash
docker build -t protean/graalvm-native-image:latest .
```

# Run

```bash
docker run -it -v /path/to/protean/arc:/project --rm protean/graalvm-native-image -jar example/target/arc-example-shaded.jar
```
20 changes: 14 additions & 6 deletions maven/src/main/java/org/jboss/shamrock/maven/NativeImageMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand Down Expand Up @@ -43,15 +43,23 @@ public class NativeImageMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

String graal = System.getenv("GRAALVM_HOME");
if (graal == null) {
throw new MojoFailureException("GRAALVM_HOME was not set");
List<String> nativeImage;
String graalvmCmd = System.getenv("GRAALVM_NATIVE_IMAGE_CMD");
if (graalvmCmd != null) {
// E.g. "/usr/bin/docker run -v {{PROJECT_DIR}}:/project --rm protean/graalvm-native-image"
nativeImage = new ArrayList<>();
Collections.addAll(nativeImage, graalvmCmd.replace("{{PROJECT_DIR}}", outputDirectory.getAbsolutePath()).split(" "));
} else {
String graalvmHome = System.getenv("GRAALVM_HOME");
if (graalvmHome == null) {
throw new MojoFailureException("GRAALVM_HOME was not set");
}
nativeImage = Collections.singletonList(graalvmHome + File.separator + "bin" + File.separator + "native-image");
}
String nativeImage = graal + File.separator + "bin" + File.separator + "native-image";

try {
List<String> command = new ArrayList<>();
command.add(nativeImage);
command.addAll(nativeImage);
command.add("--no-server");
command.add("-jar");
command.add(finalName + "-runner.jar");
Expand Down