diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java index 3f3c7064ea5d5..17a6f11d6ff63 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java @@ -242,6 +242,7 @@ protected Integer export(Path exportBaseDir, ExportBaseCommand cmd) throws Excep cmd.quarkusGroupId = this.quarkusGroupId; cmd.quarkusArtifactId = this.quarkusArtifactId; cmd.quarkusVersion = this.quarkusVersion; + cmd.quarkusPackageType = this.quarkusPackageType; cmd.springBootVersion = this.springBootVersion; cmd.mavenWrapper = this.mavenWrapper; cmd.quiet = this.quiet; diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java index f4f8f45f7338a..e62ad974f6fbd 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java @@ -199,6 +199,11 @@ public abstract class ExportBaseCommand extends CamelCommand { defaultValue = RuntimeType.QUARKUS_VERSION) protected String quarkusVersion = RuntimeType.QUARKUS_VERSION; + @CommandLine.Option(names = { "--quarkus-package-type" }, + description = "Quarkus package type (uber-jar or fast-jar)", + defaultValue = "uber-jar") + protected String quarkusPackageType = "uber-jar"; + @CommandLine.Option(names = { "--maven-wrapper" }, defaultValue = "true", description = "Include Maven Wrapper files in exported project") protected boolean mavenWrapper = true; diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportQuarkus.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportQuarkus.java index bd3b4366ec512..56ae6c1513a00 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportQuarkus.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportQuarkus.java @@ -129,7 +129,12 @@ public Integer export() throws Exception { }); // copy docker files copyDockerFiles(BUILD_DIR); - String appJar = "target" + File.separator + "quarkus-app" + File.separator + "quarkus-run.jar"; + String appJar; + if ("fast-jar".equals(quarkusPackageType)) { + appJar = "target" + File.separator + "quarkus-app" + File.separator + "quarkus-run.jar"; + } else { + appJar = "target" + File.separator + ids[1] + "-" + ids[2] + ".jar"; + } copyReadme(BUILD_DIR, appJar); // gather dependencies Set deps = resolveDependencies(settings, profile); @@ -276,12 +281,27 @@ protected String applicationPropertyLine(String key, String value) { @Override protected void copyDockerFiles(String buildDir) throws Exception { - super.copyDockerFiles(buildDir); + if ("uber-jar".equals(quarkusPackageType)) { + // For uber-jar, the generic Dockerfile works as-is + super.copyDockerFiles(buildDir); + } else { + // For fast-jar, use a Quarkus-specific JVM Dockerfile + Path docker = Path.of(buildDir).resolve("src/main/docker"); + Files.createDirectories(docker); + InputStream is + = ExportQuarkus.class.getClassLoader().getResourceAsStream("quarkus-docker/Dockerfile.jvm"); + if (is != null) { + PathUtils.copyFromStream(is, docker.resolve("Dockerfile"), true); + } + } + // Quarkus-specific Dockerfiles for native builds Path docker = Path.of(buildDir).resolve("src/main/docker"); - Files.createDirectories(docker); - // copy files - InputStream is = ExportQuarkus.class.getClassLoader().getResourceAsStream("quarkus-docker/Dockerfile.native"); - PathUtils.copyFromStream(is, docker.resolve("Dockerfile.native"), true); + for (String dockerfile : List.of("Dockerfile.native", "Dockerfile.native-micro")) { + InputStream is = ExportQuarkus.class.getClassLoader().getResourceAsStream("quarkus-docker/" + dockerfile); + if (is != null) { + PathUtils.copyFromStream(is, docker.resolve(dockerfile), true); + } + } } @Override @@ -325,6 +345,7 @@ private void createMavenPom(Path settings, Path pom, Set deps) throws Ex context = context.replaceAll("\\{\\{ \\.QuarkusGroupId }}", quarkusGroupId); context = context.replaceAll("\\{\\{ \\.QuarkusArtifactId }}", quarkusArtifactId); context = context.replaceAll("\\{\\{ \\.QuarkusVersion }}", quarkusVersion); + context = context.replaceAll("\\{\\{ \\.QuarkusPackageType }}", quarkusPackageType); context = context.replaceAll("\\{\\{ \\.QuarkusManagementPort }}", mp); context = context.replaceAll("\\{\\{ \\.JavaVersion }}", javaVersion); context = context.replaceAll("\\{\\{ \\.CamelVersion }}", camelVersion); diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/quarkus-docker/Dockerfile.jvm b/dsl/camel-jbang/camel-jbang-core/src/main/resources/quarkus-docker/Dockerfile.jvm new file mode 100644 index 0000000000000..e3204cf0719d0 --- /dev/null +++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/quarkus-docker/Dockerfile.jvm @@ -0,0 +1,51 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# using the fast-jar packaging. +# +# Before building the container image run: +# +# ./mvnw clean package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile -t quarkus/camel-app . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/camel-app +# +### +FROM registry.access.redhat.com/ubi9/openjdk-21:1.23 + +ENV LANGUAGE='en_US:en' + +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/ +COPY --chown=185 target/quarkus-app/*.jar /deployments/ +COPY --chown=185 target/quarkus-app/app/ /deployments/app/ +COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/ + +# Uncomment to expose any given port +# EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/quarkus-docker/Dockerfile.native b/dsl/camel-jbang/camel-jbang-core/src/main/resources/quarkus-docker/Dockerfile.native index b4d920348926f..8771b0fb21529 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/resources/quarkus-docker/Dockerfile.native +++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/quarkus-docker/Dockerfile.native @@ -30,10 +30,10 @@ # # docker run -i quarkus/code-with-quarkus # -# The ` registry.access.redhat.com/ubi9/ubi-minimal:9.5` base image is based on UBI 9. +# The ` registry.access.redhat.com/ubi9/ubi-minimal:9.7` base image is based on UBI 9. # To use UBI 8, switch to `quay.io/ubi8/ubi-minimal:8.10`. ### -FROM registry.access.redhat.com/ubi9/ubi-minimal:9.6 +FROM registry.access.redhat.com/ubi9/ubi-minimal:9.7 WORKDIR /work/ RUN chown 1001 /work \ && chmod "g+rwX" /work \ diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/quarkus-docker/Dockerfile.native-micro b/dsl/camel-jbang/camel-jbang-core/src/main/resources/quarkus-docker/Dockerfile.native-micro new file mode 100644 index 0000000000000..12568be5f61aa --- /dev/null +++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/quarkus-docker/Dockerfile.native-micro @@ -0,0 +1,52 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# It uses a micro base image, tuned for Quarkus native executables. +# It reduces the size of the resulting container image. +# Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/code-with-quarkus . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus +# +# The `quay.io/quarkus/ubi9-quarkus-micro-image:2.0` base image is based on UBI 9. +# To use UBI 8, switch to `quay.io/quarkus/quarkus-micro-image:2.0`. +### +FROM quay.io/quarkus/ubi9-quarkus-micro-image:2.0 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root --chmod=0755 target/*-runner /work/application + +# Uncomment to expose any given port +# EXPOSE 8080 +USER 1001 + +# Use this if you're exposing some port +# ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] +ENTRYPOINT ["./application"] diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/quarkus-pom.tmpl b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/quarkus-pom.tmpl index 09f7edd783468..bdd439a8c35fb 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/quarkus-pom.tmpl +++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/quarkus-pom.tmpl @@ -18,6 +18,7 @@ {{ .QuarkusArtifactId }} {{ .QuarkusVersion }} {{ .BuildProperties }} + {{ .QuarkusPackageType }} true 3.5.5