-
Notifications
You must be signed in to change notification settings - Fork 42
chore: Allow docker container to also build with gradle #478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dricazenck
merged 1 commit into
Women-Coding-Community:main
from
gpaOliveira:multi-stage-build-with-gradlew
Jan 26, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| .gradle/* | ||
| build/* | ||
| .idea/* | ||
| .vscode/* | ||
| .ideaDataSources/ | ||
| data-test/* | ||
| bin/* | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,26 @@ | ||
| FROM eclipse-temurin:21 | ||
| # Stage 1: Build the application using Gradle and JDK 21 (Temurin) | ||
| FROM gradle:8.7-jdk21-alpine AS build | ||
| WORKDIR /app | ||
|
|
||
| # Copy configuration files to cache dependencies | ||
| COPY build.gradle.kts settings.gradle.kts ./ | ||
|
|
||
| ARG JAR_FILE=build/libs/*.jar | ||
| # Copy source code and build the application | ||
| # Using the 'gradle' command directly since it's pre-installed | ||
| COPY src ./src | ||
| RUN gradle clean bootJar --no-daemon | ||
|
|
||
| # Stage 2: Minimal runtime image using Eclipse Temurin 21 JRE | ||
| FROM eclipse-temurin:21-jre-alpine | ||
| WORKDIR /app | ||
|
|
||
| # Copy the built JAR from the previous stage | ||
| COPY --from=build /app/build/libs/*.jar app.jar | ||
| COPY --from=build /app/src/main/resources /app/resources | ||
|
|
||
| ENV JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" | ||
| ENV SPRING_PROFILES_ACTIVE=docker | ||
|
|
||
| COPY ${JAR_FILE} /app/app.jar | ||
| COPY src/main/resources /app/resources | ||
|
|
||
| # Application configuration | ||
| EXPOSE 8080 5005 | ||
|
|
||
| CMD ["sh", "-c", "java $JAVA_OPTS -jar /app/app.jar"] | ||
| ENTRYPOINT exec java $JAVA_OPTS -jar app.jar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/bin/bash -xe | ||
|
|
||
| # Script that kills the test environment and cleanup volumes | ||
|
|
||
| dir="$(dirname -- "$(which -- "$0" 2>/dev/null || realpath -- "./$0")")" | ||
| docker compose --ansi never \ | ||
| --file "$dir/../docker/docker-compose.yml" \ | ||
| kill | ||
| if [ "$(docker ps -a -q)" ]; then | ||
| docker rm -f $(docker ps -a -q) | ||
| fi | ||
| if [ "$(docker volume ls -q)" ]; then | ||
| docker volume rm $(docker volume ls -q) | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Script that creates the test environment (bringuing it down before) by | ||
| # building the springboot-app (--build), and | ||
| # starting in detached mode (-d), and waiting for it to be healthy (--wait) | ||
| # | ||
| # Also checks how much time the application needed to be healthy in the end | ||
|
|
||
| # Bring it down | ||
| dir="$(dirname -- "$(which -- "$0" 2>/dev/null || realpath -- "./$0")")" | ||
| $dir/docker-down.sh | ||
|
|
||
| # Put it up with --build and --wait | ||
| docker compose --ansi never \ | ||
| --file "$dir/../docker/docker-compose.yml" \ | ||
| up --build -d --wait | ||
|
|
||
| # Checks how long it took, from "Now" in the container to the StartedAt time | ||
| # we don't use the local clock to avoid issues with different timezones | ||
| APP=springboot-app | ||
| NOW_TIME=$(docker exec $APP date "+%H:%M:%S") | ||
| NOW_SECONDS=$(date -d "$NOW_TIME" +%s 2>/dev/null || date -j -f "%H:%M:%S" "${NOW_TIME%.*}" +%s) | ||
| echo "Now on $APP is: $NOW_TIME ($NOW_SECONDS)" | ||
| START_TIME=$(docker inspect --format='{{.State.StartedAt}}' $APP) | ||
| START_SECONDS=$(date -d "$START_TIME" +%s 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%S" "${START_TIME%.*}" +%s) | ||
| echo "Started $APP at: $START_TIME ($START_SECONDS)" | ||
| echo "Time to be healthy (in seconds): $((NOW_SECONDS - START_SECONDS))" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.