From b5dbb0594c8a0cc30d83ee494663497bdf6dfa29 Mon Sep 17 00:00:00 2001 From: leonardomeireles55 Date: Sun, 26 Jan 2025 16:54:39 -0300 Subject: [PATCH] hotfix: add health check from actions. --- .github/workflows/docker-image.yml | 7 ++++ Dockerfile | 42 ++++-------------------- Dockerfile_OLD | 22 ------------- Dockerfile_OLD_1 | 52 ++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 58 deletions(-) delete mode 100644 Dockerfile_OLD create mode 100644 Dockerfile_OLD_1 diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index cb95acd..2357b34 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -58,6 +58,13 @@ jobs: docker-compose up -d - name: Notify deployment run: echo "Deployment completed successfully" + - name: Wait for server to be ready and healthy test + run: | + sleep 15 + until curl -sSf http://localhost:${{ secrets.SERVER_LOCAL_PORT }}/actuator/health; do + echo "Waiting for server..." + sleep 5 + done - name: Set execute permission for cleanup script run: chmod +x ./.github/scripts/cleanup_docker.sh - name: Running scripts diff --git a/Dockerfile b/Dockerfile index 0e6a359..a6cac77 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,50 +1,20 @@ -# First stage, build the custom JRE -FROM eclipse-temurin:21-jdk-alpine AS jre-builder +FROM eclipse-temurin:21-jdk-alpine AS build + +RUN apk add --no-cache maven COPY src /app/src COPY pom.xml /app WORKDIR /app - -ENV MAVEN_VERSION 3.5.4 -ENV MAVEN_HOME /usr/lib/mvn -ENV PATH $MAVEN_HOME/bin:$PATH - -RUN apk update && \ - apk add --no-cache tar binutils maven - RUN mvn clean package -DskipTests -U \ && rm -rf /root/.m2 \ && rm -rf /app/src -RUN jar xvf target/QualityLabPro-0.8.jar -RUN jdeps --ignore-missing-deps -q \ - --recursive \ - --multi-release 21 \ - --print-module-deps \ - --class-path 'BOOT-INF/lib/*' \ - target/QualityLabPro-0.8.jar > modules.txt - -# Build small JRE image -RUN $JAVA_HOME/bin/jlink \ - --verbose \ - --add-modules $(cat modules.txt) \ - --strip-debug \ - --no-man-pages \ - --no-header-files \ - --compress=zip-6 \ - --output /optimized-jdk-21 - -# Second stage, Use the custom JRE and build the app image -FROM alpine:latest -ENV JAVA_HOME=/opt/jdk/jdk-21 -ENV PATH="${JAVA_HOME}/bin:${PATH}" - -# copy JRE from the base image -COPY --from=jre-builder /optimized-jdk-21 $JAVA_HOME +# Run stage +FROM eclipse-temurin:21-jre-alpine WORKDIR /usr/src/app -COPY --from=jre-builder /app/target/QualityLabPro-0.8.jar ./app.jar +COPY --from=build /app/target/QualityLabPro-0.8.jar ./app.jar ENV SPRING_PROFILES_ACTIVE=prod \ SERVER_PORT=8080 diff --git a/Dockerfile_OLD b/Dockerfile_OLD deleted file mode 100644 index 1d6aaed..0000000 --- a/Dockerfile_OLD +++ /dev/null @@ -1,22 +0,0 @@ -FROM eclipse-temurin:21-jdk-alpine AS build - -RUN apk add --no-cache maven - -COPY src /app/src -COPY pom.xml /app - -WORKDIR /app -RUN mvn clean package -DskipTests -U \ - && rm -rf /root/.m2 \ - && rm -rf /app/src - -# Run stage -FROM eclipse-temurin:21-jre-alpine - -WORKDIR /usr/src/app -COPY --from=build /app/target/QualityLabPro-0.7.jar ./app.jar - -ENV SPRING_PROFILES_ACTIVE=prod \ - SERVER_PORT=8080 - -EXPOSE ${SERVER_PORT} \ No newline at end of file diff --git a/Dockerfile_OLD_1 b/Dockerfile_OLD_1 new file mode 100644 index 0000000..0e6a359 --- /dev/null +++ b/Dockerfile_OLD_1 @@ -0,0 +1,52 @@ +# First stage, build the custom JRE +FROM eclipse-temurin:21-jdk-alpine AS jre-builder + +COPY src /app/src +COPY pom.xml /app + +WORKDIR /app + +ENV MAVEN_VERSION 3.5.4 +ENV MAVEN_HOME /usr/lib/mvn +ENV PATH $MAVEN_HOME/bin:$PATH + +RUN apk update && \ + apk add --no-cache tar binutils maven + +RUN mvn clean package -DskipTests -U \ + && rm -rf /root/.m2 \ + && rm -rf /app/src + +RUN jar xvf target/QualityLabPro-0.8.jar +RUN jdeps --ignore-missing-deps -q \ + --recursive \ + --multi-release 21 \ + --print-module-deps \ + --class-path 'BOOT-INF/lib/*' \ + target/QualityLabPro-0.8.jar > modules.txt + +# Build small JRE image +RUN $JAVA_HOME/bin/jlink \ + --verbose \ + --add-modules $(cat modules.txt) \ + --strip-debug \ + --no-man-pages \ + --no-header-files \ + --compress=zip-6 \ + --output /optimized-jdk-21 + +# Second stage, Use the custom JRE and build the app image +FROM alpine:latest +ENV JAVA_HOME=/opt/jdk/jdk-21 +ENV PATH="${JAVA_HOME}/bin:${PATH}" + +# copy JRE from the base image +COPY --from=jre-builder /optimized-jdk-21 $JAVA_HOME + +WORKDIR /usr/src/app +COPY --from=jre-builder /app/target/QualityLabPro-0.8.jar ./app.jar + +ENV SPRING_PROFILES_ACTIVE=prod \ + SERVER_PORT=8080 + +EXPOSE ${SERVER_PORT} \ No newline at end of file