Skip to content

Commit

Permalink
refactor: JPA Entity Persistence 모듈 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
h-beeen committed Oct 27, 2024
1 parent 448eed9 commit 382648c
Show file tree
Hide file tree
Showing 22 changed files with 188 additions and 211 deletions.
90 changes: 45 additions & 45 deletions .github/workflows/Continuous Delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,48 +27,48 @@ jobs:
java-version: '21'
distribution: 'adopt'

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::125183404358:role/VacgomGithubActionAssumeRole
aws-region: ap-northeast-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Invoke Gradle
uses: gradle/gradle-build-action@v2

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build, tag, and push image to Amazon ECR
env:
PROFILE: prod
IMAGE_REPO_URL: ${{ steps.login-ecr.outputs.registry }}/vacgom-ecr-new
IMAGE_TAG: ${{ github.sha }}
run: ./gradlew jib --parallel

- name: Download Task Definition
run: |
aws ecs describe-task-definition \
--task-definition vacgom-taskdef-new \
--query taskDefinition \
> task-definition.json
- name: Update Task Definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: vacgom-backend
image: ${{ steps.login-ecr.outputs.registry }}/vacgom-ecr-new:${{ github.sha }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: new-vacgom-wow
cluster: vacgom-cluster-2
wait-for-service-stability: true
# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v4
# with:
# role-to-assume: arn:aws:iam::125183404358:role/VacgomGithubActionAssumeRole
# aws-region: ap-northeast-2
#
# - name: Login to Amazon ECR
# id: login-ecr
# uses: aws-actions/amazon-ecr-login@v1
#
# - name: Invoke Gradle
# uses: gradle/gradle-build-action@v2
#
# - name: Grant execute permission for gradlew
# run: chmod +x gradlew
#
# - name: Build, tag, and push image to Amazon ECR
# env:
# PROFILE: prod
# IMAGE_REPO_URL: ${{ steps.login-ecr.outputs.registry }}/vacgom-ecr-new
# IMAGE_TAG: ${{ github.sha }}
# run: ./gradlew jib --parallel
#
# - name: Download Task Definition
# run: |
# aws ecs describe-task-definition \
# --task-definition vacgom-taskdef-new \
# --query taskDefinition \
# > task-definition.json
#
# - name: Update Task Definition
# id: task-def
# uses: aws-actions/amazon-ecs-render-task-definition@v1
# with:
# task-definition: task-definition.json
# container-name: vacgom-backend
# image: ${{ steps.login-ecr.outputs.registry }}/vacgom-ecr-new:${{ github.sha }}
#
# - name: Deploy Amazon ECS task definition
# uses: aws-actions/amazon-ecs-deploy-task-definition@v1
# with:
# task-definition: ${{ steps.task-def.outputs.task-definition }}
# service: new-vacgom-wow
# cluster: vacgom-cluster-2
# wait-for-service-stability: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### CUSTOM ###
.vscode
.DS_Store
**/resources

### DEFAULT ###
HELP.md
Expand Down
127 changes: 26 additions & 101 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,125 +1,50 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.springframework.boot.gradle.tasks.bundling.BootJar

val activeProfile = System.getenv("PROFILE") ?: "product"
val imageTag = System.getenv("IMAGE_TAG") ?: "latest"
val repoURL: String? = System.getenv("IMAGE_REPO_URL")

plugins {
id("org.springframework.boot") version "3.3.5"
id("com.google.cloud.tools.jib") version "3.4.3"
id("io.spring.dependency-management") version "1.1.6"

id("io.freefair.lombok") version "8.10"
kotlin("plugin.lombok") version "2.0.20"

kotlin("jvm") version "2.0.21"
kotlin("kapt") version "2.0.21"
kotlin("plugin.spring") version "2.0.21"
kotlin("plugin.jpa") version "2.0.21"
kotlin("plugin.allopen") version "2.0.21"

id("org.springframework.boot") version "3.3.5"
id("io.spring.dependency-management") version "1.1.6"
}

allprojects {
group = "kr.co.vacgom"
version = "3.0.0"
group = "kr.xd"
version = "1.0.0"
repositories { mavenCentral() }

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs += "-Xjsr305=strict"
jvmTarget = "21"
}
}

tasks.withType<Test> {
useJUnitPlatform()
}
}

java {
sourceCompatibility = JavaVersion.VERSION_21
}

repositories {
mavenCentral()
}

