Skip to content

Commit d1e1c73

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

File tree

7 files changed

+257
-33
lines changed

7 files changed

+257
-33
lines changed

docker-compose.yml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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+
- "9092:9092"
42+
- "9644: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.json:/config/cors.json:ro
63+
ports:
64+
- "9000:9000"
65+
- "9001: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+
- proxy
74+
75+
minio-setup:
76+
image: minio/mc:latest
77+
container_name: ezclaim-minio-setup
78+
depends_on:
79+
minio:
80+
condition: service_healthy
81+
restart: "no"
82+
environment:
83+
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-ezclaim}
84+
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
85+
APP_OBJECTSTORE_BUCKET: ${APP_OBJECTSTORE_BUCKET:-ezclaim-prod}
86+
entrypoint: >
87+
/bin/sh -c '
88+
set -euo pipefail;
89+
mc alias set local http://minio:9000 "$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD";
90+
mc mb -p local/"$APP_OBJECTSTORE_BUCKET" || true;
91+
mc cors set local/"$APP_OBJECTSTORE_BUCKET" /config/cors.json;
92+
'
93+
volumes:
94+
- ./infra/minio/cors.json:/config/cors.json:ro
95+
networks:
96+
- backend
97+
98+
ezclaim:
99+
image: eclipse-temurin:21-jre
100+
container_name: ezclaim-app
101+
restart: unless-stopped
102+
depends_on:
103+
mongo:
104+
condition: service_healthy
105+
redpanda:
106+
condition: service_healthy
107+
minio:
108+
condition: service_healthy
109+
working_dir: /app
110+
command: ["java", "-jar", "/app/ezclaim-server.jar"]
111+
volumes:
112+
- ./target/ezclaim-server.jar:/app/ezclaim-server.jar:ro
113+
environment:
114+
SPRING_PROFILES_ACTIVE: prod
115+
SPRING_DATA_MONGODB_URI: mongodb://${MONGO_ROOT_USERNAME:-ezclaim}:${MONGO_ROOT_PASSWORD}@mongo:27017/ezclaim?authSource=admin
116+
KAFKA_BOOTSTRAP_SERVERS: redpanda:9092
117+
APP_OBJECTSTORE_ENDPOINT: https://ezclaim-static.liuzisen.com
118+
APP_OBJECTSTORE_REGION: ${APP_OBJECTSTORE_REGION:-us-east-1}
119+
APP_OBJECTSTORE_ACCESS_KEY: ${MINIO_ROOT_USER:-ezclaim}
120+
APP_OBJECTSTORE_SECRET_KEY: ${MINIO_ROOT_PASSWORD}
121+
APP_OBJECTSTORE_BUCKET: ${APP_OBJECTSTORE_BUCKET:-ezclaim-prod}
122+
APP_OBJECTSTORE_PATH_STYLE: "true"
123+
APP_OBJECTSTORE_ENSURE_BUCKET: "false"
124+
APP_JWT_SECRET: ${APP_JWT_SECRET}
125+
APP_JWT_TTL: ${APP_JWT_TTL:-PT12H}
126+
ports:
127+
- "8080:8080"
128+
healthcheck:
129+
test: ["CMD", "curl", "-f", "http://127.0.0.1:8080/actuator/health"]
130+
interval: 30s
131+
timeout: 5s
132+
retries: 5
133+
networks:
134+
- backend
135+
- proxy
136+
137+
volumes:
138+
mongo_data:
139+
minio_data:
140+
141+
networks:
142+
backend:
143+
driver: bridge
144+
proxy:
145+
external: true
146+
name: caddy

infra/minio/cors.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
{
44
"AllowedOrigins": [
55
"http://localhost:3000",
6+
"http://127.0.0.1:3000",
67
"http://localhost:3001",
7-
"https://ezclaim-admin.liuzisen.com",
8-
"https://ezclaim-web.liuzisen.com"
8+
"http://127.0.0.1:3001",
9+
"https://ezclaim.liuzisen.com",
10+
"https://ezclaim-web.liuzisen.com",
11+
"https://ezclaim-admin.liuzisen.com"
912
],
1013
"AllowedMethods": [
1114
"GET",
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)