-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from kakao-tech-campus-2nd-step3/weekly/11
11주차 종합 PR
- Loading branch information
Showing
125 changed files
with
5,602 additions
and
960 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,73 @@ | ||
name: Build and Deploy to EC2 | ||
|
||
# 워크플로우가 언제 실행될 것인지 조건 명시 | ||
on: | ||
push: # 모든 브랜치 대상 | ||
|
||
# AWS 관련 값 변수로 설정 | ||
env: | ||
AWS_REGION: ap-northeast-2 | ||
AWS_S3_BUCKET: devcard-deploy-bucket | ||
AWS_CODE_DEPLOY_APPLICATION: Devcard-Application-CD | ||
AWS_CODE_DEPLOY_GROUP: Devcard-Deployment-Group | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
# JDK 21 설치 | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
|
||
# 환경 변수를 사용하여 application-secret.properties 파일 생성 | ||
- name: make application-secret.properties | ||
run: | | ||
mkdir -p ./src/main/resources | ||
cd ./src/main/resources | ||
touch ./application-secret.properties | ||
echo "kakao.javascript.key=${{ secrets.KAKAO_JAVASCRIPT_KEY }}" >> ./application-secret.properties | ||
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> ./application-secret.properties | ||
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> ./application-secret.properties | ||
echo "GH_CLIENT_ID=${{ secrets.GH_CLIENT_ID }}" >> ./application-secret.properties | ||
echo "GH_CLIENT_SECRET=${{ secrets.GH_CLIENT_SECRET }}" >> ./application-secret.properties | ||
echo "GH_REDIRECT_URI=${{ secrets.GH_REDIRECT_URI }}" >> ./application-secret.properties | ||
# 권한 부여 | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x ./gradlew | ||
shell: bash | ||
|
||
- name: Build and Test | ||
env: | ||
DB_USERNAME: ${{ secrets.DB_USERNAME }} | ||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | ||
run: ./gradlew build test --info | ||
|
||
# 빌드 파일을 zip 형식으로 압축 | ||
- name: Make zip file | ||
run: zip -r ./$GITHUB_SHA.zip . | ||
shell: bash | ||
|
||
# AWS 권한 | ||
- name: AWS credential 설정 | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-region: ${{ env.AWS_REGION }} | ||
aws-access-key-id: ${{ secrets.CICD_ACCESS_KEY }} | ||
aws-secret-access-key: ${{ secrets.CICD_SECRET_KEY }} | ||
|
||
# S3 버킷에 빌드파일(zip 파일)을 업로드 | ||
- name: Upload to S3 | ||
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$AWS_S3_BUCKET/$GITHUB_SHA.zip | ||
|
||
# EC2 인스턴스에 S3에 저장되어 있던 zip 파일을 받아와 배포 시작 | ||
- name: EC2에 배포 | ||
run: aws deploy create-deployment --application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name ${{ env.AWS_CODE_DEPLOY_GROUP }} --s3-location bucket=$AWS_S3_BUCKET,key=$GITHUB_SHA.zip,bundleType=zip |
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,17 @@ | ||
version: 0.0 | ||
os: linux | ||
|
||
files: | ||
- source: / | ||
destination: /home/ubuntu/app | ||
overwrite: yes | ||
|
||
permissions: | ||
- object: / | ||
owner: ubuntu | ||
group: ubuntu | ||
|
||
hooks: | ||
ApplicationStart: | ||
- location: scripts/deploy.sh | ||
timeout: 60 |
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
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,29 @@ | ||
#!/bin/bash | ||
|
||
# 빌드 파일 탐색 및 이름 설정 | ||
BUILD_JAR=$(ls /home/ubuntu/app/build/libs/*-SNAPSHOT.jar) | ||
JAR_NAME=$(basename $BUILD_JAR) | ||
echo ">>> build 파일명: $JAR_NAME" >> /home/ubuntu/deploy.log | ||
|
||
# 빌드 파일 복사 | ||
echo ">>> build 파일 복사" >> /home/ubuntu/deploy.log | ||
DEPLOY_PATH=/home/ubuntu/app/ | ||
cp $BUILD_JAR $DEPLOY_PATH | ||
|
||
# 현재 실행 중인 애플리케이션 종료 | ||
echo ">>> 현재 실행중인 애플리케이션 pid 확인 후 일괄 종료" >> /home/ubuntu/deploy.log | ||
CURRENT_PID=$(pgrep -f $JAR_NAME) | ||
|
||
if [ -z "$CURRENT_PID" ]; then | ||
echo ">>> 현재 실행 중인 애플리케이션이 없습니다." >> /home/ubuntu/deploy.log | ||
else | ||
echo ">>> 실행 중인 애플리케이션 종료: $CURRENT_PID" >> /home/ubuntu/deploy.log | ||
kill -15 $CURRENT_PID | ||
sleep 5 | ||
fi | ||
|
||
# 애플리케이션 배포 | ||
DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME | ||
echo ">>> DEPLOY_JAR 배포" >> /home/ubuntu/deploy.log | ||
echo ">>> $DEPLOY_JAR을 실행합니다" >> /home/ubuntu/deploy.log | ||
nohup java -jar $DEPLOY_JAR >> /home/ubuntu/deploy.log 2>&1 & |
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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/devcard/devcard/auth/controller/page/MypageController.java
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,22 @@ | ||
package com.devcard.devcard.auth.controller.page; | ||
|
||
import com.devcard.devcard.auth.entity.Member; | ||
import com.devcard.devcard.auth.model.OauthMemberDetails; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
@Controller | ||
public class MypageController { | ||
|
||
@GetMapping("/mypage") | ||
public String mypage(@AuthenticationPrincipal OauthMemberDetails oauthMemberDetails, Model model) { | ||
if (oauthMemberDetails != null) { | ||
Member member = oauthMemberDetails.getMember(); | ||
model.addAttribute("member", member); | ||
} | ||
return "mypage"; | ||
} | ||
|
||
} |
4 changes: 2 additions & 2 deletions
4
...card/auth/controller/LoginController.java → ...auth/controller/rest/LoginController.java
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
4 changes: 1 addition & 3 deletions
4
...card/auth/controller/OauthController.java → ...auth/controller/rest/OauthController.java
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
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
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
4 changes: 4 additions & 0 deletions
4
src/main/java/com/devcard/devcard/auth/repository/MemberRepository.java
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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
package com.devcard.devcard.auth.repository; | ||
|
||
import com.devcard.devcard.auth.entity.Member; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
|
||
Member findByGithubId(String githubId); | ||
|
||
List<Member> findByIdIn(List<Long> ids); | ||
} |
Oops, something went wrong.