Skip to content

Commit 595ca87

Browse files
committed
infra: docker compose deployment
1 parent 4bb1584 commit 595ca87

File tree

9 files changed

+290
-56
lines changed

9 files changed

+290
-56
lines changed

docker-compose.yml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
services:
2+
mongo:
3+
image: mongo:8.0
4+
container_name: ezclaim-mongo
5+
restart: unless-stopped
6+
environment:
7+
MONGO_INITDB_ROOT_USERNAME: ${MONGO_ROOT_USERNAME:-ezclaim}
8+
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ROOT_PASSWORD}
9+
volumes:
10+
- mongo_data:/data/db
11+
healthcheck:
12+
test: ["CMD", "mongosh", "--quiet", "--eval", "db.adminCommand('ping')"]
13+
interval: 10s
14+
timeout: 5s
15+
retries: 5
16+
networks:
17+
- backend
18+
19+
redpanda:
20+
image: docker.redpanda.com/redpandadata/redpanda:latest
21+
container_name: ezclaim-redpanda
22+
restart: unless-stopped
23+
command:
24+
- redpanda
25+
- start
26+
- --overprovisioned
27+
- --smp
28+
- "1"
29+
- --memory
30+
- 1G
31+
- --reserve-memory
32+
- 0M
33+
- --node-id
34+
- "0"
35+
- --check=false
36+
- --kafka-addr
37+
- PLAINTEXT://0.0.0.0:9092
38+
- --advertise-kafka-addr
39+
- PLAINTEXT://redpanda:9092
40+
ports:
41+
- "4902:9092"
42+
- "4644:9644"
43+
healthcheck:
44+
test: ["CMD", "bash", "-lc", "curl -fsS http://127.0.0.1:9644/v1/status/ready >/dev/null"]
45+
interval: 10s
46+
timeout: 5s
47+
retries: 10
48+
start_period: 15s
49+
networks:
50+
- backend
51+
52+
minio:
53+
image: minio/minio:latest
54+
container_name: ezclaim-minio
55+
restart: unless-stopped
56+
command: ["server", "/data", "--console-address", ":9001"]
57+
environment:
58+
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-ezclaim}
59+
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
60+
volumes:
61+
- minio_data:/data
62+
- ./infra/minio/cors.xml:/config/cors.xml:ro
63+
ports:
64+
- "4900:9000"
65+
- "4901:9001"
66+
healthcheck:
67+
test: ["CMD", "curl", "-f", "http://127.0.0.1:9000/minio/health/live"]
68+
interval: 10s
69+
timeout: 5s
70+
retries: 5
71+
networks:
72+
- backend
73+
74+
minio-setup:
75+
image: minio/mc:latest
76+
container_name: ezclaim-minio-setup
77+
depends_on:
78+
minio:
79+
condition: service_healthy
80+
restart: "no"
81+
environment:
82+
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-ezclaim}
83+
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
84+
APP_OBJECTSTORE_BUCKET: ${APP_OBJECTSTORE_BUCKET:-ezclaim-prod}
85+
entrypoint: >
86+
/bin/sh -c '
87+
set -euo pipefail;
88+
mc alias set local http://minio:9000 "$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD";
89+
mc mb -p local/"$APP_OBJECTSTORE_BUCKET" || true;
90+
mc cors set local/"$APP_OBJECTSTORE_BUCKET" /config/cors.xml;
91+
'
92+
volumes:
93+
- ./infra/minio/cors.xml:/config/cors.xml:ro
94+
networks:
95+
- backend
96+
97+
ezclaim:
98+
image: eclipse-temurin:24-jre
99+
container_name: ezclaim-app
100+
restart: unless-stopped
101+
depends_on:
102+
mongo:
103+
condition: service_healthy
104+
redpanda:
105+
condition: service_healthy
106+
minio:
107+
condition: service_healthy
108+
working_dir: /app
109+
command: ["java", "-jar", "/app/ezclaim-server.jar"]
110+
volumes:
111+
- ./target/ezclaim-server.jar:/app/ezclaim-server.jar:ro
112+
environment:
113+
SPRING_PROFILES_ACTIVE: prod
114+
SPRING_DATA_MONGODB_URI: mongodb://${MONGO_ROOT_USERNAME:-ezclaim}:${MONGO_ROOT_PASSWORD}@mongo:27017/ezclaim?authSource=admin
115+
KAFKA_BOOTSTRAP_SERVERS: redpanda:9092
116+
APP_OBJECTSTORE_ENDPOINT: https://ezclaim-static.liuzisen.com
117+
APP_OBJECTSTORE_REGION: ${APP_OBJECTSTORE_REGION:-us-east-1}
118+
APP_OBJECTSTORE_ACCESS_KEY: ${MINIO_ROOT_USER:-ezclaim}
119+
APP_OBJECTSTORE_SECRET_KEY: ${MINIO_ROOT_PASSWORD}
120+
APP_OBJECTSTORE_BUCKET: ${APP_OBJECTSTORE_BUCKET:-ezclaim-prod}
121+
APP_OBJECTSTORE_PATH_STYLE: "true"
122+
APP_OBJECTSTORE_ENSURE_BUCKET: "false"
123+
APP_JWT_SECRET: ${APP_JWT_SECRET}
124+
APP_JWT_TTL: ${APP_JWT_TTL:-PT12H}
125+
ports:
126+
- "4080:8080"
127+
healthcheck:
128+
test: ["CMD", "curl", "-f", "http://127.0.0.1:8080/actuator/health"]
129+
interval: 30s
130+
timeout: 5s
131+
retries: 5
132+
networks:
133+
- backend
134+
135+
volumes:
136+
mongo_data:
137+
minio_data:
138+
139+
networks:
140+
backend:
141+
driver: bridge

