Skip to content

Commit 586045b

Browse files
authored
fix: docker image for java + fix access to swagger (#12)
1 parent c87e56e commit 586045b

4 files changed

Lines changed: 26 additions & 21 deletions

File tree

Dockerfile

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
11
# Build Stage
22
FROM gradle:8.13-jdk21 AS build
3-
4-
# Set the working directory inside the container
53
WORKDIR /home/gradle/src
6-
7-
# Copy only the necessary files to the container to minimize cache invalidation
8-
COPY . /home/gradle/src
9-
10-
# Build the project without the Gradle daemon to avoid cache issues
4+
COPY . .
115
RUN gradle clean build --no-daemon
126

13-
# Final Stage: Create a minimal Docker image with just the JAR file
14-
FROM openjdk:21-jdk-slim
15-
16-
# Install curl for debugging purposes
17-
RUN apt update && apt install -y curl
18-
19-
# Set the working directory inside the container
7+
# Runtime Stage (JRE only)
8+
FROM eclipse-temurin:21-jre
209
WORKDIR /app
2110

11+
RUN apt-get update \
12+
&& apt-get install -y --no-install-recommends curl \
13+
&& rm -rf /var/lib/apt/lists/*
14+
2215
# Copy the built jar from the build stage
23-
COPY --from=build /home/gradle/src/build/libs/*.jar app.jar
16+
COPY --from=build /home/gradle/src/build/libs/*.jar /app/app.jar
2417

25-
# Expose the application's port
2618
EXPOSE 8083
2719

28-
# Set JVM options to handle memory issues
29-
ENV JAVA_OPTS="-Xms2g -Xmx4g"
20+
# JVM options (optional)
21+
ENV JAVA_OPTS="-XX:MaxRAMPercentage=75"
3022

31-
# Command to run the application
32-
CMD ["java", "-jar", "app.jar"]
23+
# Use a shell form to expand JAVA_OPTS
24+
CMD ["sh", "-c", "java $JAVA_OPTS -jar /app/app.jar"]

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Local API Usage
2+
3+
To use the API locally, you must pass the following token using the ModHeader browser extension. Otherwise, the API will not work.
4+
5+
**Header:** `X-Auth-Request-Access-Token`
6+
7+
**Token:** `eyJhbGciOiJSUzI1NiIsInR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BGvDW04uO6gZzIoTU6YrPxiX20d74fIc5AjgliuAnNWYYcguTJjhh8hCougrQZGaC_9qkxyWLgakWJATo3DilbuYPoNy0ylFwJZZvr1la5m1S2Kwr5HA`
8+
9+
1. Install the [ModHeader](https://modheader.com/) extension in your browser.
10+
2. Add a new header with the required token when making requests to the API.

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.gradle.caching=true
2+
org.gradle.parallel=true

src/main/java/com/example/spring/security/SecurityConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
4545

4646
// Swagger + OpenAPI - only in dev
4747
// To access Swagger UI and OpenAPI documentation on Docker
48+
// Swagger UI: http://localhost:8080/swagger-ui/index.html
4849
// Fill the search bar at the top with: https://localhost/api/v3/api-docs
49-
authorize.requestMatchers("/swagger-ui/**", "/api/v3/api-docs").hasRole("admin");
50+
authorize.requestMatchers("/swagger-ui/index.html", "/v3/api-docs").hasRole("admin");
5051

5152
// permitAll() is used here because the OAuth proxy handles the authentication
5253
// and the user is already authenticated before reaching this point.

0 commit comments

Comments
 (0)