From b52d06fa234f1bac3ea4d438879fc40324ed0813 Mon Sep 17 00:00:00 2001 From: Gcolon021 <34667267+Gcolon021@users.noreply.github.com> Date: Mon, 13 Jan 2025 15:38:39 -0500 Subject: [PATCH] Dockerize maven install (#133) * Refactor Dockerfiles to use multi-stage builds. Simplified builds by introducing Maven-based multi-stage builds, consolidating dependencies, and reducing image sizes. Updated entry points to ensure runtime efficiency and maintainability. Transitioned from `ADD` to `COPY` for better clarity and consistency. --- docker/pic-sure-hpds-etl/Dockerfile | 50 ++++++++++++++++++----------- docker/pic-sure-hpds/Dockerfile | 17 ++++++++-- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/docker/pic-sure-hpds-etl/Dockerfile b/docker/pic-sure-hpds-etl/Dockerfile index b375fc13..f160b120 100644 --- a/docker/pic-sure-hpds-etl/Dockerfile +++ b/docker/pic-sure-hpds-etl/Dockerfile @@ -1,21 +1,33 @@ +FROM maven:3.9.4-amazoncorretto-21 AS build + +RUN yum update -y && yum install -y git && yum clean all + +WORKDIR /app + +COPY .m2 /root/.m2 + +COPY . . + +RUN mvn clean install -DskipTests + FROM eclipse-temurin:21-alpine -RUN apk add --no-cache --purge -uU bash && rm -rf /var/cache/apk/* /tmp/* - -RUN apk add --no-cache --purge -uU curl wget unzip gnupg openssl - -ADD create_key.sh . -ADD SQLLoader-jar-with-dependencies.jar . -ADD CSVLoader-jar-with-dependencies.jar . -ADD CSVLoaderNewSearch-jar-with-dependencies.jar . -ADD CSVDumper-jar-with-dependencies.jar . -ADD VCFLocalLoader-jar-with-dependencies.jar . -ADD VariantMetadataLoader-jar-with-dependencies.jar . -ADD UnifiedVCFLocalLoader-jar-with-dependencies.jar . -ADD MultialleleCounter-jar-with-dependencies.jar . -ADD RekeyDataset-jar-with-dependencies.jar . -ADD RemoveConceptFromMetadata-jar-with-dependencies.jar . -ADD HideAnnotationCategoryValue-jar-with-dependencies.jar . -ADD SequentialLoader-jar-with-dependencies.jar . - -ENTRYPOINT java $JAVA_OPTS -Xmx${HEAPSIZE:-2048}m -jar ${LOADER_NAME:-CSVLoader}-jar-with-dependencies.jar +RUN apk add --no-cache --purge -uU bash curl wget unzip gnupg openssl && \ + rm -rf /var/cache/apk/* /tmp/* + +WORKDIR /app +COPY --from=build /app/docker/pic-sure-hpds-etl/SQLLoader-jar-with-dependencies.jar . +COPY --from=build /app/docker/pic-sure-hpds-etl/CSVLoader-jar-with-dependencies.jar . +COPY --from=build /app/docker/pic-sure-hpds-etl/CSVLoaderNewSearch-jar-with-dependencies.jar . +COPY --from=build /app/docker/pic-sure-hpds-etl/CSVDumper-jar-with-dependencies.jar . +COPY --from=build /app/docker/pic-sure-hpds-etl/VCFLocalLoader-jar-with-dependencies.jar . +COPY --from=build /app/docker/pic-sure-hpds-etl/VariantMetadataLoader-jar-with-dependencies.jar . +COPY --from=build /app/docker/pic-sure-hpds-etl/UnifiedVCFLocalLoader-jar-with-dependencies.jar . +COPY --from=build /app/docker/pic-sure-hpds-etl/MultialleleCounter-jar-with-dependencies.jar . +COPY --from=build /app/docker/pic-sure-hpds-etl/RekeyDataset-jar-with-dependencies.jar . +COPY --from=build /app/docker/pic-sure-hpds-etl/RemoveConceptFromMetadata-jar-with-dependencies.jar . +COPY --from=build /app/docker/pic-sure-hpds-etl/HideAnnotationCategoryValue-jar-with-dependencies.jar . +COPY --from=build /app/docker/pic-sure-hpds-etl/SequentialLoader-jar-with-dependencies.jar . +COPY --from=build /app/docker/pic-sure-hpds-etl/create_key.sh . + +ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -Xmx${HEAPSIZE:-2048}m -jar ${LOADER_NAME:-CSVLoader}-jar-with-dependencies.jar"] diff --git a/docker/pic-sure-hpds/Dockerfile b/docker/pic-sure-hpds/Dockerfile index fca99d31..6d973a83 100644 --- a/docker/pic-sure-hpds/Dockerfile +++ b/docker/pic-sure-hpds/Dockerfile @@ -1,6 +1,19 @@ +FROM maven:3.9.4-amazoncorretto-21 AS build + +RUN yum update -y && yum install -y git && yum clean all + +WORKDIR /app + +COPY .m2 /root/.m2 + +COPY . . + +RUN mvn clean install -DskipTests + FROM amazoncorretto:21.0.1-alpine3.18 -# Copy jar and access token from maven build -ADD service-3.0.0-SNAPSHOT.jar /service.jar +WORKDIR /app + +COPY --from=build /app/service/target/service-*-SNAPSHOT.jar /service.jar ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /service.jar"] \ No newline at end of file