From 12486bcaf52dbbbfb71f1a9257b7d94cec7687cd Mon Sep 17 00:00:00 2001 From: bongsh0112 Date: Sat, 2 Sep 2023 01:49:30 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20jenkins=20=EC=97=B0=EA=B2=B0=ED=95=98?= =?UTF-8?q?=EC=97=AC=20batch=20=EA=B5=AC=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/batch-deploy.yml | 33 +++++++++++++++++++ .github/workflows/ci.yml | 1 + Batch/Dockerfile | 7 ++++ .../tify/server/job/CrawlingJobConfig.java | 28 +++++++++++----- ...bParameter.java => CrawlJobParameter.java} | 4 +-- Batch/src/main/resources/application.yml | 28 ++++++++++++++++ 6 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/batch-deploy.yml create mode 100644 Batch/Dockerfile rename Batch/src/main/java/tify/server/job/parameter/{OliveYoungCrawlJobParameter.java => CrawlJobParameter.java} (89%) create mode 100644 Batch/src/main/resources/application.yml diff --git a/.github/workflows/batch-deploy.yml b/.github/workflows/batch-deploy.yml new file mode 100644 index 00000000..8ac7a168 --- /dev/null +++ b/.github/workflows/batch-deploy.yml @@ -0,0 +1,33 @@ +name: Build Batch Server +on: + push: + branches: [ "feat/36-batch" ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + java-version: [ 17 ] + + steps: + - name: Check Out The Repository + uses: actions/checkout@v3 + + - name: Set up Java + uses: actions/setup-java@v3 + with: + java-version: ${{ matrix.java-version }} + distribution: 'corretto' + + - name: Gradle Build + uses: gradle/gradle-build-action@v2 + + - name: Execute Gradle build + run: ./gradlew :Batch:build --no-daemon + + - name: Docker build + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_BATCH_REPO }} . + docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_BATCH_REPO }}:latest diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92876daa..2b58777e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,3 +1,4 @@ + name: TIFY Build on: diff --git a/Batch/Dockerfile b/Batch/Dockerfile new file mode 100644 index 00000000..171da7dd --- /dev/null +++ b/Batch/Dockerfile @@ -0,0 +1,7 @@ +FROM amazoncorretto:17 +ARG JAR_FILE=./Api/build/libs/Api.jar +COPY ${JAR_FILE} app.jar + +ARG PROFILE=dev +ENV PROFILE=${PROFILE} +ENTRYPOINT ["java","-Dspring.profiles.active=${PROFILE}", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] diff --git a/Batch/src/main/java/tify/server/job/CrawlingJobConfig.java b/Batch/src/main/java/tify/server/job/CrawlingJobConfig.java index 6106e118..68c600d1 100644 --- a/Batch/src/main/java/tify/server/job/CrawlingJobConfig.java +++ b/Batch/src/main/java/tify/server/job/CrawlingJobConfig.java @@ -7,14 +7,16 @@ import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; +import org.springframework.batch.core.configuration.annotation.JobScope; import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.repeat.RepeatStatus; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import tify.server.domain.domains.product.adaptor.ProductAdaptor; import tify.server.domain.domains.product.domain.Product; import tify.server.infrastructure.outer.crawling.OliveYoungCrawl; -import tify.server.job.parameter.OliveYoungCrawlJobParameter; +import tify.server.job.parameter.CrawlJobParameter; @Slf4j @Configuration @@ -26,23 +28,31 @@ public class CrawlingJobConfig { private final ProductAdaptor productAdaptor; private final OliveYoungCrawl oliveYoungCrawl; - @Bean - public OliveYoungCrawlJobParameter oliveYoungCrawlJobParameter() { - return new OliveYoungCrawlJobParameter(productAdaptor); + private static final String JOB_NAME = "크롤링"; + private static final String BEAN_PREFIX = JOB_NAME + "_"; + + @Bean(BEAN_PREFIX + "crawlJobParameter") + @JobScope + public CrawlJobParameter crawlJobParameter() { + return new CrawlJobParameter(productAdaptor); } - @Bean - public Job oliveYoungJob() { - return jobBuilderFactory.get("oliveYoungJob").start(step()).build(); + @Qualifier(BEAN_PREFIX + "crawlJobParameter") + private final CrawlJobParameter crawlJobParameter; + + @Bean(JOB_NAME) + public Job crawlJob() { + return jobBuilderFactory.get(JOB_NAME).preventRestart().start(step()).build(); } - @Bean + @Bean(BEAN_PREFIX + "step") + @JobScope public Step step() { return stepBuilderFactory .get("step") .tasklet( (contribution, chunkContext) -> { - List products = oliveYoungCrawlJobParameter().getProducts(); + List products = crawlJobParameter().getProducts(); products.forEach( product -> { product.updateImageUrl( diff --git a/Batch/src/main/java/tify/server/job/parameter/OliveYoungCrawlJobParameter.java b/Batch/src/main/java/tify/server/job/parameter/CrawlJobParameter.java similarity index 89% rename from Batch/src/main/java/tify/server/job/parameter/OliveYoungCrawlJobParameter.java rename to Batch/src/main/java/tify/server/job/parameter/CrawlJobParameter.java index a03f7e55..9946c8f8 100644 --- a/Batch/src/main/java/tify/server/job/parameter/OliveYoungCrawlJobParameter.java +++ b/Batch/src/main/java/tify/server/job/parameter/CrawlJobParameter.java @@ -12,9 +12,9 @@ import tify.server.domain.domains.product.domain.Site; @Getter -public class OliveYoungCrawlJobParameter { +public class CrawlJobParameter { - public OliveYoungCrawlJobParameter(ProductAdaptor productAdaptor) { + public CrawlJobParameter(ProductAdaptor productAdaptor) { this.productAdaptor = productAdaptor; } diff --git a/Batch/src/main/resources/application.yml b/Batch/src/main/resources/application.yml new file mode 100644 index 00000000..4b2e1ec7 --- /dev/null +++ b/Batch/src/main/resources/application.yml @@ -0,0 +1,28 @@ +# commons +spring: + profiles: + include: + - infrastructure + - domain + - core + batch.job.names: ${job.name:NONE} + +--- +spring: + config: + activate: + on-profile: dev + +#logging: +# level: +# root: info +#logging: +# level: +# org.springframework.data.*.*: debug +# org.springframework.cache.*: debug + +--- +spring: + config: + activate: + on-profile: prod