diff --git a/.github/workflows/ci-cd-main.yml b/.github/workflows/ci-cd-main.yml index f3a526f..2f664d3 100644 --- a/.github/workflows/ci-cd-main.yml +++ b/.github/workflows/ci-cd-main.yml @@ -1,4 +1,4 @@ -name: Batch Server CI/CD Pipeline +xname: Batch Server CI/CD Pipeline on: push: @@ -70,4 +70,7 @@ jobs: docker stop batch-service || true docker rm batch-service || true docker pull ${{ secrets.DOCKER_USERNAME }}/cantech:${{ github.sha }} - docker run -d --name batch-service -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/cantech:${{ github.sha }} + docker run -d --name batch-service -p 8080:8080 \ + -e SPRING_PROFILES_ACTIVE=prod \ + -e CONFIG_SERVER_URL="${{ secrets.CONFIG_SERVER_URL }}" \ + ${{ secrets.DOCKER_USERNAME }}/cantech:${{ github.sha }} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index e6e8def..5505533 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -41,6 +41,16 @@ dependencies { // Lombok (테스트 환경) testCompileOnly("org.projectlombok:lombok") testAnnotationProcessor("org.projectlombok:lombok") + + // Spring Cloud Config + implementation("org.springframework.cloud:spring-cloud-starter-config") + testImplementation("com.h2database:h2") +} + +dependencyManagement { + imports { + mavenBom("org.springframework.cloud:spring-cloud-dependencies:2023.0.3") + } } tasks.withType { diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 7e717be..9e61139 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -1,5 +1,16 @@ +spring.config.import=optional:configserver: + +eureka.client.register-with-eureka=true +eureka.client.fetch-registry=true eureka.client.service-url.defaultZone=${EUREKA_SERVER_URL} +spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.url=${DATABASE_URL} spring.datasource.username=${DATABASE_USERNAME} -spring.datasource.password=${DATABASE_PASSWORD} \ No newline at end of file +spring.datasource.password=${DATABASE_PASSWORD} + +spring.jpa.database=postgresql +spring.jpa.hibernate.ddl-auto=none +spring.jpa.show-sql=true + +server.port=8080 \ No newline at end of file diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 7e717be..e53955b 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -1,5 +1 @@ -eureka.client.service-url.defaultZone=${EUREKA_SERVER_URL} - -spring.datasource.url=${DATABASE_URL} -spring.datasource.username=${DATABASE_USERNAME} -spring.datasource.password=${DATABASE_PASSWORD} \ No newline at end of file +spring.config.import=optional:configserver:${CONFIG_SERVER_URL} \ No newline at end of file diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties new file mode 100644 index 0000000..e051d10 --- /dev/null +++ b/src/main/resources/application-test.properties @@ -0,0 +1,7 @@ +spring.datasource.url=${DATABASE_URL:jdbc:h2:mem:testdb} +spring.datasource.username=${DATABASE_USERNAME:sa} +spring.datasource.password=${DATABASE_PASSWORD:} +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect + +spring.cloud.config.enabled=false +eureka.client.enabled=false \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c33a317..11631e4 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,11 +1,3 @@ -spring.application.name=batch-service -server.port=8083 +spring.application.name=back -eureka.client.register-with-eureka=true -eureka.client.fetch-registry=true - -spring.jpa.database=postgresql -spring.jpa.hibernate.ddl-auto=none -spring.jpa.show-sql=true - -spring.datasource.driver-class-name=org.postgresql.Driver \ No newline at end of file +spring.profiles.active=${SPRING_PROFILES_ACTIVE:dev} \ No newline at end of file diff --git a/src/test/java/com/cantech/batch/batch_service/BatchServiceApplicationTests.java b/src/test/java/com/cantech/batch/batch_service/BatchServiceApplicationTests.java index 975f75a..ae55572 100644 --- a/src/test/java/com/cantech/batch/batch_service/BatchServiceApplicationTests.java +++ b/src/test/java/com/cantech/batch/batch_service/BatchServiceApplicationTests.java @@ -2,8 +2,10 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; @SpringBootTest +@ActiveProfiles("test") class BatchServiceApplicationTests { @Test