Skip to content

Commit

Permalink
chore: jenkins 연결하여 batch 구동
Browse files Browse the repository at this point in the history
  • Loading branch information
bongsh0112 committed Sep 1, 2023
1 parent e581316 commit 12486bc
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 11 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/batch-deploy.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

name: TIFY Build

on:
Expand Down
7 changes: 7 additions & 0 deletions Batch/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
28 changes: 19 additions & 9 deletions Batch/src/main/java/tify/server/job/CrawlingJobConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Product> products = oliveYoungCrawlJobParameter().getProducts();
List<Product> products = crawlJobParameter().getProducts();
products.forEach(
product -> {
product.updateImageUrl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
28 changes: 28 additions & 0 deletions Batch/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 12486bc

Please sign in to comment.