From 5ca5728087aa15067686b9a90a59de831a202554 Mon Sep 17 00:00:00 2001 From: Jabir Emeka Date: Wed, 24 Jul 2024 13:33:48 -0500 Subject: [PATCH 1/4] Dockerfile --- .vscode/settings.json | 3 ++ Geocoder/.dockerignore | 62 ++++++++++++++++++++++++++++++++++ Geocoder/Dockerfile | 77 ++++++++++++++++++++++++++++++++++++++++++ Geocoder/build.gradle | 2 +- 4 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100644 Geocoder/.dockerignore create mode 100644 Geocoder/Dockerfile diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c995aa5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.debug.settings.onBuildFailureProceed": true +} \ No newline at end of file diff --git a/Geocoder/.dockerignore b/Geocoder/.dockerignore new file mode 100644 index 0000000..8893889 --- /dev/null +++ b/Geocoder/.dockerignore @@ -0,0 +1,62 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + +**/.DS_Store +**/.classpath +**/.dockerignore +**/.env +**/.factorypath +**/.git +**/.gitignore +**/.idea +**/.project +**/.sts4-cache +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.next +**/.cache +**/*.dbmdl +**/*.jfm +**/charts +**/docker-compose* +**/compose.y*ml +**/Dockerfile* +**/secrets.dev.yaml +**/values.dev.yaml +**/vendor +LICENSE +README.md +**/*.class +**/*.iml +**/*.ipr +**/*.iws +**/*.log +**/.apt_generated +**/.gradle +**/.gradletasknamecache +**/.nb-gradle +**/.springBeans +**/build +**/dist +**/gradle-app.setting +**/nbbuild +**/nbdist +**/nbproject/private +**/target +*.ctxt +.mtj.tmp +.mvn/timing.properties +buildNumber.properties +dependency-reduced-pom.xml +hs_err_pid* +pom.xml.next +pom.xml.releaseBackup +pom.xml.tag +pom.xml.versionsBackup +release.properties +replay_pid* \ No newline at end of file diff --git a/Geocoder/Dockerfile b/Geocoder/Dockerfile new file mode 100644 index 0000000..c214b1d --- /dev/null +++ b/Geocoder/Dockerfile @@ -0,0 +1,77 @@ +# syntax=docker/dockerfile:1 + +# Comments are provided throughout this file to help you get started. +# If you need more help, visit the Dockerfile reference guide at +# https://docs.docker.com/go/dockerfile-reference/ + +# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7 + +################################################################################ + +# Create a stage for resolving and downloading dependencies. +FROM eclipse-temurin:21-jdk-jammy as deps + +WORKDIR /build + +# Copy the mvnw wrapper with executable permissions. +COPY --chmod=0755 mvnw mvnw +COPY .mvn/ .mvn/ + +# Download dependencies as a separate step to take advantage of Docker's caching. +# Leverage a cache mount to /root/.m2 so that subsequent builds don't have to +# re-download packages. +RUN --mount=type=bind,source=pom.xml,target=pom.xml \ + --mount=type=cache,target=/root/.m2 ./mvnw dependency:go-offline -DskipTests + +################################################################################ + +# Create a stage for building the application based on the stage with downloaded dependencies. +# This Dockerfile is optimized for Java applications that output an uber jar, which includes +# all the dependencies needed to run your app inside a JVM. If your app doesn't output an uber +# jar and instead relies on an application server like Apache Tomcat, you'll need to update this +# stage with the correct filename of your package and update the base image of the "final" stage +# use the relevant app server, e.g., using tomcat (https://hub.docker.com/_/tomcat/) as a base image. +FROM deps as package + +WORKDIR /build + +COPY ./src src/ +RUN --mount=type=bind,source=pom.xml,target=pom.xml \ + --mount=type=cache,target=/root/.m2 \ + ./mvnw package -DskipTests && \ + mv target/$(./mvnw help:evaluate -Dexpression=project.artifactId -q -DforceStdout)-$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout).jar target/app.jar + + +################################################################################ + +# Create a new stage for running the application that contains the minimal +# runtime dependencies for the application. This often uses a different base +# image from the install or build stage where the necessary files are copied +# from the install stage. +# +# The example below uses eclipse-turmin's JRE image as the foundation for running the app. +# By specifying the "21-jre-jammy" tag, it will also use whatever happens to be the +# most recent version of that tag when you build your Dockerfile. +# If reproducability is important, consider using a specific digest SHA, like +# eclipse-temurin@sha256:99cede493dfd88720b610eb8077c8688d3cca50003d76d1d539b0efc8cca72b4. +FROM eclipse-temurin:21-jre-jammy AS final + +# Create a non-privileged user that the app will run under. +# See https://docs.docker.com/go/dockerfile-user-best-practices/ +ARG UID=10001 +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + appuser +USER appuser + +# Copy the executable from the "package" stage. +COPY --from=package build/target/app.jar app.jar + +EXPOSE 8081 + +ENTRYPOINT [ "java", "-jar", "app.jar" ] diff --git a/Geocoder/build.gradle b/Geocoder/build.gradle index 50d4ff6..615db66 100644 --- a/Geocoder/build.gradle +++ b/Geocoder/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'com.example' -version = '0.0.1-SNAPSHOT' +version = '1.0.0-DEMO' java { toolchain { From e68d49e0250eccc9d90649795dc1b521985250ae Mon Sep 17 00:00:00 2001 From: Jabir Emeka Date: Wed, 24 Jul 2024 13:35:42 -0500 Subject: [PATCH 2/4] Updated Docker --- Geocoder/Dockerfile | 76 +++------------------------------------------ 1 file changed, 4 insertions(+), 72 deletions(-) diff --git a/Geocoder/Dockerfile b/Geocoder/Dockerfile index c214b1d..b06e0da 100644 --- a/Geocoder/Dockerfile +++ b/Geocoder/Dockerfile @@ -1,77 +1,9 @@ -# syntax=docker/dockerfile:1 +FROM openjdk:21-jdk-slim -# Comments are provided throughout this file to help you get started. -# If you need more help, visit the Dockerfile reference guide at -# https://docs.docker.com/go/dockerfile-reference/ +WORKDIR /geocoder -# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7 - -################################################################################ - -# Create a stage for resolving and downloading dependencies. -FROM eclipse-temurin:21-jdk-jammy as deps - -WORKDIR /build - -# Copy the mvnw wrapper with executable permissions. -COPY --chmod=0755 mvnw mvnw -COPY .mvn/ .mvn/ - -# Download dependencies as a separate step to take advantage of Docker's caching. -# Leverage a cache mount to /root/.m2 so that subsequent builds don't have to -# re-download packages. -RUN --mount=type=bind,source=pom.xml,target=pom.xml \ - --mount=type=cache,target=/root/.m2 ./mvnw dependency:go-offline -DskipTests - -################################################################################ - -# Create a stage for building the application based on the stage with downloaded dependencies. -# This Dockerfile is optimized for Java applications that output an uber jar, which includes -# all the dependencies needed to run your app inside a JVM. If your app doesn't output an uber -# jar and instead relies on an application server like Apache Tomcat, you'll need to update this -# stage with the correct filename of your package and update the base image of the "final" stage -# use the relevant app server, e.g., using tomcat (https://hub.docker.com/_/tomcat/) as a base image. -FROM deps as package - -WORKDIR /build - -COPY ./src src/ -RUN --mount=type=bind,source=pom.xml,target=pom.xml \ - --mount=type=cache,target=/root/.m2 \ - ./mvnw package -DskipTests && \ - mv target/$(./mvnw help:evaluate -Dexpression=project.artifactId -q -DforceStdout)-$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout).jar target/app.jar - - -################################################################################ - -# Create a new stage for running the application that contains the minimal -# runtime dependencies for the application. This often uses a different base -# image from the install or build stage where the necessary files are copied -# from the install stage. -# -# The example below uses eclipse-turmin's JRE image as the foundation for running the app. -# By specifying the "21-jre-jammy" tag, it will also use whatever happens to be the -# most recent version of that tag when you build your Dockerfile. -# If reproducability is important, consider using a specific digest SHA, like -# eclipse-temurin@sha256:99cede493dfd88720b610eb8077c8688d3cca50003d76d1d539b0efc8cca72b4. -FROM eclipse-temurin:21-jre-jammy AS final - -# Create a non-privileged user that the app will run under. -# See https://docs.docker.com/go/dockerfile-user-best-practices/ -ARG UID=10001 -RUN adduser \ - --disabled-password \ - --gecos "" \ - --home "/nonexistent" \ - --shell "/sbin/nologin" \ - --no-create-home \ - --uid "${UID}" \ - appuser -USER appuser - -# Copy the executable from the "package" stage. -COPY --from=package build/target/app.jar app.jar +COPY /build/libs/Geocoder-1.0.0-DEMO.jar /geocoder/Geocoder.jar EXPOSE 8081 -ENTRYPOINT [ "java", "-jar", "app.jar" ] +ENTRYPOINT ["java", "-jar", "Geocoder.jar"] From e013b65da1b3d14c68ac015cf6678b3d3e581a1e Mon Sep 17 00:00:00 2001 From: Jabir Emeka Date: Fri, 26 Jul 2024 09:09:19 -0500 Subject: [PATCH 3/4] Added Jar packaging to the DockerFile --- Geocoder/Dockerfile | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Geocoder/Dockerfile b/Geocoder/Dockerfile index b06e0da..4520aa4 100644 --- a/Geocoder/Dockerfile +++ b/Geocoder/Dockerfile @@ -1,9 +1,15 @@ +FROM gradle:8.9-jdk21 AS builder + +WORKDIR /app + +COPY build.gradle settings.gradle ./ +COPY src/ ./src/ +RUN gradle build --no-daemon -x test + FROM openjdk:21-jdk-slim WORKDIR /geocoder -COPY /build/libs/Geocoder-1.0.0-DEMO.jar /geocoder/Geocoder.jar - +COPY --from=builder /app/build/libs/Geocoder-1.0.0-DEMO.jar /geocoder/Geocoder.jar EXPOSE 8081 - -ENTRYPOINT ["java", "-jar", "Geocoder.jar"] +ENTRYPOINT ["java", "-jar", "/geocoder/Geocoder.jar"] From e133027251af3e9a1f301f8d94afaf1e9cbd7342 Mon Sep 17 00:00:00 2001 From: Jabir Emeka Date: Fri, 26 Jul 2024 10:11:33 -0500 Subject: [PATCH 4/4] Adding Docker-compose file --- Geocoder/Docker-compose.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Geocoder/Docker-compose.yaml diff --git a/Geocoder/Docker-compose.yaml b/Geocoder/Docker-compose.yaml new file mode 100644 index 0000000..1cea9bc --- /dev/null +++ b/Geocoder/Docker-compose.yaml @@ -0,0 +1,5 @@ +services: + geocoder: + build: . + ports: + - "8081:8081" \ No newline at end of file