dependencies {
val springBootVersion = "3.3.5"
val jsonwebtokenVersion = "0.12.6"
val javaJwtVersion = "4.4.0"

implementation(platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion"))
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("io.jsonwebtoken:jjwt-api:$jsonwebtokenVersion")
implementation("io.jsonwebtoken:jjwt-gson:$jsonwebtokenVersion")
runtimeOnly("io.jsonwebtoken:jjwt-impl:$jsonwebtokenVersion")
implementation("com.auth0:java-jwt:$javaJwtVersion")
runtimeOnly("com.mysql:mysql-connector-j")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
}

jib {
from {
image = "amazoncorretto:21-alpine-jdk"
}
to {
image = repoURL
tags = setOf(imageTag)
}
container {
jvmFlags = listOf(
"-Dspring.profiles.active=$activeProfile",
"-Dserver.port=8080",
"-XX:+UseContainerSupport",
"-Duser.timezone=Asia/Seoul"
)
ports = listOf("8080")
}
}

subprojects {
apply(plugin = "java")
apply(plugin = "kotlin")
apply(plugin = "kotlin-spring")
apply(plugin = "org.springframework.boot")
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "io.spring.dependency-management")
apply(plugin = "io.freefair.lombok")

dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.0")
}

repositories { mavenCentral() }
tasks.withType<JavaCompile> {
sourceCompatibility = "21"
targetCompatibility = "21"
}

dependencies {
val springBootVersion = "3.3.5"
val jsonwebtokenVersion = "0.12.6"
val javaJwtVersion = "4.4.0"
tasks.withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_21)
}
}

implementation(platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion"))
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("io.jsonwebtoken:jjwt-api:$jsonwebtokenVersion")
implementation("io.jsonwebtoken:jjwt-gson:$jsonwebtokenVersion")
runtimeOnly("io.jsonwebtoken:jjwt-impl:$jsonwebtokenVersion")
implementation("com.auth0:java-jwt:$javaJwtVersion")
runtimeOnly("com.mysql:mysql-connector-j")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
tasks.withType<Test> {
useJUnitPlatform()
}

java {
sourceCompatibility = JavaVersion.VERSION_21
tasks.withType<BootJar> {
enabled = false
}
}
26 changes: 26 additions & 0 deletions vacgom-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
plugins {
kotlin("jvm")
kotlin("plugin.spring")
id("org.springframework.boot")
id("io.freefair.lombok") version "8.10"
}

dependencies {
val springBootVersion = "3.3.5"
val jsonwebtokenVersion = "0.12.6"
val javaJwtVersion = "4.4.0"

implementation(project(":vacgom-persistence"))
// implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation(platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion"))
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("io.jsonwebtoken:jjwt-api:$jsonwebtokenVersion")
implementation("io.jsonwebtoken:jjwt-gson:$jsonwebtokenVersion")
runtimeOnly("io.jsonwebtoken:jjwt-impl:$jsonwebtokenVersion")
implementation("com.auth0:java-jwt:$javaJwtVersion")

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
}
2 changes: 2 additions & 0 deletions vacgom-api/src/main/kotlin/kr/co/vacgom/api/VagomApi.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package kr.co.vacgom.api

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.domain.EntityScan
import org.springframework.boot.runApplication

@SpringBootApplication
@EntityScan(basePackages = ["kr.co.vacgom.persistence"])
class VacgomApi

fun main(args: Array<String>) {
Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions vacgom-persistence/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import org.springframework.boot.gradle.tasks.bundling.BootJar

plugins {
id("java")
java
id("io.freefair.lombok") version "8.10"
}

repositories { mavenCentral() }

dependencies {
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor:3.3.5")
runtimeOnly("com.mysql:mysql-connector-j")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
}

tasks.withType<BootJar> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package kr.co.vacgom.persistence.global.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@Configuration
@EnableJpaAuditing
@EnableJpaRepositories(basePackages = "kr.co.vacgom.persistence")
public class JpaConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package kr.co.vacgom.persistence.global.config;

import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SnakeCaseUpperCaseNamingStrategy implements PhysicalNamingStrategy {


private String convertToSnakeCaseUpperCase(String input) {
String regex = "([a-z])([A-Z]+)";
String replacement = "$1_$2";
return input.replaceAll(regex, replacement).toUpperCase();
}

@Override
public Identifier toPhysicalCatalogName(Identifier identifier, JdbcEnvironment jdbcEnvironment) {
return null;
}

@Override
public Identifier toPhysicalSchemaName(Identifier identifier, JdbcEnvironment jdbcEnvironment) {
return null;
}

@Override
public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
return new Identifier(convertToSnakeCaseUpperCase(name.getText()), name.isQuoted());
}

@Override
public Identifier toPhysicalSequenceName(Identifier identifier, JdbcEnvironment jdbcEnvironment) {
return null;
}

@Override
public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment context) {
return new Identifier(convertToSnakeCaseUpperCase(name.getText()), name.isQuoted());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kr.co.vacgom.persistence.global;
package kr.co.vacgom.persistence.global.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.Column;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package kr.co.vacgom.persistence.hospital;
package kr.co.vacgom.persistence.hospital.entity;

import jakarta.persistence.*;
import kr.co.vacgom.persistence.global.BaseEntity;
import kr.co.vacgom.persistence.hospital.constants.HospitalType;
import kr.co.vacgom.persistence.global.entity.BaseEntity;
import kr.co.vacgom.persistence.hospital.entity.constants.HospitalType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand Down
Loading

0 comments on commit 382648c

Please sign in to comment.