Skip to content

Commit

Permalink
Add "jlink-image" support. (#1398)
Browse files Browse the repository at this point in the history
* Add "jlink-image" support.

* Fix copyright.
  • Loading branch information
batsatt committed Feb 19, 2020
1 parent 0a2485d commit c63b7b9
Show file tree
Hide file tree
Showing 9 changed files with 370 additions and 34 deletions.
22 changes: 21 additions & 1 deletion applications/mp/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2019, 2020 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -84,6 +84,7 @@
<artifactId>helidon-maven-plugin</artifactId>
<executions>
<execution>
<id>native-image</id>
<goals>
<goal>native-image</goal>
</goals>
Expand All @@ -99,5 +100,24 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>jlink-image</id>
<build>
<plugins>
<plugin>
<groupId>io.helidon.build-tools</groupId>
<artifactId>helidon-maven-plugin</artifactId>
<executions>
<execution>
<id>jlink-image</id>
<goals>
<goal>jlink-image</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
22 changes: 21 additions & 1 deletion applications/se/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2019, 2020 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,6 +40,7 @@
<artifactId>helidon-maven-plugin</artifactId>
<executions>
<execution>
<id>native-image</id>
<goals>
<goal>native-image</goal>
</goals>
Expand All @@ -55,5 +56,24 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>jlink-image</id>
<build>
<plugins>
<plugin>
<groupId>io.helidon.build-tools</groupId>
<artifactId>helidon-maven-plugin</artifactId>
<executions>
<execution>
<id>jlink-image</id>
<goals>
<goal>jlink-image</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
40 changes: 40 additions & 0 deletions examples/quickstarts/helidon-quickstart-mp/Dockerfile.jlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright (c) 2020 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# 1st stage, build the app
FROM maven:3.6.3-jdk-11-slim as build

WORKDIR /helidon

# Create a first layer to cache the "Maven World" in the local repository.
# Incremental docker builds will always resume after that, unless you update
# the pom
ADD pom.xml .
RUN mvn package -DskipTests

# Do the Maven build to create the custom Java Runtime Image
# Incremental docker builds will resume here when you change sources
ADD src src
RUN mvn -Ddocker.build=true package -Pjlink-image -DskipTests
RUN echo "done!"

# 2nd stage, build the final image with the JRI built in the 1st stage

FROM debian:stretch-slim
WORKDIR /helidon
COPY --from=build /helidon/target/helidon-quickstart-mp ./
ENTRYPOINT ["/bin/bash", "/helidon/bin/start"]
EXPOSE 8080
49 changes: 49 additions & 0 deletions examples/quickstarts/helidon-quickstart-mp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,52 @@ kubectl get pods # Verify connectivity to cluster
kubectl create -f app.yaml # Deploy application
kubectl get service helidon-quickstart-mp # Verify deployed service
```

## Build a Java Runtime Image using jlink

You can build a custom Java Runtime Image (JRI) containing the application jars and the JDK modules
on which they depend. This image also:

* Enables Class Data Sharing by default to reduce startup time.
* Contains a customized `start` script to simplify CDS usage and support debug and test modes.

You can build a custom JRI in two different ways:
* Local
* Using Docker


### Local build

```
# build the JRI
mvn package -Pjlink-image
```

See https://github.com/oracle/helidon-build-tools/tree/master/helidon-maven-plugin#goal-jlink-image
for more information.

Start the application:

```
./target/helidon-quickstart-se/bin/start
```

### Multi-stage Docker build

Build the "jlink" Docker Image

```
docker build -t helidon-quickstart-se-jlink -f Dockerfile.jlink .
```

Start the application:

```
docker run --rm -p 8080:8080 helidon-quickstart-se-jlink:latest
```

See the start script help:

```
docker run --rm helidon-quickstart-se-jlink:latest --help
```
40 changes: 40 additions & 0 deletions examples/quickstarts/helidon-quickstart-se/Dockerfile.jlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright (c) 2020 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# 1st stage, build the app
FROM maven:3.6.3-jdk-11-slim as build

WORKDIR /helidon

# Create a first layer to cache the "Maven World" in the local repository.
# Incremental docker builds will always resume after that, unless you update
# the pom
ADD pom.xml .
RUN mvn package -DskipTests

# Do the Maven build to create the custom Java Runtime Image
# Incremental docker builds will resume here when you change sources
ADD src src
RUN mvn -Ddocker.build=true package -Pjlink-image -DskipTests
RUN echo "done!"

# 2nd stage, build the final image with the JRI built in the 1st stage

FROM debian:stretch-slim
WORKDIR /helidon
COPY --from=build /helidon/target/helidon-quickstart-se ./
ENTRYPOINT ["/bin/bash", "/helidon/bin/start"]
EXPOSE 8080
53 changes: 51 additions & 2 deletions examples/quickstarts/helidon-quickstart-se/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ kubectl create -f app.yaml # Deply application
kubectl get service helidon-quickstart-se # Get service info
```

## Native image with GraalVM
## Build a native image with GraalVM

GraalVM allows you to compile your programs ahead-of-time into a native
executable. See https://www.graalvm.org/docs/reference-manual/aot-compilation/
Expand All @@ -92,7 +92,7 @@ mvn package -Pnative-image
You can also put the Graal VM `bin` directory in your PATH, or pass
`-DgraalVMHome=/path` to the Maven command.

See https://github.com/oracle/helidon-build-tools/tree/master/helidon-maven-plugin
See https://github.com/oracle/helidon-build-tools/tree/master/helidon-maven-plugin#goal-native-image
for more information.

Start the application:
Expand All @@ -114,3 +114,52 @@ Start the application:
```
docker run --rm -p 8080:8080 helidon-quickstart-se-native:latest
```

## Build a Java Runtime Image using jlink

You can build a custom Java Runtime Image (JRI) containing the application jars and the JDK modules
on which they depend. This image also:

* Enables Class Data Sharing by default to reduce startup time.
* Contains a customized `start` script to simplify CDS usage and support debug and test modes.

You can build a custom JRI in two different ways:
* Local
* Using Docker


### Local build

```
# build the JRI
mvn package -Pjlink-image
```

See https://github.com/oracle/helidon-build-tools/tree/master/helidon-maven-plugin#goal-jlink-image
for more information.

Start the application:

```
./target/helidon-quickstart-se/bin/start
```

### Multi-stage Docker build

Build the "jlink" Docker Image

```
docker build -t helidon-quickstart-se-jlink -f Dockerfile.jlink .
```

Start the application:

```
docker run --rm -p 8080:8080 helidon-quickstart-se-jlink:latest
```

See the start script help:

```
docker run --rm helidon-quickstart-se-jlink:latest --help
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright (c) 2020 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# 1st stage, build the app
FROM maven:3.6.3-jdk-11-slim as build

WORKDIR /helidon

# Create a first layer to cache the "Maven World" in the local repository.
# Incremental docker builds will always resume after that, unless you update
# the pom
ADD pom.xml .
RUN mvn package -DskipTests

# Do the Maven build to create the custom Java Runtime Image
# Incremental docker builds will resume here when you change sources
ADD src src
RUN mvn -Ddocker.build=true package -Pjlink-image -DskipTests
RUN echo "done!"

# 2nd stage, build the final image with the JRI built in the 1st stage

FROM debian:stretch-slim
WORKDIR /helidon
COPY --from=build /helidon/target/helidon-quickstart-mp ./
ENTRYPOINT ["/bin/bash", "/helidon/bin/start"]
EXPOSE 8080
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright (c) 2020 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# 1st stage, build the app
FROM maven:3.6.3-jdk-11-slim as build

WORKDIR /helidon

# Create a first layer to cache the "Maven World" in the local repository.
# Incremental docker builds will always resume after that, unless you update
# the pom
ADD pom.xml .
RUN mvn package -DskipTests

# Do the Maven build to create the custom Java Runtime Image
# Incremental docker builds will resume here when you change sources
ADD src src
RUN mvn -Ddocker.build=true package -Pjlink-image -DskipTests
RUN echo "done!"

# 2nd stage, build the final image with the JRI built in the 1st stage

FROM debian:stretch-slim
WORKDIR /helidon
COPY --from=build /helidon/target/helidon-quickstart-se ./
ENTRYPOINT ["/bin/bash", "/helidon/bin/start"]
EXPOSE 8080
Loading

0 comments on commit c63b7b9

Please sign in to comment.