项目作者: vegardit

项目描述 :
Docker image to build native Linux binaries from Java Maven projects using GraalVM native-image feature.
高级语言: Shell
项目地址: git://github.com/vegardit/docker-graalvm-maven.git
创建时间: 2020-12-02T14:51:51Z
项目社区:https://github.com/vegardit/docker-graalvm-maven

开源协议:Apache License 2.0

下载


docker-graalvm-maven

Build Status
License
Docker Pulls
Docker Stars
Contributor Covenant

  1. What is it?
  2. Usage
  3. License

What is it?" class="reference-link">What is it?

Opinionated docker image based on the Debian docker image debian:stable-slim to
build native Linux binaries from Java Maven projects using GraalVM CE native-image feature.

It is automatically built weekly to include the latest OS security fixes.

The image comes pre-installed with latest releases of:

Further we add the user user with uid 1000 and gid 1000 as non-privileged user in order to run without root privileges.
Note, that the user is not set to 1000 within the docker image. Specify the uid to be 1000 with your docker run command.

Docker image tagging scheme" class="reference-link">Docker image tagging scheme

Tag Description
  1. :latest-java11
    :latest-java17
    :latest-java21
    :latest-java24
latest available GraalVM CE releases for the given JDK
  1. :dev-java25
latest available GraalVM CE development builds for the given JDK
  1. :XX.Y.Z
the given GraalVM CE releases (e.g. 17.0.8 for JDK 17 and 21.0.0 for JDK 21) following GraaLVM’s new version naming scheme.
  1. :XX.Y.Z-java11
    :XX.Y.Z-java17
the given GraalVM CE releases (e.g. 22.3.2-java11) following GraaLVM’s old version naming scheme

See all available tags at https://hub.docker.com/r/vegardit/graalvm-maven/tags

Usage

Building a local Maven project

To build a Maven project located on your local workstation with via this docker image you can do:

  1. On Linux:

    1. $ cd ~/myproject
    2. $ docker run --rm -it \
    3. -v $PWD:/mnt/myproject:rw \
    4. -w /mnt/myproject \
    5. vegardit/graalvm-maven:latest-java17 \
    6. mvn clean package
  2. On Windows:

    1. C:> cd C:\Users\MyUser\myproject
    2. C:\Users\MyUser\myproject> docker run --rm -it ^
    3. -v /c/Users/MyUser/myproject:/mnt/myproject:rw ^
    4. -w /mnt/myproject ^
    5. vegardit/graalvm-maven:latest-java17 ^
    6. mvn clean package

Also checkout the example project which provides convenient batch/bash script wrappers and outlines how to do compile Java projects to native Linux binaries.

Using custom Maven settings.xml

You can use a custom Maven settings.xml by mounting it to /root/.m2/settings.xml

  1. $ cd ~/myproject
  2. $ docker run --rm -it \
  3. -v /path/to/my/settings.xml:/root/.m2/settings.xml:ro \
  4. -v $PWD:/mnt/myproject:rw \
  5. -w /mnt/myproject \
  6. vegardit/graalvm-maven:latest-java17 \
  7. mvn clean package

Running docker commands inside the container

This image has the docker command line client installed, which allows you to run other docker containers as part of your build toolchain using a
docker-out-of-docker (DooD) approach
by mounting the /var/run/docker.sock into the container.

  1. $ cd ~/myproject
  2. $ docker run --rm -it \
  3. -v /var/run/docker.sock:/var/run/docker.sock:rw \
  4. -v $PWD:/mnt/myproject:rw \
  5. vegardit/graalvm-maven:latest-java17 \
  6. docker run --rm hello-world

Caching local Maven repository between runs

You can a local folder to /root/.m2/repository to cache the downloaded artifacts between Maven runs

  1. $ cd ~/myproject
  2. $ docker run --rm -it \
  3. -v /path/to/my/local/repository:/root/.m2/repository:rw \
  4. -v $PWD:/mnt/myproject:rw \
  5. -w /mnt/myproject \
  6. vegardit/graalvm-maven:latest-java17 \
  7. mvn clean package

License" class="reference-link">License

All files in this repository are released under the Apache License 2.0.

Individual files contain the following tag instead of the full license text:

  1. SPDX-License-Identifier: Apache-2.0

This enables machine processing of license information based on the SPDX License Identifiers that are available here: https://spdx.org/licenses/.