Skip to content

Commit

Permalink
Codestart modularize Dockerfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
vsevel committed Aug 19, 2024
1 parent b7d6639 commit 2dd738d
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Before building the container image run:
#
# {#insert quarkusbuild /}
# {buildtool.cli} {cmd}
#
# Then, build the image with:
#
Expand Down Expand Up @@ -77,15 +77,20 @@
# accessed directly. (example: "foo.example.com,bar.example.com")
#
###
{#if dockerfile.jvm.from}
FROM {dockerfile.jvm.from}
{#else}
FROM registry.access.redhat.com/ubi8/openjdk-{java.version}:1.20
{/if}
FROM {image}

ENV LANGUAGE='en_US:en'

{#insert copy /}
{#if type == 'jvm'}
# We make four distinct layers so if there are application changes the library layers can be re-used
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/
{#else}
COPY {buildtool.build-dir}/lib/* /deployments/lib/
COPY {buildtool.build-dir}/*-runner.jar /deployments/quarkus-run.jar
{/if}

EXPOSE 8080
USER 185
Expand All @@ -95,4 +100,4 @@ ENV AB_JOLOKIA_OFF=""
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" ]
ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
####
# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode.
{#if type == 'native-micro'}
# 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.
{/if}
#
# Before building the container image run:
#
# {buildtool.cli} {buildtool.cmd.package-native}
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.{type} -t quarkus/{project.artifact-id} .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 quarkus/{project.artifact-id}
#
###
FROM {image}
WORKDIR /work/
RUN chown 1001 /work \
&& chmod "g+rwX" /work \
&& chown 1001:root /work
COPY --chown=1001:root {buildtool.build-dir}/*-runner /work/application

EXPOSE 8080
USER 1001

ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"]
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
{#include Dockerfile-layout type='jvm'}
{#quarkusbuild}{buildtool.cli} {buildtool.cmd.package}{/quarkusbuild}
{#copy}
# We make four distinct layers so if there are application changes the library layers can be re-used
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}

{#include Dockerfile-jar
type='jvm'
image=dockerfile.jvm.from.format(java.version)
cmd=buildtool.cmd.package /}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{#include Dockerfile-layout type='legacy-jar'}
{#quarkusbuild}{buildtool.cli} {buildtool.cmd.package-legacy-jar}{/quarkusbuild}
{#copy}
COPY {buildtool.build-dir}/lib/* /deployments/lib/
COPY {buildtool.build-dir}/*-runner.jar /deployments/quarkus-run.jar
{/copy}
{/include}
{#include Dockerfile-jar
type='legacy-jar'
image=dockerfile.jvm.from.format(java.version)
cmd=buildtool.cmd.package-legacy-jar /}
Original file line number Diff line number Diff line change
@@ -1,27 +1 @@
####
# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode.
#
# Before building the container image run:
#
# {buildtool.cli} {buildtool.cmd.package-native}
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.native -t quarkus/{project.artifact-id} .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 quarkus/{project.artifact-id}
#
###
FROM {dockerfile.native.from}
WORKDIR /work/
RUN chown 1001 /work \
&& chmod "g+rwX" /work \
&& chown 1001:root /work
COPY --chown=1001:root {buildtool.build-dir}/*-runner /work/application

EXPOSE 8080
USER 1001

ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"]
{#include Dockerfile-native type='native' image=dockerfile.native.from /}
Original file line number Diff line number Diff line change
@@ -1,30 +1 @@
####
# 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:
#
# {buildtool.cli} {buildtool.cmd.package-native}
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/{project.artifact-id} .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 quarkus/{project.artifact-id}
#
###
FROM {dockerfile.native-micro.from}
WORKDIR /work/
RUN chown 1001 /work \
&& chmod "g+rwX" /work \
&& chown 1001:root /work
COPY --chown=1001:root {buildtool.build-dir}/*-runner /work/application

EXPOSE 8080
USER 1001

ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"]
{#include Dockerfile-native type='native-micro' image=dockerfile.native-micro.from /}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ language:
from: registry.access.redhat.com/ubi8/ubi-minimal:8.10
native-micro:
from: quay.io/quarkus/quarkus-micro-image:2.0
jvm:
from: registry.access.redhat/ubi8/openjdk-%s:1.20
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -197,6 +199,15 @@ public CompletionStage<Object> resolve(EvalContext context) {
return CompletedStage.of(compareVersionTo(value, (String) e));
});
}
case "format":
CompletableFuture<?>[] paramStages = context.getParams().stream()
.map(context::evaluate)
.map(CompletionStage::toCompletableFuture)
.toArray(CompletableFuture[]::new);

return CompletableFuture.allOf(paramStages)
.thenApply(a -> Arrays.stream(paramStages).map(CompletableFuture::join).toArray(Object[]::new))
.thenApply(a -> String.format(value, a));
default:
return Results.notFound(context);
}
Expand Down

0 comments on commit 2dd738d

Please sign in to comment.