infra/minio/cors.json

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

infra/minio/cors.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
3+
<CORSRule>
4+
<AllowedOrigin>http://localhost:3000</AllowedOrigin>
5+
<AllowedOrigin>http://127.0.0.1:3000</AllowedOrigin>
6+
<AllowedOrigin>http://localhost:3001</AllowedOrigin>
7+
<AllowedOrigin>http://127.0.0.1:3001</AllowedOrigin>
8+
<AllowedOrigin>https://ezclaim.liuzisen.com</AllowedOrigin>
9+
<AllowedOrigin>https://ezclaim-web.liuzisen.com</AllowedOrigin>
10+
<AllowedOrigin>https://ezclaim-admin.liuzisen.com</AllowedOrigin>
11+
<AllowedMethod>GET</AllowedMethod>
12+
<AllowedMethod>PUT</AllowedMethod>
13+
<AllowedMethod>POST</AllowedMethod>
14+
<AllowedMethod>HEAD</AllowedMethod>
15+
<AllowedHeader>*</AllowedHeader>
16+
<ExposeHeader>ETag</ExposeHeader>
17+
<MaxAgeSeconds>3000</MaxAgeSeconds>
18+
</CORSRule>
19+
</CORSConfiguration>

scripts/build.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Build the Spring Boot jar using a Dockerized Maven+JDK toolchain.
5+
# This script requires Docker and internet access for Maven dependencies.
6+
7+
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
8+
IMAGE="maven:3.9-eclipse-temurin-24"
9+
10+
echo "[build] Using image: $IMAGE"
11+
echo "[build] Project root: $ROOT_DIR"
12+
13+
# Create a local Maven cache directory to speed up repeated builds
14+
mkdir -p "$ROOT_DIR/.m2"
15+
16+
docker run --rm \
17+
-v "$ROOT_DIR":/workspace \
18+
-v "$ROOT_DIR/.m2":/root/.m2 \
19+
-w /workspace \
20+
"$IMAGE" \
21+
mvn -B -e clean package
22+
23+
echo "[build] Build completed. Jar(s) in target/"
24+
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 org.springframework.boot.context.properties.EnableConfigurationProperties;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.web.cors.CorsConfiguration;
7+
import org.springframework.web.cors.CorsConfigurationSource;
8+
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
9+
10+
@Configuration
11+
@EnableConfigurationProperties(CorsProperties.class)
12+
public class CorsConfig {
13+
14+
@Bean
15+
public CorsConfigurationSource corsConfigurationSource(CorsProperties props) {
16+
CorsConfiguration cfg = new CorsConfiguration();
17+
cfg.setAllowedOrigins(props.getAllowedOrigins());
18+
cfg.setAllowedMethods(props.getAllowedMethods());
19+
cfg.setAllowedHeaders(props.getAllowedHeaders());
20+
cfg.setExposedHeaders(props.getExposedHeaders());
21+
cfg.setAllowCredentials(props.isAllowCredentials());
22+
cfg.setMaxAge(props.getMaxAge().toSeconds());
23+
24+
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
25+
source.registerCorsConfiguration("/**", cfg);
26+
return source;
27+
}
28+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.acssz.ezclaim.config;
2+
3+
import java.time.Duration;
4+
import java.util.List;
5+
import org.springframework.boot.context.properties.ConfigurationProperties;
6+
7+
@ConfigurationProperties(prefix = "app.cors")
8+
public class CorsProperties {
9+
10+
private List<String> allowedOrigins = List.of();
11+
private List<String> allowedMethods =
12+
List.of("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD");
13+
private List<String> allowedHeaders = List.of("*");
14+
private List<String> exposedHeaders = List.of();
15+
private boolean allowCredentials = true;
16+
private Duration maxAge = Duration.ofHours(1);
17+
18+
public List<String> getAllowedOrigins() {
19+
return allowedOrigins;
20+
}
21+
22+
public void setAllowedOrigins(List<String> allowedOrigins) {
23+
this.allowedOrigins = allowedOrigins;
24+
}
25+
26+
public List<String> getAllowedMethods() {
27+
return allowedMethods;
28+
}
29+
30+
public void setAllowedMethods(List<String> allowedMethods) {
31+
this.allowedMethods = allowedMethods;
32+
}
33+
34+
public List<String> getAllowedHeaders() {
35+
return allowedHeaders;
36+
}
37+
38+
public void setAllowedHeaders(List<String> allowedHeaders) {
39+
this.allowedHeaders = allowedHeaders;
40+
}
41+
42+
public List<String> getExposedHeaders() {
43+
return exposedHeaders;
44+
}
45+
46+
public void setExposedHeaders(List<String> exposedHeaders) {
47+
this.exposedHeaders = exposedHeaders;
48+
}
49+
50+
public boolean isAllowCredentials() {
51+
return allowCredentials;
52+
}
53+
54+
public void setAllowCredentials(boolean allowCredentials) {
55+
this.allowCredentials = allowCredentials;
56+
}
57+
58+
public Duration getMaxAge() {
59+
return maxAge;
60+
}
61+
62+
public void setMaxAge(Duration maxAge) {
63+
this.maxAge = maxAge;
64+
}
65+
}

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

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

src/main/resources/application-dev.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ spring:
2828
content-type: application/json
2929

3030
app:
31+
cors:
32+
allowed-origins:
33+
- http://localhost:3000
34+
- http://127.0.0.1:3000
35+
- http://localhost:3001
36+
- http://127.0.0.1:3001
37+
- https://ezclaim-web.liuzisen.com
38+
- https://ezclaim-admin.liuzisen.com
3139
objectstore:
3240
# For local dev against S3-compatible (Compose MinIO)
3341
endpoint: http://localhost:9000

src/main/resources/application-prod.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ spring:
2828
content-type: application/json
2929

3030
app:
31+
cors:
32+
allowed-origins:
33+
- https://ezclaim.liuzisen.com
34+
- https://ezclaim-web.liuzisen.com
35+
- https://ezclaim-admin.liuzisen.com
3136
objectstore:
3237
# Leave endpoint unset for AWS S3; set to https://host:port for S3-compatible
3338
endpoint: ${APP_OBJECTSTORE_ENDPOINT:}

0 commit comments

Comments
 (0)