From 88d4410c5649280955aec45edd78ee0e709284a5 Mon Sep 17 00:00:00 2001 From: JeongInJae <93825184+injae-348@users.noreply.github.com> Date: Thu, 12 Sep 2024 23:30:25 +0900 Subject: [PATCH] =?UTF-8?q?[CHORE]=20=EC=9A=B4=EC=98=81=20=EC=84=9C?= =?UTF-8?q?=EB=B2=84=20github=20actions=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20(#?= =?UTF-8?q?151)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [CHORE] 운영 서버 workflow 작성 및 개발 서버 workflow 파일 이름 변경 (#145) * rename: docker-deploy.yml -> dev-deploy.yml * chore: 운영 환경 workflow 파일 작성 * [FEAT] 로그아웃 HTTP method 변경 (#150) * feat: 로그아웃 비즈니스 예외 구현 * refactor: 로그아웃 method 변경 GET에서 POST로 변경 * config: 프론트 URL 변경 --------- Co-authored-by: 강명덕 <68066437+Profile-exe@users.noreply.github.com> --- .../{docker-deploy.yml => dev-deploy.yml} | 0 .github/workflows/prod-deploy.yml | 46 +++++++++++++++++++ .../auth/controller/AuthController.java | 5 +- .../exception/AlreadyLogoutException.java | 13 ++++++ .../auth/exception/AuthErrorCode.java | 1 + .../econo/buddybridge/config/WebConfig.java | 3 +- 6 files changed, 64 insertions(+), 4 deletions(-) rename .github/workflows/{docker-deploy.yml => dev-deploy.yml} (100%) create mode 100644 .github/workflows/prod-deploy.yml create mode 100644 src/main/java/econo/buddybridge/auth/exception/AlreadyLogoutException.java diff --git a/.github/workflows/docker-deploy.yml b/.github/workflows/dev-deploy.yml similarity index 100% rename from .github/workflows/docker-deploy.yml rename to .github/workflows/dev-deploy.yml diff --git a/.github/workflows/prod-deploy.yml b/.github/workflows/prod-deploy.yml new file mode 100644 index 0000000..c5e897d --- /dev/null +++ b/.github/workflows/prod-deploy.yml @@ -0,0 +1,46 @@ +name: Prod CI/CD + +on: + workflow_dispatch: + push: + branches: [ "production" ] + +permissions: + contents: read + +jobs: + + build: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'corretto' + + - name: Build with Gradle + run: | + chmod +x ./gradlew + ./gradlew clean build -x test + + - name: Build the Docker image + run: | + docker login -u ${{ secrets.PROD_DOCKER_USERNAME }} -p ${{ secrets.PROD_DOCKER_PASSWORD }} + docker build -f Dockerfile -t ${{ secrets.PROD_DOCKER_REPO }} . + docker push ${{ secrets.PROD_DOCKER_REPO }} + + - name: Deploy to server + uses: appleboy/ssh-action@master + id: deploy + with: + host: ${{ secrets.PROD_HOST }} + username: ${{ secrets.PROD_USERNAME }} + key: ${{ secrets.PROD_KEY }} + envs: GITHUB_SHA + script: | + cd ./buddies + bash deploy.sh \ No newline at end of file diff --git a/src/main/java/econo/buddybridge/auth/controller/AuthController.java b/src/main/java/econo/buddybridge/auth/controller/AuthController.java index 7356949..50ac31d 100644 --- a/src/main/java/econo/buddybridge/auth/controller/AuthController.java +++ b/src/main/java/econo/buddybridge/auth/controller/AuthController.java @@ -2,6 +2,7 @@ import econo.buddybridge.auth.OAuthProvider; import econo.buddybridge.auth.dto.kakao.KakaoLoginParams; +import econo.buddybridge.auth.exception.AlreadyLogoutException; import econo.buddybridge.auth.service.OAuthLoginService; import econo.buddybridge.common.annotation.AllowAnonymous; import econo.buddybridge.member.dto.MemberResDto; @@ -39,7 +40,7 @@ public class AuthController { @Operation(summary = "로그아웃", description = "세션을 제거합니다.") @AllowAnonymous - @GetMapping("/logout") + @PostMapping("/logout") public ApiResponse> logout(HttpServletRequest request) { HttpSession session = request.getSession(false); if (session != null) { @@ -47,7 +48,7 @@ public ApiResponse> logout(HttpServletRequest request) { oAuthLoginService.logout(OAuthProvider.KAKAO); return ApiResponseGenerator.success("로그아웃 성공", HttpStatus.OK); } - return ApiResponseGenerator.success("이미 로그아웃 상태입니다.", HttpStatus.OK); + throw AlreadyLogoutException.EXCEPTION; } @Operation(summary = "카카오 소셜 로그인 (코드로 로그인)", description = "Redirect URL이 백엔드 주소로 설정될 때 사용합니다.") diff --git a/src/main/java/econo/buddybridge/auth/exception/AlreadyLogoutException.java b/src/main/java/econo/buddybridge/auth/exception/AlreadyLogoutException.java new file mode 100644 index 0000000..1f262d7 --- /dev/null +++ b/src/main/java/econo/buddybridge/auth/exception/AlreadyLogoutException.java @@ -0,0 +1,13 @@ +package econo.buddybridge.auth.exception; + +import econo.buddybridge.common.exception.BusinessException; + +public class AlreadyLogoutException extends BusinessException { + + public static BusinessException EXCEPTION = new AlreadyLogoutException(); + + public AlreadyLogoutException() { + super(AuthErrorCode.ALREADY_LOGOUT); + } + +} diff --git a/src/main/java/econo/buddybridge/auth/exception/AuthErrorCode.java b/src/main/java/econo/buddybridge/auth/exception/AuthErrorCode.java index 9af6687..d351c3d 100644 --- a/src/main/java/econo/buddybridge/auth/exception/AuthErrorCode.java +++ b/src/main/java/econo/buddybridge/auth/exception/AuthErrorCode.java @@ -7,6 +7,7 @@ public enum AuthErrorCode implements ErrorCode { SESSION_ALREADY_EXISTS("A001", HttpStatus.BAD_REQUEST, "이미 세션이 존재합니다. 삭제 응답 후 다시 시도해주세요."), FEIGN_REDIRECT("A002", HttpStatus.OK, "Feign Client Logout Redirect"), FEIGN_KAKAO_EXCEPTION("A003", HttpStatus.BAD_REQUEST, "카카오 API 호출 오류가 발생했습니다."), + ALREADY_LOGOUT("A004", HttpStatus.BAD_REQUEST, "이미 로그아웃 상태입니다."), ; private final String code; diff --git a/src/main/java/econo/buddybridge/config/WebConfig.java b/src/main/java/econo/buddybridge/config/WebConfig.java index 1671255..ed71f2c 100644 --- a/src/main/java/econo/buddybridge/config/WebConfig.java +++ b/src/main/java/econo/buddybridge/config/WebConfig.java @@ -19,8 +19,7 @@ public void addCorsMappings(CorsRegistry registry) { // CORS 설정 "http://localhost:3000", "https://localhost:3000", "http://localhost:8080", "https://localhost:8080", "http://localhost:8081", "https://localhost:8081", - "https://buddybridge-git-master-simminbos-projects.vercel.app/", - "https://buddybridge-simminbos-projects.vercel.app/" + "https://buddy-bridge.vercel.app/" ) .allowedMethods("GET", "POST", "PUT", "DELETE") .allowedHeaders("*")