-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ 문제 업데이트 Job 개발 * ✨ DataSource 분리 및 ECR 배포코드 작성
- Loading branch information
Showing
34 changed files
with
1,516 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: cicd-dev | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
|
||
env: | ||
AWS_REGION: ap-northeast-2 | ||
ECR_REPOSITORY: new_morandi_batch | ||
ECR_REGISTRY: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com/new_morandi_backend | ||
GITHUB_SHA: ${{ github.sha }} | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
# Gradle 빌드를 추가합니다. | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'adopt' | ||
java-version: '17' | ||
|
||
- name: Cleanup application.yml | ||
run: rm -f src/main/resources/application.yml | ||
|
||
# GitHub Secret에서 application-prod.yml 내용을 불러와 파일로 저장 | ||
- name: Create application.yml from GitHub Secret | ||
run: | | ||
mkdir -p src/main/resources | ||
echo "${{ secrets.DEV_APPLICATION_YML }}" > src/main/resources/application.yml | ||
- name: Build with Gradle | ||
env: | ||
ORG_GRADLE_OPTS: "-Duser.timezone=Asia/Seoul" | ||
run: ./gradlew clean bootJar -x test | ||
|
||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.ECR_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.ECR_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
mask-aws-account-id: true | ||
|
||
- name: Login to Private ECR | ||
run: aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ env.ECR_REGISTRY }} | ||
|
||
- name: Build Docker Image | ||
run: docker build -t ${{ env.ECR_REGISTRY }}:${{ github.sha }} . | ||
|
||
- name: Push Docker Image to ECR | ||
run: docker push ${{ env.ECR_REGISTRY }}:${{ github.sha }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/Users/miiiinju/NewMorandi-Batch/morandi-batch/src/main/resources/application.yml | ||
|
||
HELP.md | ||
.gradle | ||
build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM openjdk:17-oracle | ||
WORKDIR /app | ||
COPY build/libs/*.jar app.jar | ||
ENTRYPOINT ["java", "-jar", "app.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 25 additions & 39 deletions
64
src/main/java/kr/co/morandi_batch/batch/config/DataSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,41 @@ | ||
package kr.co.morandi_batch.batch.config; | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.batch.BatchDataSource; | ||
import org.springframework.boot.jdbc.DataSourceBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
import org.springframework.jdbc.datasource.DataSourceTransactionManager; | ||
import org.springframework.orm.jpa.JpaTransactionManager; | ||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; | ||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; | ||
|
||
import javax.sql.DataSource; | ||
|
||
@Configuration | ||
@EnableJpaRepositories( | ||
basePackages = "kr.co.morandi_batch.domain", | ||
entityManagerFactoryRef = "businessEntityManager", | ||
transactionManagerRef = "businessTransactionManager" | ||
) | ||
public class DataSourceConfig { | ||
|
||
@Bean | ||
@Primary | ||
public LocalContainerEntityManagerFactoryBean businessEntityManager() { | ||
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); | ||
|
||
em.setDataSource(businessDataSource()); | ||
em.setPackagesToScan("kr.co.morandi_batch.domain"); | ||
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); | ||
|
||
return em; | ||
} | ||
|
||
@Primary | ||
@Bean(name = "businessDataSource") | ||
@ConfigurationProperties(prefix = "spring.datasource.business") | ||
public DataSource businessDataSource() { | ||
return DataSourceBuilder.create().build(); | ||
@Bean(name = "batchDataSource") | ||
@BatchDataSource | ||
public DataSource H2Datasource () { | ||
return new EmbeddedDatabaseBuilder() | ||
.addScript("classpath:org/springframework/batch/core/schema-drop-h2.sql") | ||
.addScript("classpath:org/springframework/batch/core/schema-h2.sql") | ||
.setType(EmbeddedDatabaseType.H2) | ||
.build(); | ||
} | ||
|
||
@Primary | ||
@Bean(name = "businessTransactionManager") | ||
public PlatformTransactionManager businessTransactionManager() { | ||
JpaTransactionManager transactionManager = new JpaTransactionManager(); | ||
|
||
transactionManager.setEntityManagerFactory(businessEntityManager().getObject()); | ||
|
||
return transactionManager; | ||
@Bean | ||
@Primary // 이 DataSource를 애플리케이션의 주 데이터 소스로 지정 | ||
public DataSource dataSource(@Value("${spring.datasource.driver-class-name}") String driverClassName, | ||
@Value("${spring.datasource.url}") String url, | ||
@Value("${spring.datasource.username}") String user, | ||
@Value("${spring.datasource.password}") String pass) { | ||
return DataSourceBuilder.create() | ||
.driverClassName(driverClassName) | ||
.url(url) | ||
.username(user) | ||
.password(pass) | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
src/main/java/kr/co/morandi_batch/batch/dto/response/BojAlgorithmTag.java
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/main/java/kr/co/morandi_batch/batch/dto/response/BojProblemInfo.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/main/java/kr/co/morandi_batch/batch/dto/response/BojProblemInfoList.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/main/java/kr/co/morandi_batch/batch/dto/response/TagDTO.java
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
src/main/java/kr/co/morandi_batch/batch/dto/response/TitleDTO.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.