From 0258f8d1a0baf74c3edba409d5cf06099e0cf16a Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Tue, 3 Dec 2024 06:25:18 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fingerprint=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EB=8F=99=EC=9E=91=20=EB=B9=84=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../sulmun2yong/ai/service/GenerateService.kt | 5 +- .../global/util/FakeFingerprintApi.kt | 30 ----------- .../sulmun2yong/global/util/FingerprintApi.kt | 54 ------------------- .../FakeSurveyResponseController.kt | 27 ---------- .../doc/FakeSurveyResponseApiDoc.kt | 22 -------- .../service/FakeSurveyResponseService.kt | 49 ----------------- .../survey/service/SurveyResponseService.kt | 5 +- 8 files changed, 5 insertions(+), 189 deletions(-) delete mode 100644 src/main/kotlin/com/sbl/sulmun2yong/global/util/FakeFingerprintApi.kt delete mode 100644 src/main/kotlin/com/sbl/sulmun2yong/global/util/FingerprintApi.kt delete mode 100644 src/main/kotlin/com/sbl/sulmun2yong/survey/controller/FakeSurveyResponseController.kt delete mode 100644 src/main/kotlin/com/sbl/sulmun2yong/survey/controller/doc/FakeSurveyResponseApiDoc.kt delete mode 100644 src/main/kotlin/com/sbl/sulmun2yong/survey/service/FakeSurveyResponseService.kt diff --git a/build.gradle.kts b/build.gradle.kts index 52bfdbfa..0dab27c4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -36,7 +36,7 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-actuator") // fingerprint - implementation("com.github.fingerprintjs:fingerprint-pro-server-api-java-sdk:v6.0.0") + // implementation("com.github.fingerprintjs:fingerprint-pro-server-api-java-sdk:v6.0.0") // security implementation("org.springframework.boot:spring-boot-starter-security") diff --git a/src/main/kotlin/com/sbl/sulmun2yong/ai/service/GenerateService.kt b/src/main/kotlin/com/sbl/sulmun2yong/ai/service/GenerateService.kt index 2f33fa25..29cbc5b3 100644 --- a/src/main/kotlin/com/sbl/sulmun2yong/ai/service/GenerateService.kt +++ b/src/main/kotlin/com/sbl/sulmun2yong/ai/service/GenerateService.kt @@ -7,7 +7,6 @@ import com.sbl.sulmun2yong.ai.domain.AIGenerateLog import com.sbl.sulmun2yong.ai.dto.request.DemoSurveyGenerationWithFileUrlRequest import com.sbl.sulmun2yong.ai.dto.request.SurveyGenerationWithFileUrlRequest import com.sbl.sulmun2yong.ai.dto.response.AISurveyGenerationResponse -import com.sbl.sulmun2yong.global.fingerprint.FingerprintApi import com.sbl.sulmun2yong.global.util.validator.FileUrlValidator import com.sbl.sulmun2yong.survey.adapter.SurveyAdapter import com.sbl.sulmun2yong.survey.domain.Survey @@ -21,7 +20,7 @@ class GenerateService( private val surveyAdapter: SurveyAdapter, private val aiDemoCountRedisAdapter: AIDemoCountRedisAdapter, private val aiGenerateLogAdapter: AIGenerateLogAdapter, - val fingerprintApi: FingerprintApi, + // val fingerprintApi: FingerprintApi, ) { fun generateSurveyWithFileUrl( surveyGenerationWithFileUrlRequest: SurveyGenerationWithFileUrlRequest, @@ -74,7 +73,7 @@ class GenerateService( val userPrompt = demoSurveyGenerationWithFileUrlRequest.userPrompt validateFileUrl(fileUrl) - fingerprintApi.validateVisitorId(visitorId) + // fingerprintApi.validateVisitorId(visitorId) aiDemoCountRedisAdapter.incrementOrCreate(visitorId) val surveyId = UUID.randomUUID() diff --git a/src/main/kotlin/com/sbl/sulmun2yong/global/util/FakeFingerprintApi.kt b/src/main/kotlin/com/sbl/sulmun2yong/global/util/FakeFingerprintApi.kt deleted file mode 100644 index 551aa80e..00000000 --- a/src/main/kotlin/com/sbl/sulmun2yong/global/util/FakeFingerprintApi.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.sbl.sulmun2yong.global.util - -import jakarta.ws.rs.client.Client -import jakarta.ws.rs.client.ClientBuilder -import jakarta.ws.rs.client.Invocation -import jakarta.ws.rs.core.MediaType -import jakarta.ws.rs.core.Response -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.stereotype.Component - -@ConditionalOnProperty(prefix = "fingerprint", name = ["mocking-server-url"], matchIfMissing = false) -@Component -class FakeFingerprintApi( - @Value("\${fingerprint.mocking-server-url}") - private val mockingServerUrl: String, -) { - private val url = "$mockingServerUrl/finger-print" - private val client: Client = ClientBuilder.newClient() - - fun callFingerPrintApi(visitorId: String) { - val target = client.target(url) - val invocationBuilder: Invocation.Builder = target.request(MediaType.APPLICATION_JSON_TYPE) - val response: Response = invocationBuilder.get() - - if (response.status != Response.Status.OK.statusCode) { - throw IllegalStateException("Fake 핑거프린트 API를 호출할 수 없습니다.") - } - } -} diff --git a/src/main/kotlin/com/sbl/sulmun2yong/global/util/FingerprintApi.kt b/src/main/kotlin/com/sbl/sulmun2yong/global/util/FingerprintApi.kt deleted file mode 100644 index 014aa85a..00000000 --- a/src/main/kotlin/com/sbl/sulmun2yong/global/util/FingerprintApi.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.sbl.sulmun2yong.global.fingerprint - -import com.fingerprint.api.FingerprintApi -import com.fingerprint.model.BotdDetectionResult -import com.fingerprint.model.EventResponse -import com.fingerprint.model.ProductsResponse -import com.fingerprint.model.Response -import com.fingerprint.model.ResponseVisits -import com.fingerprint.sdk.ApiClient -import com.fingerprint.sdk.Configuration -import com.fingerprint.sdk.Region -import com.sbl.sulmun2yong.global.util.exception.UncleanVisitorException -import org.springframework.beans.factory.annotation.Value -import org.springframework.stereotype.Component - -@Component -class FingerprintApi( - @Value("\${fingerprint.secret-key}") - private val secretKey: String, -) { - private val client: ApiClient = - Configuration.getDefaultApiClient( - secretKey, - Region.ASIA, - ) - val api = FingerprintApi(client) - - fun validateVisitorId(visitorId: String) { - val visits = getVisits(visitorId) - if (visits.isNullOrEmpty()) { - throw Exception("Invalid visitorId") - } - checkIsVisitorClean(visits) - } - - private fun getVisits(visitorId: String): MutableList? { - val response: Response = api.getVisits(visitorId, null, null, 1, null, null) - return response.visits - } - - private fun getEvent(requestId: String): ProductsResponse { - val response: EventResponse = api.getEvent(requestId) - return response.products - } - - private fun checkIsVisitorClean(visits: MutableList) { - val product = getEvent(visits[0].requestId) - if (product.tampering.data.result == true || - product.botd.data.bot.result !== BotdDetectionResult.ResultEnum.NOT_DETECTED - ) { - throw UncleanVisitorException() - } - } -} diff --git a/src/main/kotlin/com/sbl/sulmun2yong/survey/controller/FakeSurveyResponseController.kt b/src/main/kotlin/com/sbl/sulmun2yong/survey/controller/FakeSurveyResponseController.kt deleted file mode 100644 index 8cbdf52a..00000000 --- a/src/main/kotlin/com/sbl/sulmun2yong/survey/controller/FakeSurveyResponseController.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.sbl.sulmun2yong.survey.controller - -import com.sbl.sulmun2yong.survey.controller.doc.FakeSurveyResponseApiDoc -import com.sbl.sulmun2yong.survey.dto.request.SurveyResponseRequest -import com.sbl.sulmun2yong.survey.service.FakeSurveyResponseService -import jakarta.validation.Valid -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController -import java.util.UUID - -@ConditionalOnProperty(prefix = "fingerprint", name = ["mocking-server-url"], matchIfMissing = false) -@RestController -@RequestMapping("/api/v1/surveys/response/fake") -class FakeSurveyResponseController( - private val fakeSurveyResponseService: FakeSurveyResponseService, -) : FakeSurveyResponseApiDoc { - @PostMapping("/{survey-id}") - override fun fakeResponseToSurvey( - @PathVariable("survey-id") surveyId: UUID, - @Valid @RequestBody surveyResponseRequest: SurveyResponseRequest, - ) = ResponseEntity.ok(fakeSurveyResponseService.fakeResponseToSurvey(surveyId, surveyResponseRequest)) -} diff --git a/src/main/kotlin/com/sbl/sulmun2yong/survey/controller/doc/FakeSurveyResponseApiDoc.kt b/src/main/kotlin/com/sbl/sulmun2yong/survey/controller/doc/FakeSurveyResponseApiDoc.kt deleted file mode 100644 index d23f5869..00000000 --- a/src/main/kotlin/com/sbl/sulmun2yong/survey/controller/doc/FakeSurveyResponseApiDoc.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.sbl.sulmun2yong.survey.controller.doc - -import com.sbl.sulmun2yong.survey.dto.request.SurveyResponseRequest -import com.sbl.sulmun2yong.survey.dto.response.SurveyParticipantResponse -import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.tags.Tag -import jakarta.validation.Valid -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import java.util.UUID - -@Tag(name = "FakeSurveyResponse", description = "테스트용 설문 응답 관련 API") -interface FakeSurveyResponseApiDoc { - @Operation(summary = "Fingerprint Mocking 서버를 사용하는 설문 응답 API") - @PostMapping - fun fakeResponseToSurvey( - @PathVariable("survey-id") surveyId: UUID, - @Valid @RequestBody surveyResponseRequest: SurveyResponseRequest, - ): ResponseEntity -} diff --git a/src/main/kotlin/com/sbl/sulmun2yong/survey/service/FakeSurveyResponseService.kt b/src/main/kotlin/com/sbl/sulmun2yong/survey/service/FakeSurveyResponseService.kt deleted file mode 100644 index 62720e24..00000000 --- a/src/main/kotlin/com/sbl/sulmun2yong/survey/service/FakeSurveyResponseService.kt +++ /dev/null @@ -1,49 +0,0 @@ -package com.sbl.sulmun2yong.survey.service - -import com.sbl.sulmun2yong.global.util.FakeFingerprintApi -import com.sbl.sulmun2yong.survey.adapter.ParticipantAdapter -import com.sbl.sulmun2yong.survey.adapter.ResponseAdapter -import com.sbl.sulmun2yong.survey.adapter.SurveyAdapter -import com.sbl.sulmun2yong.survey.domain.Participant -import com.sbl.sulmun2yong.survey.dto.request.SurveyResponseRequest -import com.sbl.sulmun2yong.survey.dto.response.SurveyParticipantResponse -import com.sbl.sulmun2yong.survey.exception.AlreadyParticipatedException -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.stereotype.Service -import java.util.UUID - -@ConditionalOnProperty(prefix = "fingerprint", name = ["mocking-server-url"], matchIfMissing = false) -@Service -class FakeSurveyResponseService( - val surveyAdapter: SurveyAdapter, - val participantAdapter: ParticipantAdapter, - val responseAdapter: ResponseAdapter, - val fakeFingerprintApi: FakeFingerprintApi, -) { - fun fakeResponseToSurvey( - surveyId: UUID, - surveyResponseRequest: SurveyResponseRequest, - ): SurveyParticipantResponse { - validateIsAlreadyParticipated(surveyId, surveyResponseRequest.visitorId) - // 가짜 Fingerprint API를 호출하는 부분을 제외하고는 SurveyResponseService responseToSurvey 동일 - fakeFingerprintApi.callFingerPrintApi(surveyResponseRequest.visitorId) - val visitorId = surveyResponseRequest.visitorId - val survey = surveyAdapter.getSurvey(surveyId) - val surveyResponse = surveyResponseRequest.toDomain(surveyId) - survey.validateResponse(surveyResponse) - val participant = Participant.create(visitorId, surveyId, null) - participantAdapter.insert(participant) - responseAdapter.insertSurveyResponse(surveyResponse, participant.id) - return SurveyParticipantResponse(participant.id, survey.isImmediateDraw()) - } - - private fun validateIsAlreadyParticipated( - surveyId: UUID, - visitorId: String, - ) { - val participant = participantAdapter.findBySurveyIdAndVisitorId(surveyId, visitorId) - participant?.let { - throw AlreadyParticipatedException() - } - } -} diff --git a/src/main/kotlin/com/sbl/sulmun2yong/survey/service/SurveyResponseService.kt b/src/main/kotlin/com/sbl/sulmun2yong/survey/service/SurveyResponseService.kt index 975e5158..52da5442 100644 --- a/src/main/kotlin/com/sbl/sulmun2yong/survey/service/SurveyResponseService.kt +++ b/src/main/kotlin/com/sbl/sulmun2yong/survey/service/SurveyResponseService.kt @@ -1,6 +1,5 @@ package com.sbl.sulmun2yong.survey.service -import com.sbl.sulmun2yong.global.fingerprint.FingerprintApi import com.sbl.sulmun2yong.survey.adapter.ParticipantAdapter import com.sbl.sulmun2yong.survey.adapter.ResponseAdapter import com.sbl.sulmun2yong.survey.adapter.SurveyAdapter @@ -16,7 +15,7 @@ class SurveyResponseService( val surveyAdapter: SurveyAdapter, val participantAdapter: ParticipantAdapter, val responseAdapter: ResponseAdapter, - val fingerprintApi: FingerprintApi, + // val fingerprintApi: FingerprintApi, ) { // TODO: 트랜잭션 처리 추가하기 fun responseToSurvey( @@ -24,7 +23,7 @@ class SurveyResponseService( surveyResponseRequest: SurveyResponseRequest, ): SurveyParticipantResponse { validateIsAlreadyParticipated(surveyId, surveyResponseRequest.visitorId) - fingerprintApi.validateVisitorId(surveyResponseRequest.visitorId) + // fingerprintApi.validateVisitorId(surveyResponseRequest.visitorId) val visitorId = surveyResponseRequest.visitorId val survey = surveyAdapter.getSurvey(surveyId) val surveyResponse = surveyResponseRequest.toDomain(surveyId) From d8f616ebb88eef13c7f5dd1186d6617591f85885 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Tue, 3 Dec 2024 06:26:02 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=EA=B0=9C=EB=B0=9C=20=EC=84=9C=EB=B2=84=20?= =?UTF-8?q?=EB=B0=B0=ED=8F=AC=20=EC=9E=91=EC=97=85=20=EB=B9=84=ED=99=9C?= =?UTF-8?q?=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev_deploy.yml | 92 ++++++++++++++++---------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/.github/workflows/dev_deploy.yml b/.github/workflows/dev_deploy.yml index 32ec00c2..c3085de5 100644 --- a/.github/workflows/dev_deploy.yml +++ b/.github/workflows/dev_deploy.yml @@ -57,49 +57,49 @@ jobs: - name: Jib로 Docker 이미지 빌드 및 푸시 run: ./gradlew jib -Ddocker.id="${{ env.DOCKER_ID }}" -Ddocker.password="${{ env.DOCKER_PASSWORD }}" -Ddocker.image.name="${{ env.DOCKER_IMAGE_NAME }}" - deploy: - name: 개발 서버 배포 작업 - needs: build - runs-on: ubuntu-latest - - env: - # AWS 관련 - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - EC2_INSTANCE_ID: ${{ secrets.DEVELOP_EC2_INSTANCE_ID }} - AWS_REGION: ap-northeast-2 - # Docker 관련 - CONTAINER_NAME: sulmun2yong-develop-server - DOCKER_ID: ${{ secrets.DOCKER_ID }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - DOCKER_IMAGE_NAME: ${{ secrets.DOCKER_BACKEND_IMAGE_NAME }}:devLatest - # MongoDB 관련 - MONGODB_URL: ${{ secrets.DEVELOP_MONGODB_URL }} - MONGODB_DATABASE: ${{ secrets.DEVELOP_MONGODB_DATABASE }} - # Spring Boot 관련 - FRONTEND_BASE_URL: http://localhost:3000 - BACKEND_BASE_URL: https://dev-api.sulmoon.io - AI_SERVER_BASE_URL: http://ai.sulmoon.io:8000 - FINGERPRINT_MOCKING_SERVER_URL: ${{ secrets.FINGERPRINT_MOCKING_SERVER_URL }} - # New Relic 관련 - NEW_RELIC_APP_NAME: sulmun2yong-development - - steps: - - name: AWS 로그인 - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ env.AWS_REGION }} - - - name: SSM으로 EC2에 배포 - run: | - aws --no-cli-pager ssm send-command \ - --document-name "AWS-RunShellScript" \ - --targets "Key=instanceIds, Values=${{ env.EC2_INSTANCE_ID }}" \ - --parameters '{"commands" : ["echo \"${{ env.DOCKER_PASSWORD }}\" | docker login -u \"${{ env.DOCKER_ID }}\" --password-stdin", - "docker pull ${{ env.DOCKER_ID }}/${{ env.DOCKER_IMAGE_NAME }}", - "docker stop ${{ env.CONTAINER_NAME }} || true", - "docker rm ${{ env.CONTAINER_NAME }} || true", - "docker run -d --name ${{ env.CONTAINER_NAME }} -p 8080:8080 -e SPRING_DATA_MONGODB_URI=${{ env.MONGODB_URL }} -e SPRING_DATA_MONGODB_DATABASE=${{ env.MONGODB_DATABASE }} -e FRONTEND_BASE-URL=${{ env.FRONTEND_BASE_URL }} -e BACKEND_BASE-URL=${{ env.BACKEND_BASE_URL }} -e AI-SERVER_BASE-URL=${{ env.AI_SERVER_BASE_URL }} -e NEW_RELIC_APP_NAME=${{ env.NEW_RELIC_APP_NAME }} -e FINGERPRINT_MOCKING_SERVER_URL=${{ env.FINGERPRINT_MOCKING_SERVER_URL }} ${{ env.DOCKER_ID }}/${{ env.DOCKER_IMAGE_NAME }}", - "docker image prune -af"]}' +# deploy: +# name: 개발 서버 배포 작업 +# needs: build +# runs-on: ubuntu-latest +# +# env: +# # AWS 관련 +# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} +# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} +# EC2_INSTANCE_ID: ${{ secrets.DEVELOP_EC2_INSTANCE_ID }} +# AWS_REGION: ap-northeast-2 +# # Docker 관련 +# CONTAINER_NAME: sulmun2yong-develop-server +# DOCKER_ID: ${{ secrets.DOCKER_ID }} +# DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} +# DOCKER_IMAGE_NAME: ${{ secrets.DOCKER_BACKEND_IMAGE_NAME }}:devLatest +# # MongoDB 관련 +# MONGODB_URL: ${{ secrets.DEVELOP_MONGODB_URL }} +# MONGODB_DATABASE: ${{ secrets.DEVELOP_MONGODB_DATABASE }} +# # Spring Boot 관련 +# FRONTEND_BASE_URL: http://localhost:3000 +# BACKEND_BASE_URL: https://dev-api.sulmoon.io +# AI_SERVER_BASE_URL: http://ai.sulmoon.io:8000 +# FINGERPRINT_MOCKING_SERVER_URL: ${{ secrets.FINGERPRINT_MOCKING_SERVER_URL }} +# # New Relic 관련 +# NEW_RELIC_APP_NAME: sulmun2yong-development +# +# steps: +# - name: AWS 로그인 +# uses: aws-actions/configure-aws-credentials@v4 +# with: +# aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} +# aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} +# aws-region: ${{ env.AWS_REGION }} +# +# - name: SSM으로 EC2에 배포 +# run: | +# aws --no-cli-pager ssm send-command \ +# --document-name "AWS-RunShellScript" \ +# --targets "Key=instanceIds, Values=${{ env.EC2_INSTANCE_ID }}" \ +# --parameters '{"commands" : ["echo \"${{ env.DOCKER_PASSWORD }}\" | docker login -u \"${{ env.DOCKER_ID }}\" --password-stdin", +# "docker pull ${{ env.DOCKER_ID }}/${{ env.DOCKER_IMAGE_NAME }}", +# "docker stop ${{ env.CONTAINER_NAME }} || true", +# "docker rm ${{ env.CONTAINER_NAME }} || true", +# "docker run -d --name ${{ env.CONTAINER_NAME }} -p 8080:8080 -e SPRING_DATA_MONGODB_URI=${{ env.MONGODB_URL }} -e SPRING_DATA_MONGODB_DATABASE=${{ env.MONGODB_DATABASE }} -e FRONTEND_BASE-URL=${{ env.FRONTEND_BASE_URL }} -e BACKEND_BASE-URL=${{ env.BACKEND_BASE_URL }} -e AI-SERVER_BASE-URL=${{ env.AI_SERVER_BASE_URL }} -e NEW_RELIC_APP_NAME=${{ env.NEW_RELIC_APP_NAME }} -e FINGERPRINT_MOCKING_SERVER_URL=${{ env.FINGERPRINT_MOCKING_SERVER_URL }} ${{ env.DOCKER_ID }}/${{ env.DOCKER_IMAGE_NAME }}", +# "docker image prune -af"]}' From ca40066425a267c432eac589d2c927f64cf7cc5e Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Tue, 3 Dec 2024 06:27:02 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=ED=94=84=EB=A1=9C=EB=8D=95=EC=85=98=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=20=EB=B0=B0=ED=8F=AC=20=EC=8B=9C=20SSM=20?= =?UTF-8?q?=EB=8C=80=EC=8B=A0=20SSH=20=EC=A0=91=EC=86=8D=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/prod_deploy.yml | 70 +++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/.github/workflows/prod_deploy.yml b/.github/workflows/prod_deploy.yml index 4eeeec53..c45d5473 100644 --- a/.github/workflows/prod_deploy.yml +++ b/.github/workflows/prod_deploy.yml @@ -70,10 +70,14 @@ jobs: env: # AWS 관련 - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - EC2_INSTANCE_ID: ${{ secrets.PRODUCTION_EC2_INSTANCE_ID }} - AWS_REGION: ap-northeast-2 + # AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + # AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # EC2_INSTANCE_ID: ${{ secrets.PRODUCTION_EC2_INSTANCE_ID }} + # AWS_REGION: ap-northeast-2 + EC2_HOST: ${{ secrets.PRODUCTION_EC2_HOST }} + EC2_USER: ${{ secrets.EC2_USER }} + EC2_KEY: ${{ secrets.EC2_KEY }} + # Docker 관련 CONTAINER_NAME: sulmun2yong-production-server DOCKER_ID: ${{ secrets.DOCKER_ID }} @@ -87,23 +91,45 @@ jobs: BACKEND_BASE_URL: https://api.sulmoon.io AI_SERVER_BASE_URL: http://ai.sulmoon.io:8000 - steps: - - name: AWS 로그인 - uses: aws-actions/configure-aws-credentials@v4 + - name: EC2에 배포 + uses: appleboy/ssh-action@v0.1.7 with: - aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ env.AWS_REGION }} - - - name: SSM으로 EC2에 배포 - run: | - aws --no-cli-pager ssm send-command \ - --document-name "AWS-RunShellScript" \ - --targets "Key=instanceIds, Values=${{ env.EC2_INSTANCE_ID}}" \ - --parameters '{"commands" : ["echo \"${{ env.DOCKER_PASSWORD }}\" | docker login -u \"${{ env.DOCKER_ID }}\" --password-stdin", - "docker pull ${{ env.DOCKER_ID }}/${{ env.DOCKER_IMAGE_NAME }}", - "docker stop ${{ env.CONTAINER_NAME }} || true", - "docker rm ${{ env.CONTAINER_NAME }} || true", - "docker run -d --name ${{ env.CONTAINER_NAME }} -p 8080:8080 -e SPRING_DATA_MONGODB_URI=${{ env.MONGODB_URL }} -e SPRING_DATA_MONGODB_DATABASE=${{ env.MONGODB_DATABASE }} -e FRONTEND_BASE-URL=${{ env.FRONTEND_BASE_URL }} -e BACKEND_BASE-URL=${{ env.BACKEND_BASE_URL }} -e AI-SERVER_BASE-URL=${{ env.AI_SERVER_BASE_URL }} -e COOKIE_DOMAIN=${{ env.COOKIE_DOMAIN }} ${{ env.DOCKER_ID }}/${{ env.DOCKER_IMAGE_NAME }}", - "docker image prune -af"]}' + host: ${{ env.EC2_HOST }} + username: ${{ env.EC2_USER }} + key: ${{ env.EC2_KEY }} + debug: true + script: | + echo "${{ env.DOCKER_PASSWORD }}" | docker login -u "${{ env.DOCKER_ID }}" --password-stdin + docker pull ${{ env.DOCKER_ID }}/${{ env.DOCKER_IMAGE_NAME }} + docker stop ${{ env.CONTAINER_NAME }} || true + docker rm ${{ env.CONTAINER_NAME }} || true + docker run -d --name ${{ env.CONTAINER_NAME }} -p 8080:8080 \ + -e SPRING_DATA_MONGODB_URI=${{ env.MONGODB_URL }} \ + -e SPRING_DATA_MONGODB_DATABASE=${{ env.MONGODB_DATABASE }} \ + -e FRONTEND_BASE-URL=${{ env.FRONTEND_BASE_URL }} \ + -e BACKEND_BASE-URL=${{ env.BACKEND_BASE_URL }} \ + -e AI-SERVER_BASE-URL=${{ env.AI_SERVER_BASE_URL }} \ + -e COOKIE_DOMAIN=${{ env.COOKIE_DOMAIN }} \ + ${{ env.DOCKER_ID }}/${{ env.DOCKER_IMAGE_NAME }} + docker image prune -af + +# steps: +# - name: AWS 로그인 +# uses: aws-actions/configure-aws-credentials@v4 +# with: +# aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} +# aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} +# aws-region: ${{ env.AWS_REGION }} +# +# - name: SSM으로 EC2에 배포 +# run: | +# aws --no-cli-pager ssm send-command \ +# --document-name "AWS-RunShellScript" \ +# --targets "Key=instanceIds, Values=${{ env.EC2_INSTANCE_ID}}" \ +# --parameters '{"commands" : ["echo \"${{ env.DOCKER_PASSWORD }}\" | docker login -u \"${{ env.DOCKER_ID }}\" --password-stdin", +# "docker pull ${{ env.DOCKER_ID }}/${{ env.DOCKER_IMAGE_NAME }}", +# "docker stop ${{ env.CONTAINER_NAME }} || true", +# "docker rm ${{ env.CONTAINER_NAME }} || true", +# "docker run -d --name ${{ env.CONTAINER_NAME }} -p 8080:8080 -e SPRING_DATA_MONGODB_URI=${{ env.MONGODB_URL }} -e SPRING_DATA_MONGODB_DATABASE=${{ env.MONGODB_DATABASE }} -e FRONTEND_BASE-URL=${{ env.FRONTEND_BASE_URL }} -e BACKEND_BASE-URL=${{ env.BACKEND_BASE_URL }} -e AI-SERVER_BASE-URL=${{ env.AI_SERVER_BASE_URL }} -e COOKIE_DOMAIN=${{ env.COOKIE_DOMAIN }} ${{ env.DOCKER_ID }}/${{ env.DOCKER_IMAGE_NAME }}", +# "docker image prune -af"]}'