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