diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/buildtool/gradle-kotlin-dsl/base/build-layout.include.qute b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/buildtool/gradle-kotlin-dsl/base/build-layout.include.qute index d4003bc777c82..c479f7a41d5e6 100644 --- a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/buildtool/gradle-kotlin-dsl/base/build-layout.include.qute +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/buildtool/gradle-kotlin-dsl/base/build-layout.include.qute @@ -50,12 +50,12 @@ version = "{project.version}" {#insert java} java { - {#if java.version == "11"} + {#if java.version == "17"} + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + {#else} sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 - {#else} - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 {/if} } {/} diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/buildtool/gradle/base/build-layout.include.qute b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/buildtool/gradle/base/build-layout.include.qute index 48038997da2fc..de2062542adfb 100644 --- a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/buildtool/gradle/base/build-layout.include.qute +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/buildtool/gradle/base/build-layout.include.qute @@ -46,12 +46,12 @@ version '{project.version}' {#insert java} java { - {#if java.version == "11"} + {#if java.version == "17"} + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + {#else} sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 - {#else} - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 {/if} } {/} diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/Dockerfile-layout.include.qute b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/Dockerfile-layout.include.qute index a3cd865662437..212f75390f6f6 100644 --- a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/Dockerfile-layout.include.qute +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/Dockerfile-layout.include.qute @@ -18,31 +18,18 @@ # # Then run the container using : # -# docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/{project.artifact-id}-{type} +# docker run -i --rm -p 8080:8080 quarkus/{project.artifact-id}-{type} # ### -FROM {#insert image /} -{#insert args /} +FROM registry.access.redhat.com/ubi8/openjdk-{java.version}-runtime:1.10 + ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' -# Install java and the run-java script -# Also set up permissions for user `1001` -RUN microdnf install curl ca-certificates $\{JAVA_PACKAGE} \ - && microdnf update \ - && microdnf clean all \ - && mkdir /deployments \ - && chown 1001 /deployments \ - && chmod "g+rwX" /deployments \ - && chown 1001:root /deployments \ - && curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/$\{RUN_JAVA_VERSION}/run-java-sh-$\{RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \ - && chown 1001 /deployments/run-java.sh \ - && chmod 540 /deployments/run-java.sh \ - && echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/conf/security/java.security # Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" {#insert copy /} EXPOSE 8080 -USER 1001 +USER 185 -ENTRYPOINT [ "/deployments/run-java.sh" ] +ENTRYPOINT [ "java", "-jar", "/deployments/quarkus-run.jar" ] diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.jvm b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.jvm index 7dd930589ab34..bcd1e2e6f711a 100644 --- a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.jvm +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.jvm @@ -1,16 +1,11 @@ {#include Dockerfile-layout type='jvm'} {#quarkusbuild}{buildtool.cli} {buildtool.cmd.package}{/quarkusbuild} - {#image}{dockerfile.jvm.from} {/image} - {#args} -ARG JAVA_PACKAGE={dockerfile.jvm.java-package} -ARG RUN_JAVA_VERSION={dockerfile.jvm.run-java-version} - {/args} {#copy} # We make four distinct layers so if there are application changes the library layers can be re-used -COPY --chown=1001 {buildtool.build-dir}/quarkus-app/lib/ /deployments/lib/ -COPY --chown=1001 {buildtool.build-dir}/quarkus-app/*.jar /deployments/ -COPY --chown=1001 {buildtool.build-dir}/quarkus-app/app/ /deployments/app/ -COPY --chown=1001 {buildtool.build-dir}/quarkus-app/quarkus/ /deployments/quarkus/ +COPY --chown=185 {buildtool.build-dir}/quarkus-app/lib/ /deployments/lib/ +COPY --chown=185 {buildtool.build-dir}/quarkus-app/*.jar /deployments/ +COPY --chown=185 {buildtool.build-dir}/quarkus-app/app/ /deployments/app/ +COPY --chown=185 {buildtool.build-dir}/quarkus-app/quarkus/ /deployments/quarkus/ {/copy} {/include} diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.legacy-jar b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.legacy-jar index 4f30fe8d7fa14..a1c61bb037cc3 100644 --- a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.legacy-jar +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.legacy-jar @@ -1,12 +1,7 @@ {#include Dockerfile-layout type='legacy-jar'} {#quarkusbuild}{buildtool.cli} {buildtool.cmd.package-legacy-jar}{/quarkusbuild} - {#image}{dockerfile.legacy-jar.from} {/image} - {#args} -ARG JAVA_PACKAGE={dockerfile.legacy-jar.java-package} -ARG RUN_JAVA_VERSION={dockerfile.legacy-jar.run-java-version} - {/args} {#copy} COPY {buildtool.build-dir}/lib/* /deployments/lib/ -COPY {buildtool.build-dir}/*-runner.jar /deployments/app.jar +COPY {buildtool.build-dir}/*-runner.jar /deployments/quarkus-run.jar {/copy} {/include} diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/codestart.yml b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/codestart.yml index 3a09f50daef71..d8496556c3484 100644 --- a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/codestart.yml +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/codestart.yml @@ -4,14 +4,6 @@ language: base: data: dockerfile: - jvm: - from: registry.access.redhat.com/ubi8/ubi-minimal:8.4 - java-package: java-11-openjdk-headless - run-java-version: 1.3.8 - legacy-jar: - from: registry.access.redhat.com/ubi8/ubi-minimal:8.4 - java-package: java-11-openjdk-headless - run-java-version: 1.3.8 native: from: registry.access.redhat.com/ubi8/ubi-minimal:8.4 native-distroless: diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/CreateProjectHelper.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/CreateProjectHelper.java index bd06533112e30..33e670544c398 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/CreateProjectHelper.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/CreateProjectHelper.java @@ -18,6 +18,9 @@ import javax.lang.model.SourceVersion; public class CreateProjectHelper { + + private static final Set JAVA_VERSIONS_LTS = Set.of("11", "17"); + private static final String DEFAULT_JAVA_VERSION = "11"; private static final Pattern JAVA_VERSION_PATTERN = Pattern.compile("(?:1\\.)?(\\d+)(?:\\..*)?"); public static final String DEFAULT_GROUP_ID = "org.acme"; @@ -78,10 +81,13 @@ public static void setJavaVersion(Map values, String javaTarget) Matcher matcher = JAVA_VERSION_PATTERN .matcher(javaTarget != null ? javaTarget : System.getProperty("java.version", "")); - if (matcher.matches() && Integer.parseInt(matcher.group(1)) < 11) { - values.put(ProjectGenerator.JAVA_TARGET, "8"); + + if (matcher.matches()) { + String versionExtracted = matcher.group(1); + String version = JAVA_VERSIONS_LTS.contains(versionExtracted) ? versionExtracted : DEFAULT_JAVA_VERSION; + values.put(ProjectGenerator.JAVA_TARGET, version); } else { - values.put(ProjectGenerator.JAVA_TARGET, "11"); + values.put(ProjectGenerator.JAVA_TARGET, DEFAULT_JAVA_VERSION); } } diff --git a/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/project/codegen/CreateProjectHelperTest.java b/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/project/codegen/CreateProjectHelperTest.java new file mode 100644 index 0000000000000..3c1e416987790 --- /dev/null +++ b/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/project/codegen/CreateProjectHelperTest.java @@ -0,0 +1,28 @@ +package io.quarkus.devtools.project.codegen; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Test; + +class CreateProjectHelperTest { + + @Test + public void givenJavaVersion17ShouldReturn17() { + Map values = new HashMap<>(); + values.put("nonull", "nonull"); + + CreateProjectHelper.setJavaVersion(values, "17"); + assertEquals("17", values.get("java_target")); + } + + @Test + public void givenJavaVersion16ShouldReturn11() { + Map values = new HashMap<>(); + values.put("nonull", "nonull"); + + CreateProjectHelper.setJavaVersion(values, "16.0.1"); + assertEquals("11", values.get("java_target")); + } +} diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java index c39afd3b76026..ac80f1de5232f 100644 --- a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java +++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java @@ -276,15 +276,15 @@ private void checkDockerfilesWithMaven(Path projectDir) { assertThat(projectDir.resolve("src/main/docker/Dockerfile.jvm")).exists() .satisfies(checkContains("./mvnw package")) .satisfies(checkContains("docker build -f src/main/docker/Dockerfile.jvm")) - .satisfies(checkContains("registry.access.redhat.com/ubi8/ubi-minimal:8.4")) - .satisfies(checkContains("ARG JAVA_PACKAGE=java-11-openjdk-headless")) - .satisfies(checkContains("ENTRYPOINT [ \"/deployments/run-java.sh\" ]")); + .satisfies(checkContains("registry.access.redhat.com/ubi8/openjdk-11-runtime:1.10"))//TODO: make a teste to java17 + .satisfies(checkContains("ENTRYPOINT [ \"java\", \"-jar\", \"/deployments/quarkus-run.jar\" ]")); assertThat(projectDir.resolve("src/main/docker/Dockerfile.legacy-jar")).exists() .satisfies(checkContains("./mvnw package -Dquarkus.package.type=legacy-jar")) .satisfies(checkContains("docker build -f src/main/docker/Dockerfile.legacy-jar")) - .satisfies(checkContains("registry.access.redhat.com/ubi8/ubi-minimal:8.4")) - .satisfies(checkContains("ARG JAVA_PACKAGE=java-11-openjdk-headless")) - .satisfies(checkContains("ENTRYPOINT [ \"/deployments/run-java.sh\" ]")); + .satisfies(checkContains("registry.access.redhat.com/ubi8/openjdk-11-runtime:1.10")) + .satisfies(checkContains("EXPOSE 8080")) + .satisfies(checkContains("USER 185")) + .satisfies(checkContains("ENTRYPOINT [ \"java\", \"-jar\", \"/deployments/quarkus-run.jar\" ]")); assertThat(projectDir.resolve("src/main/docker/Dockerfile.native")).exists() .satisfies(checkContains("./mvnw package -Pnative")) .satisfies(checkContains("registry.access.redhat.com/ubi8/ubi-minimal:8.4"))