diff --git a/.gitignore b/.gitignore index 2e735616..fcc22047 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,12 @@ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 +# docker +db/** + +## shell script +dev-restart.sh + # User-specific stuff .idea/**/workspace.xml .idea/**/tasks.xml diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 00000000..17c1a148 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,7 @@ +FROM gradle:7.4-jdk17 + +WORKDIR /app + +COPY . . + +CMD ["./gradlew", ":application:bootRun"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..262876be --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,42 @@ +# docker-compose.yml + +services: + mysql: + container_name: spot-mysql + image: mysql:8 # 선호하는 버전 있을 경우 선정 예정! + ports: + - 3306:3306 # 혹시나 기존에 MySQL 사용 중일 경우 앞자리를 다른 포트로 바꿔야함. + volumes: + - ./db/mysql/data:/var/lib/mysql # 기존 데이터 파일과 격리를 위해 db/mysql/data 로 설정함! + command: + - '--character-set-server=utf8mb4' + - '--collation-server=utf8mb4_unicode_ci' + environment: + TZ : "Asia/Seoul" + MYSQL_ROOT_PASSWORD: test1234 # 임시 비밀번호 + MYSQL_DATABASE: spot # DB 이름 선정 시 변경 예정. + MYSQL_USER: test1234 # 임시 유저 + MYSQL_PASSWORD: test1234 # 임시 비밀번호 + healthcheck: # MySQL 서비스 상태 확인 + test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] + timeout: 20s + retries: 10 + + server: + build: # 디렉토리에 있는 도커파일 이용해서 이미지 빌드 + context: . + dockerfile: Dockerfile.dev + container_name: spot-spring-server + ports: + - 8080:8080 + depends_on: # 항상 mysql 실행하고 서버 실행되게 함. + mysql: + condition: service_healthy # mysql 컨테이너의 healthcheck가 정상일 때까지 대기! + environment: + SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/spot + SPRING_DATASOURCE_USERNAME: test1234 + SPRING_DATASOURCE_PASSWORD: test1234 + volumes: + - ./:/app + - ~/.gradle:/root/.gradle + command: ./gradlew :application:bootRun \ No newline at end of file diff --git a/infrastructure/jpa/build.gradle.kts b/infrastructure/jpa/build.gradle.kts index 5a06ab8d..af4e9e27 100644 --- a/infrastructure/jpa/build.gradle.kts +++ b/infrastructure/jpa/build.gradle.kts @@ -5,6 +5,9 @@ dependencies { // spring implementation("org.springframework.boot:spring-boot-starter-data-jpa:_") + + runtimeOnly("com.mysql:mysql-connector-j") + // queryDSL implementation("com.querydsl:querydsl-jpa:_:jakarta") annotationProcessor("com.querydsl:querydsl-apt:_:jakarta") @@ -13,9 +16,6 @@ dependencies { // p6spy implementation("com.github.gavlyukovskiy:p6spy-spring-boot-starter:_") - - // h2 - DB (또는 도커) 세팅 후 사라질 예정,, - runtimeOnly("com.h2database:h2") } tasks.bootJar { enabled = false } diff --git a/infrastructure/jpa/src/main/resources/application-jpa.yaml b/infrastructure/jpa/src/main/resources/application-jpa.yaml index c5b523ff..48307996 100644 --- a/infrastructure/jpa/src/main/resources/application-jpa.yaml +++ b/infrastructure/jpa/src/main/resources/application-jpa.yaml @@ -1,24 +1,37 @@ spring: datasource: - driver-class-name: org.h2.Driver - url: jdbc:h2:mem:spot - username: sa - password: + url: jdbc:mysql://mysql:3306/spot + username: test1234 + password: test1234 + driver-class-name: com.mysql.cj.jdbc.Driver jpa: - database: h2 + database: mysql + database-platform: org.hibernate.dialect.MySQL8Dialect hibernate: - ddl-auto: create - database-platform: org.hibernate.dialect.H2Dialect - open-in-view: false - defer-datasource-initialization: true + ddl-auto: update # 주의: 프로덕션 환경에서는 'validate' 사용 권장 + show-sql: true + properties: + hibernate: + format_sql: true + use_sql_comments: true - h2: - console: - enabled: true - path: /h2-console + sql: + init: + mode: always # 필요한 경우 'never'로 변경 + +server: + port: 8080 + +logging: + level: + org.hibernate.SQL: DEBUG + org.hibernate.type.descriptor.sql.BasicBinder: TRACE decorator: - datasource: - p6spy: - enable-logging: true \ No newline at end of file + datasource: + p6spy: + enable-logging: true + +# 필요한 경우 추가 설정 +