Skip to content

Commit ab109ec

Browse files
committed
Address review: non-root image, workflow ordering, config + entity cleanup
- Dockerfile: run the JVM as a non-root 'spring' user. - workflow: smoke now 'needs: build', so it doesn't rebuild and burn its timeout when the build has already failed. - keploy.yml: drop the unused mongoPassword default (this app is Postgres-only). - Product: remove the setCreatedAt setter; createdAt is @PrePersist-assigned on an updatable=false column, so a setter is silently dropped on save and misleads callers. - seed.sh: fail loudly in create() when the POST fails or returns no id, instead of appending an empty id and corrupting later phases. Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
1 parent f4f692c commit ab109ec

5 files changed

Lines changed: 15 additions & 8 deletions

File tree

.github/workflows/spring-boot-product-catalog.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545

4646
smoke:
4747
name: end-to-end smoke test
48+
needs: build
4849
runs-on: ubuntu-latest
4950
timeout-minutes: 20
5051
steps:

spring-boot-product-catalog/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ RUN ./mvnw -B -q -DskipTests clean package
1616
# ---- Run stage: slim JRE image ----
1717
FROM eclipse-temurin:21-jre
1818
WORKDIR /app
19-
# curl is used by the docker-compose healthcheck.
19+
# curl is used by the docker-compose healthcheck. Also create a non-root user to run the JVM.
2020
RUN apt-get update && apt-get install -y --no-install-recommends curl \
21-
&& rm -rf /var/lib/apt/lists/*
21+
&& rm -rf /var/lib/apt/lists/* \
22+
&& addgroup --system spring && adduser --system --ingroup spring spring
2223
COPY --from=build /app/target/*.jar app.jar
2324
EXPOSE 8080
25+
USER spring:spring
2426
ENTRYPOINT ["java", "-jar", "app.jar"]

spring-boot-product-catalog/keploy.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ test:
4242
skipCoverage: false
4343
coverageReportPath: ""
4444
ignoreOrdering: true
45-
mongoPassword: default@123
4645
language: ""
4746
removeUnusedMocks: false
4847
preserveFailedMocks: false

spring-boot-product-catalog/seed.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ CREATED=() # ids of products created, in order
1717
# create '<json>' -> prints response, appends new id to CREATED
1818
create() {
1919
local json="$1" body id
20-
body=$(curl -fsS -X POST "$BASE/api/products" -H 'Content-Type: application/json' -d "$json")
20+
if ! body=$(curl -fsS -X POST "$BASE/api/products" -H 'Content-Type: application/json' -d "$json"); then
21+
echo " ERROR: create request failed for: $json" >&2
22+
exit 1
23+
fi
2124
echo " created: $body"
2225
id=$(printf '%s' "$body" | id_of)
26+
if [ -z "$id" ]; then
27+
echo " ERROR: no id in create response: $body" >&2
28+
exit 1
29+
fi
2330
CREATED+=("$id")
2431
}
2532

spring-boot-product-catalog/src/main/java/io/keploy/productcatalog/model/Product.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,9 @@ public void setCategory(String category) {
101101
this.category = category;
102102
}
103103

104+
// Read-only: createdAt is assigned once by @PrePersist and the column is updatable = false,
105+
// so there is intentionally no setter — a set would be silently dropped on the next save().
104106
public Instant getCreatedAt() {
105107
return createdAt;
106108
}
107-
108-
public void setCreatedAt(Instant createdAt) {
109-
this.createdAt = createdAt;
110-
}
111109
}

0 commit comments

Comments
 (0)