diff --git a/.gitignore b/.gitignore index 24cdedf..8c1cf68 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ # production /build +/secrets # misc .DS_Store @@ -20,4 +21,4 @@ npm-debug.log* yarn-debug.log* -yarn-error.log* \ No newline at end of file +yarn-error.log* diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..3779723 --- /dev/null +++ b/compose.yml @@ -0,0 +1,69 @@ +services: + web: + image: nginx + restart: always + ports: + - 80:80 + volumes: + - ./client/build:/usr/share/nginx/html:ro + - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro + depends_on: + - backend + + db: + image: mariadb + restart: always + secrets: + - db-password + volumes: + - db-data:/var/lib/mysql + environment: + - MYSQL_DATABASE=stackoverflow + - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db-password + healthcheck: + test: ['CMD-SHELL', 'mysqladmin ping -h 127.0.0.1 --password="$$(cat /run/secrets/db-password)" --silent'] + interval: 3s + retries: 5 + start_period: 30s + ports: + - 3306:3306 + + redis: + image: redis + restart: always + healthcheck: + test: ["CMD-SHELL", "redis-cli ping | grep PONG"] + interval: 3s + retries: 5 + ports: + - 6379:6379 + + backend: + image: eclipse-temurin:11-jre + restart: always + secrets: + - backend-secrets + command: java -jar app.jar + volumes: + - ./server/build/libs/seb41-41-pre-project-0.0.1-SNAPSHOT.jar:/app.jar:ro + environment: + - SPRING_CONFIG_IMPORT=file:/run/secrets/backend-secrets[.yml] + - SPRING_PROFILES_ACTIVE=server + - SPRING_DATASOURCE_URL=jdbc:mysql://db/stackoverflow + - SPRING_DATASOURCE_USERNAME=root + - SPRING_REDIS_HOST=redis + # - SPRING_JPA_HIBERNATE_DDL-AUTO=create-only # 최초 기동시 스키마 생성을 위해 사용 + depends_on: + db: + condition: service_healthy + redis: + condition: service_healthy + +volumes: + db-data: + +secrets: + db-password: + file: ./secrets/db-password + backend-secrets: + file: ./secrets/backend-secrets.yml diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..6ad5f5b --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,15 @@ +events {} + +http { + server { + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri /index.html =404; + } + + location /api/ { + proxy_pass http://backend:8080/api/; + } + } +} diff --git a/server/src/main/java/seb4141preproject/security/auth/redis/RedisConfig.java b/server/src/main/java/seb4141preproject/security/auth/redis/RedisConfig.java index 312931b..2cdd29a 100644 --- a/server/src/main/java/seb4141preproject/security/auth/redis/RedisConfig.java +++ b/server/src/main/java/seb4141preproject/security/auth/redis/RedisConfig.java @@ -1,7 +1,7 @@ package seb4141preproject.security.auth.redis; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.data.redis.RedisProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; @@ -15,15 +15,11 @@ @RequiredArgsConstructor public class RedisConfig { -// @Value("${spring.redis.host}") - private final String host = "localhost"; - -// @Value("${spring.redis.port}") - private final int port = 6379; + private final RedisProperties redisProperties; @Bean public RedisConnectionFactory redisConnectionFactory() { - return new LettuceConnectionFactory(host, port); + return new LettuceConnectionFactory(redisProperties.getHost(), redisProperties.getPort()); } @Bean diff --git a/server/src/main/resources/application-server.yml b/server/src/main/resources/application-server.yml index bc275b9..d7f42a9 100644 --- a/server/src/main/resources/application-server.yml +++ b/server/src/main/resources/application-server.yml @@ -2,3 +2,4 @@ spring: jpa: hibernate: ddl-auto: validate + \ No newline at end of file diff --git a/server/src/test/resources/application.yml b/server/src/test/resources/application.yml new file mode 100644 index 0000000..5a4f036 --- /dev/null +++ b/server/src/test/resources/application.yml @@ -0,0 +1,4 @@ +jwt: + key: kevin12341234123412341234123412341234adsfgeeettwaeaafasfsadf + ATExpiration: 10 + RTExpiration: 420