-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: 배치서버 세팅 * chore: 배치 ci/cd 설정 * chore: 배치 ci/cd 설정 * chore: 배치 ci/cd 설정 * chore: 배치 ci/cd 설정 * chore: Dockerfile 포트 수정 * chore: batch 서버 정보 수정 * chore: batch 서버 정보 수정 * chore: 수정사항 있을때 배포되도록 옵션 추가
- Loading branch information
Showing
6 changed files
with
167 additions
and
0 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,93 @@ | ||
name: batch deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- feature/#58 | ||
- main | ||
- develop | ||
paths: | ||
- 'adapters/in-batch/**' | ||
|
||
env: | ||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | ||
DOCKERHUB_BATCH_IMAGE: ${{ secrets.DOCKERHUB_BATCH_IMAGE }} | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
kotlin-version: [ "1.9.23" ] | ||
java-version: [ "17" ] | ||
|
||
steps: | ||
- name: Check Out The Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Kotlin | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: ${{ matrix.java-version }} | ||
kotlin-version: ${{ matrix.kotlin-version }} | ||
distribution: 'corretto' | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x ./gradlew | ||
|
||
- name: Create config file | ||
run: | | ||
mkdir -p ./adapters/out-persistence/src/main/resources | ||
echo "${{ secrets.OUT_PERSISTENCE_YML }}" > ./adapters/out-persistence/src/main/resources/application-out-persistence.yml | ||
mkdir -p ./adapters/out-web/src/main/resources | ||
echo "${{ secrets.OUT_WEB_GOOGLE }}" | base64 --decode > ./adapters/out-web/src/main/resources/google-services.json | ||
echo "${{ secrets.OUT_WEB_YML }}" > ./adapters/out-web/src/main/resources/application-out-web.yml | ||
mkdir -p ./application/src/main/resources | ||
echo "${{ secrets.APPLICATION_CORE }}" > ./application/src/main/resources/application-core.yml | ||
- name: Build with Gradle | ||
run: ./gradlew :entry:batch:build --no-daemon | ||
|
||
- name: Docker build and push | ||
run: | | ||
docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_TOKEN | ||
docker build -f entry/batch/Dockerfile -t $DOCKERHUB_USERNAME/$DOCKERHUB_BATCH_IMAGE:latest . | ||
docker push $DOCKERHUB_USERNAME/$DOCKERHUB_BATCH_IMAGE:latest | ||
- name: Get Public IP | ||
id: publicip | ||
run: | | ||
response=$(curl -s canhazip.com) | ||
echo "ip='$response'" >> $GITHUB_OUTPUT | ||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_BATCH_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_BATCH_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ secrets.AWS_REGION }} | ||
|
||
- name: Add GitHub IP to AWS | ||
run: | | ||
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_BATCH_SG_ID }} --protocol tcp --port ${{ secrets.PORT }} --cidr ${{ steps.publicip.outputs.ip }}/32 | ||
- name: executing remote ssh commands using ssh key | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.BATCH_HOST }} | ||
username: ${{ secrets.BATCH_USERNAME }} | ||
key: ${{ secrets.BATCH_KEY }} | ||
port: ${{ secrets.PORT }} | ||
script: | | ||
cd pokit-batch | ||
sudo docker-compose pull | ||
sudo docker-compose down | ||
sudo docker-compose up --force-recreate --remove-orphans -d | ||
sudo docker image prune -f | ||
- name: Remove IP FROM security group | ||
run: | | ||
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_BATCH_SG_ID }} --protocol tcp --port ${{ secrets.PORT }} --cidr ${{ steps.publicip.outputs.ip }}/32 |
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,27 @@ | ||
import org.springframework.boot.gradle.tasks.bundling.BootJar | ||
|
||
plugins { | ||
id("org.springframework.boot") version "3.3.0" | ||
id("io.spring.dependency-management") version "1.1.5" | ||
kotlin("plugin.spring") version "1.9.24" | ||
} | ||
|
||
dependencies { | ||
// 모듈 | ||
implementation(project(":domain")) | ||
implementation(project(":application")) | ||
|
||
// 라이브러리 | ||
implementation("org.springframework.boot:spring-boot-starter-web") | ||
implementation("org.springframework.boot:spring-boot-starter-actuator") | ||
implementation("org.springframework.boot:spring-boot-starter-batch") | ||
|
||
// 테스팅 | ||
testImplementation("io.kotest.extensions:kotest-extensions-spring:1.1.1") | ||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
} | ||
|
||
tasks { | ||
withType<Jar> { enabled = true } | ||
withType<BootJar> { enabled = false } | ||
} |
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,8 @@ | ||
FROM amazoncorretto:17 | ||
|
||
ARG JAR_FILE=entry/batch/build/libs/*.jar | ||
COPY ${JAR_FILE} app.jar | ||
|
||
ENV SERVER_PORT=8081 | ||
|
||
ENTRYPOINT ["java", "-Dserver.port=${SERVER_PORT}", "-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import org.springframework.boot.gradle.tasks.bundling.BootJar | ||
|
||
plugins { | ||
id("org.springframework.boot") version "3.3.0" | ||
id("io.spring.dependency-management") version "1.1.5" | ||
kotlin("plugin.spring") version "1.9.24" | ||
} | ||
|
||
dependencies { | ||
// 모듈 | ||
implementation(project(":adapters:in-batch")) | ||
implementation(project(":adapters:out-persistence")) | ||
implementation(project(":adapters:out-web")) | ||
implementation(project(":domain")) | ||
|
||
// 라이브러리 | ||
implementation("org.springframework.boot:spring-boot-starter-web") | ||
} | ||
|
||
tasks { | ||
withType<Jar> { enabled = false } | ||
withType<BootJar> { enabled = true } | ||
} |
14 changes: 14 additions & 0 deletions
14
entry/batch/src/main/kotlin/com/pokit/batch/BatchApplication.kt
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,14 @@ | ||
package com.pokit.batch | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan | ||
import org.springframework.boot.runApplication | ||
|
||
@SpringBootApplication | ||
@ConfigurationPropertiesScan | ||
class BatchApplication | ||
|
||
fun main(args: Array<String>) { | ||
System.setProperty("spring.config.name", "application-out-web, application-core, application-out-persistence") | ||
runApplication<BatchApplication>(*args) | ||
} |
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