Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

소셜 로그인 리다이렉트 수정 테스트, 도커 가독성 수정 #62

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 17 additions & 39 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
docker push $REPOSITORY_URI:$TAG

# 9. Docker 이미지 실행 파일을 EC2로 전달
- name: Deploy to EC2
- name: Send Deploy File to EC2
run: |
# 1. SSH 개인 키 준비
echo "${{ secrets.EC2_SSH_PRIVATE_KEY }}" > private_key.pem
Expand All @@ -83,33 +83,6 @@ jobs:
echo \"Deploying Docker image with TAG: \$TAG\"
echo \"Deploying Docker image with REPOSITORY_URI: \$REPOSITORY_URI\"

# 여기서 부분적으로 시크릿을 확인하기 위해 마스킹(앞 3글자 + 길이 표시) 예시
# -------------------------------------------------------------------
echo \"=== Print partial Secrets (masked) for Debug ===\"
# DB_ENDPOINT 전체 길이
LEN_DB_ENDPOINT=\${#DB_ENDPOINT}
# 앞 3글자 + 나머지 부분을 *로 대체
DB_ENDPOINT_PARTIAL=\"\${DB_ENDPOINT:0:3}\$(printf '%*s' \$((LEN_DB_ENDPOINT-3)) | tr ' ' '*')\"
echo \"DB_ENDPOINT (length=\$LEN_DB_ENDPOINT) => \$DB_ENDPOINT_PARTIAL\"

LEN_DB_USERNAME=\${#DB_USERNAME}
DB_USERNAME_PARTIAL=\"\${DB_USERNAME:0:3}\$(printf '%*s' \$((LEN_DB_USERNAME-3)) | tr ' ' '*')\"
echo \"DB_USERNAME (length=\$LEN_DB_USERNAME) => \$DB_USERNAME_PARTIAL\"

LEN_DB_PASSWORD=\${#DB_PASSWORD}
DB_PASSWORD_PARTIAL=\"\${DB_PASSWORD:0:3}\$(printf '%*s' \$((LEN_DB_PASSWORD-3)) | tr ' ' '*')\"
echo \"DB_PASSWORD (length=\$LEN_DB_PASSWORD) => \$DB_PASSWORD_PARTIAL\"

# 다른 메일/비밀번호도 같은 방식으로 부분 마스킹 예시
LEN_MAIL_USERNAME=\${#MAIL_USERNAME}
MAIL_USERNAME_PARTIAL=\"\${MAIL_USERNAME:0:3}\$(printf '%*s' \$((LEN_MAIL_USERNAME-3)) | tr ' ' '*')\"
echo \"MAIL_USERNAME (length=\$LEN_MAIL_USERNAME) => \$MAIL_USERNAME_PARTIAL\"

LEN_MAIL_PASSWORD=\${#MAIL_PASSWORD}
MAIL_PASSWORD_PARTIAL=\"\${MAIL_PASSWORD:0:3}\$(printf '%*s' \$((LEN_MAIL_PASSWORD-3)) | tr ' ' '*')\"
echo \"MAIL_PASSWORD (length=\$LEN_MAIL_PASSWORD) => \$MAIL_PASSWORD_PARTIAL\"
# -------------------------------------------------------------------

aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin \$REPOSITORY_URI

echo \"Container exists: $(docker ps -aq -f name=memowithtags-backend)\"
Expand All @@ -120,20 +93,25 @@ jobs:
docker pull \$REPOSITORY_URI:\$TAG
docker run -d \
-p 8080:8080 \
-e SPRING_PROFILES_ACTIVE=prod \
-e DB_NAME=memowithtags_db \
-e DB_ENDPOINT=${{ secrets.DB_ENDPOINT }} \\
-e DB_USERNAME=${{ secrets.DB_USERNAME }} \
-e DB_PASSWORD=${{ secrets.DB_PASSWORD }} \
-e MAIL_USERNAME=${{ secrets.MAIL_USERNAME }} \
-e MAIL_PASSWORD=${{ secrets.MAIL_PASSWORD }} \
-e KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }} \
-e KAKAO_REDIRECT_URL=${{ secrets.KAKAO_REDIRECT_URL }} \
-e NAVER_CLIENT_ID=${{ secrets.NAVER_CLIENT_ID }} \
-e NAVER_CLIENT_SECRET=${{ secrets.NAVER_CLIENT_SECRET }} \
--env-file /home/ubuntu/.env \
--name memowithtags-backend \
\$REPOSITORY_URI:\$TAG" > deploy.sh

# 3. .env 파일 생성
echo "SPRING_PROFILES_ACTIVE=prod
DB_NAME=memowithtags_db
DB_ENDPOINT=${{ secrets.DB_ENDPOINT }}
DB_USERNAME=${{ secrets.DB_USERNAME }}
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
MAIL_USERNAME=${{ secrets.MAIL_USERNAME }}
MAIL_PASSWORD=${{ secrets.MAIL_PASSWORD }}
KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }}
KAKAO_REDIRECT_URL=${{ secrets.KAKAO_REDIRECT_URL }}
NAVER_CLIENT_ID=${{ secrets.NAVER_CLIENT_ID }}
NAVER_CLIENT_SECRET=${{ secrets.NAVER_CLIENT_SECRET }}
GOOGLE_CLIENT_ID=1234
GOOGLE_REDIRECT_URI=1234" > .env

# 배포 스크립트 EC2로 전송
scp -i private_key.pem -o StrictHostKeyChecking=no deploy.sh ubuntu@${{ secrets.EC2_PUBLIC_IP }}:/home/ubuntu/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ package com.wafflestudio.toyproject.memoWithTags.user
enum class RoleType(val type: String) {
ROLE_USER("ROLE_USER"),
ROLE_ADMIN("ROLE_ADMIN");

companion object {
fun from(type: String?): RoleType? = entries.find { it.type == type }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.wafflestudio.toyproject.memoWithTags.user.controller
import com.wafflestudio.toyproject.memoWithTags.exception.OAuthRequestException
import com.wafflestudio.toyproject.memoWithTags.user.dto.UserResponse.LoginResponse
import com.wafflestudio.toyproject.memoWithTags.user.service.SocialLoginService
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
Expand Down Expand Up @@ -32,6 +33,16 @@ class SocialLoginController(
@GetMapping("/oauth/kakao")
fun kakaoCallback(
@RequestParam("code") code: String
): ResponseEntity<Unit> {
val appLink = "memowithtags://oauth/kakao?code=$code"
return ResponseEntity.status(HttpStatus.FOUND)
.header("Location", appLink)
.build()
}

@GetMapping("/oauth/kakao/login")
fun kakaoLogin(
@RequestParam("code") code: String
): ResponseEntity<LoginResponse> {
val (_, accessToken, refreshToken) = socialLoginService.kakaoCallBack(code)
return ResponseEntity.ok(LoginResponse(accessToken, refreshToken))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.wafflestudio.toyproject.memoWithTags.user.persistence
import com.wafflestudio.toyproject.memoWithTags.memo.persistence.MemoEntity
import com.wafflestudio.toyproject.memoWithTags.tag.persistence.TagEntity
import com.wafflestudio.toyproject.memoWithTags.user.RoleType
import com.wafflestudio.toyproject.memoWithTags.user.RoleType.ROLE_USER
import com.wafflestudio.toyproject.memoWithTags.user.SocialType
import jakarta.persistence.CascadeType
import jakarta.persistence.Column
Expand All @@ -29,7 +28,7 @@ class UserEntity(
@Column(name = "verified", nullable = false)
var verified: Boolean = false,
@Column(name = "role", nullable = false)
var role: RoleType = ROLE_USER,
var role: RoleType = RoleType.ROLE_USER,
@Column(name = "social_type", nullable = true)
var socialType: SocialType? = null,
@Column(name = "created_at", nullable = false)
Expand Down
Loading