Skip to content

Commit f586b7c

Browse files
committed
deploy: add prod configuration (gcs + local mongo + local redpanda)
1 parent 6491828 commit f586b7c

File tree

7 files changed

+155
-29
lines changed

7 files changed

+155
-29
lines changed

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM eclipse-temurin:24-jdk AS build
2+
WORKDIR /app
3+
4+
# Copy build tooling first to leverage layer caching during dependency resolution
5+
COPY .mvn/ .mvn/
6+
COPY mvnw pom.xml ./
7+
8+
# Pre-fetch dependencies to speed up subsequent builds
9+
RUN ./mvnw -B -ntp dependency:go-offline
10+
11+
# Bring in the full project and build the Spring Boot fat jar
12+
COPY . .
13+
RUN ./mvnw -B -DskipTests clean package \
14+
&& JAR_FILE="$(find target -maxdepth 1 -type f -name '*.jar' ! -name '*original*' | head -n 1)" \
15+
&& test -n "$JAR_FILE" \
16+
&& cp "$JAR_FILE" app.jar
17+
18+
FROM eclipse-temurin:24-jre AS runtime
19+
WORKDIR /app
20+
21+
# Run as a non-root user for better container hardening
22+
RUN useradd --system --create-home --home-dir /app ezclaim
23+
24+
COPY --from=build /app/app.jar ./app.jar
25+
26+
EXPOSE 8080
27+
USER ezclaim
28+
29+
ENTRYPOINT ["java","-jar","/app/app.jar"]

docker-compose.prod.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
services:
2+
app:
3+
image: rabbull/ezclaim-server:0.0.1-snapshot
4+
container_name: ezclaim-server-app
5+
restart: unless-stopped
6+
depends_on:
7+
mongo:
8+
condition: service_healthy
9+
redpanda:
10+
condition: service_healthy
11+
ports:
12+
- "8080:8080"
13+
environment:
14+
SPRING_PROFILES_ACTIVE: prod
15+
SPRING_DATA_MONGODB_URI: mongodb://ezclaim:E2ClaimPass@mongo:27017/ezclaim?authSource=admin
16+
KAFKA_BOOTSTRAP_SERVERS: redpanda:9092
17+
APP_OBJECTSTORE_ENDPOINT: https://storage.googleapis.com
18+
APP_OBJECTSTORE_REGION: auto
19+
APP_OBJECTSTORE_BUCKET: ezclaim
20+
APP_OBJECTSTORE_ACCESS_KEY: changeme
21+
APP_OBJECTSTORE_SECRET_KEY: changeme
22+
APP_OBJECTSTORE_PATH_STYLE: false
23+
APP_OBJECTSTORE_ENSURE_BUCKET: false
24+
APP_JWT_SECRET: changeme
25+
APP_JWT_ALG: HS256
26+
APP_JWT_TTL: PT12H
27+
28+
mongo:
29+
image: mongo:8.0
30+
container_name: ezclaim-server-mongo
31+
restart: unless-stopped
32+
ports:
33+
- "27017:27017"
34+
environment:
35+
MONGO_INITDB_ROOT_USERNAME: ezclaim
36+
MONGO_INITDB_ROOT_PASSWORD: E2ClaimPass
37+
volumes:
38+
- /mnt/ezclaim/ezclaim-server/mongo:/data/db
39+
healthcheck:
40+
test: ["CMD", "mongosh", "--quiet", "--eval", "db.adminCommand('ping')"]
41+
interval: 10s
42+
timeout: 5s
43+
retries: 5
44+
45+
redpanda:
46+
image: docker.redpanda.com/redpandadata/redpanda:latest
47+
container_name: ezclaim-server-redpanda
48+
restart: unless-stopped
49+
ports:
50+
- "9092:9092"
51+
- "9644:9644"
52+
volumes:
53+
- /mnt/ezclaim/ezclaim-server/redpanda:/var/lib/redpanda/data
54+
command:
55+
- redpanda
56+
- start
57+
- --smp
58+
- "1"
59+
- --memory
60+
- 2G
61+
- --reserve-memory
62+
- 0M
63+
- --overprovisioned
64+
- --node-id
65+
- "0"
66+
- --check=false
67+
- --kafka-addr
68+
- PLAINTEXT://0.0.0.0:9092
69+
- --advertise-kafka-addr
70+
- PLAINTEXT://redpanda:9092
71+
healthcheck:
72+
test: ["CMD", "bash", "-lc", "curl -fsS http://localhost:9644/v1/status/ready >/dev/null"]
73+
interval: 10s
74+
timeout: 5s
75+
retries: 10
76+
start_period: 30s

infra/env/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Keep actual prod env files out of version control.
2+
*.env
3+

infra/gcs/cors.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"origin": ["https://claim.acssz.org", "https://claim-admin.acssz.org"],
4+
"method": ["GET", "PUT", "POST", "DELETE", "HEAD", "OPTIONS"],
5+
"responseHeader": ["Content-Type"],
6+
"maxAgeSeconds": 3600
7+
}
8+
]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.acssz.ezclaim.config;
2+
3+
import java.time.Duration;
4+
import java.util.List;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.web.cors.CorsConfiguration;
8+
import org.springframework.web.cors.CorsConfigurationSource;
9+
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
10+
11+
@Configuration
12+
public class CorsConfig {
13+
14+
@Bean
15+
public CorsConfigurationSource corsConfigurationSource() {
16+
CorsConfiguration c = new CorsConfiguration();
17+
c.setAllowedOriginPatterns(List.of("https://*.acssz.org", "https://acssz.org"));
18+
c.setAllowedMethods(List.of("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"));
19+
c.setAllowedHeaders(List.of("*"));
20+
c.setAllowCredentials(true);
21+
c.setMaxAge(Duration.ofHours(1));
22+
23+
UrlBasedCorsConfigurationSource s = new UrlBasedCorsConfigurationSource();
24+
s.registerCorsConfiguration("/**", c);
25+
return s;
26+
}
27+
28+
}

src/main/java/org/acssz/ezclaim/config/DevCorsConfig.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/main/resources/application-prod.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
spring:
2+
kafka:
3+
bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS}
4+
mvc:
5+
cors:
6+
mappings:
7+
"[/**]":
8+
allowed-origins: ${APP_CORS_ALLOWED_ORIGINS}
9+
allowed-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS,HEAD
10+
allowed-headers: "*"
11+
allow-credentials: true
12+
max-age: PT1H
213
data:
314
mongodb:
415
# Provide as environment variable in deployment

0 commit comments

Comments
 (0)