Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
becda9f
Update README.md
kyungmin1221 May 2, 2024
81a3dbd
FIX : 토큰재발급시 cookie 추가로 변겸
juwum12 May 2, 2024
fa35c8a
Update README.md
kyungmin1221 May 2, 2024
f0290dd
Update README.md
minnieming May 2, 2024
a1537b6
Update README.md
kyungmin1221 May 2, 2024
c7c4ecb
Update README.md
kyungmin1221 May 2, 2024
27e68ad
Update README.md
kyungmin1221 May 2, 2024
f92119c
Update README.md
kyungmin1221 May 3, 2024
b87e943
Update README.md
kyungmin1221 May 3, 2024
0b918cf
Update README.md
kyungmin1221 May 3, 2024
04e9d9f
Update README.md
kyungmin1221 May 3, 2024
7fdabad
Update README.md
kyungmin1221 May 3, 2024
b4b5534
Update README.md
kyungmin1221 May 3, 2024
35d527c
Update README.md
kyungmin1221 May 3, 2024
6721db2
Update README.md
kyungmin1221 May 3, 2024
3aa84f8
FIX : asc->desc
minnieming May 4, 2024
5be1d8d
Merge branch 'develop' of https://github.com/Nawabali-project/Nawabal…
juwum12 May 4, 2024
55eb8e7
FIX : develop 로그인 로직변경
juwum12 May 4, 2024
e32cfb7
FIX : cookie SameSite 설정
juwum12 May 4, 2024
80792b2
FIX : cookie Secure 설정
juwum12 May 4, 2024
9def8cc
FIX : cookie Secure 설정
juwum12 May 4, 2024
e036f7e
FIX : cookie Secure 설정
juwum12 May 4, 2024
6f806dc
FIX : response에 헤더, 쿠키 추가
juwum12 May 4, 2024
963419b
FIX : httponly설정
juwum12 May 4, 2024
b0024de
FIX : header에 토큰저장
juwum12 May 4, 2024
e2a8ff0
FIX : updateAll 수정
juwum12 May 4, 2024
cf307d3
Merge remote-tracking branch 'origin/release' into release
minnieming May 4, 2024
d622ba8
Merge remote-tracking branch 'origin/develop' into feature/187/testSe…
minnieming May 4, 2024
20c28d6
FIX : user controller / service
minnieming May 4, 2024
3083558
Merge pull request #191 from Nawabali-project/feature/187/testServer
minnieming May 4, 2024
8bb3d77
fix : cicd 관련 파일 develop 기준으로 변경
devjsyu May 4, 2024
40989d5
fix : elasticsearch gradle 변경
devjsyu May 4, 2024
6651771
Update README.md
minnieming May 6, 2024
a25f1ef
Update README.md
kyungmin1221 May 6, 2024
b5164c9
Update README.md
minnieming May 7, 2024
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
22 changes: 8 additions & 14 deletions .github/workflows/cicd_production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: Deploy to Amazon EC2

on:
push:
branches: ["release"]
branches: ["develop"]

env:
AWS_REGION: ap-northeast-2
S3_BUCKET_NAME: sparta-project-build
CODE_DEPLOY_APPLICATION_NAME: codedeploy
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: deployment-group-dongnaebangnae
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: codedeploy-deployment-group-production

permissions:
contents: read
Expand All @@ -35,7 +35,7 @@ jobs:
- name: Make an application.properties
run: |
mkdir -p ./src/main/resources
echo "${{ secrets.APPLICATION_PROD }}" > ./src/main/resources/application.properties
echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.properties
cat ./src/main/resources/application.properties

# (4) Gradle build (Test 제외)
Expand All @@ -55,15 +55,6 @@ jobs:
gradle-version: 8.7
arguments: clean build -x test

# 실제 필요한 파일(Jar, appspect.yml, 배포 스크립트)만 담기
- name: zip 파일 생성
run: |
mkdir -p deploy/scripts
cp scripts/*.sh deploy/scripts
cp appspec.yml deploy/
cp build/libs/*.jar deploy/
cd deploy && zip -r ./$GITHUB_SHA.zip *
shell: bash

# (5) AWS 인증 (IAM 사용자 Access Key, Secret Key 활용)
- name: Configure AWS credentials
Expand All @@ -77,8 +68,11 @@ jobs:
# (6) 빌드 결과물을 S3 버킷에 업로드
- name: Upload to AWS S3
run: |
aws s3 cp deploy/$GITHUB_SHA.zip s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip

aws deploy push \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
--ignore-hidden-files \
--s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \
--source .

# (7) S3 버킷에 있는 파일을 대상으로 CodeDeploy 실행
- name: Deploy to AWS EC2 from S3
Expand Down
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@

### 📌 일반 회원가입 시 이메일 인증

![회원가입인증메일짤]()
![이메일인증_저화질3gif](https://github.com/Nawabali-project/Nawabali-BE/assets/157681548/14f170b3-de06-401c-96a3-b64c9b20561a)
- 실제 사용 중인 이메일인지 인증 메일을 발송하고, 인증 코드를 발급하여 메일을 인증할 수 있습니다.

### 📌 소셜 로그인(Kakao)
Expand Down Expand Up @@ -173,6 +173,7 @@


## ✅ 동네 소식
![동네 소식_5](https://github.com/Nawabali-project/Nawabali-BE/assets/157681548/51a80338-94f4-4de2-9b32-4bbf0868b54e)
|우리동네 인기글은?|여러동네의 인기들은?|카테고리별로 인기동네는?|
|:--:|:--:|:--:|
|![image](https://github.com/Nawabali-project/Nawabali-BE/assets/105621255/b7cff42b-ec6f-4379-a98b-a70a47e93859)|![image](https://github.com/Nawabali-project/Nawabali-BE/assets/105621255/4c64ec9f-d0ce-4795-abe4-447ecb868ca2)|![image](https://github.com/Nawabali-project/Nawabali-BE/assets/105621255/bf8f085b-a8f8-4695-a9bb-263742dc170e)|
Expand All @@ -184,16 +185,18 @@


## ✅ 마이페이지
![프로필편집gif](https://github.com/Nawabali-project/Nawabali-BE/assets/157681548/a3d1ee19-9dbd-47fa-abaf-c3988913feef)
![회원정보변경짤](https://github.com/Nawabali-project/Nawabali-BE/assets/105621255/760e16b3-b3dc-44f7-a9c5-9d1c176b2d33)

- 마이페이지에서 회원 정보를 변경할 수 있습니다.
- 프로필 사진, 닉네임, 나의 지역을 변경할 수 있습니다.

![00마이페이지 _ 등록한 게시물 확인](https://github.com/Nawabali-project/Nawabali-BE/assets/157681548/675f6f3d-9bb0-45a4-b48a-8a434c64a190)
![본인게시물확인짤](https://github.com/Nawabali-project/Nawabali-BE/assets/105621255/f39b2b0b-85b2-4ca6-8e75-42d8b7ee871d)

- 마이페이지에서 내가 등록한 게시물들을 확인할 수 있습니다.

![북마크](https://github.com/Nawabali-project/Nawabali-BE/assets/157681548/85842426-1704-49a8-a8cc-4890a0e10e27)
![본인의 북마크짤](https://github.com/Nawabali-project/Nawabali-BE/assets/105621255/032dd71f-a49d-421f-b9bb-d3cebce953df)
- 마이페이지에서 내가 등록한 북마크된 게시물들을 볼 수 있습니다.

Expand All @@ -202,17 +205,21 @@
- 등급은 좋아요를 받은 수와 게시글 수를 기준으로 **"주민,토박이,터줏대감"** 으로 구분됩니다.

## ✅ 실시간 채팅/알림 기능
![알림짤](https://github.com/Nawabali-project/Nawabali-BE/assets/105621255/a20de69c-9bba-4a81-a7c7-01ac8ba4c115)

![채팅검색기능_1](https://github.com/Nawabali-project/Nawabali-BE/assets/157681548/c6cfc20b-0f15-49c0-8d29-32069b408b2e)
![알림짤](https://github.com/Nawabali-project/Nawabali-BE/assets/105621255/f3495696-4fa7-485c-a9fe-4791c814ce10)
- 상대방과 1:1 대화를 할 수 있습니다.
![알림짤](https://github.com/Nawabali-project/Nawabali-BE/assets/105621255/f961b00c-b847-41a2-8d95-a8bcd19a6e8b)
- 검색을 통해 채팅방이나 메세지 내용을 검색 할 수 있습니다.메세지가 오면 상단에 알림으로 표시되어 어떤 페이지에 있어도 메세지가 왔음을 알 수 있습니다.
- 채팅방이나 채팅메세지를 통한 검색이 가능합니다.

<br>
![채팅방 생성gif](https://github.com/Nawabali-project/Nawabali-BE/assets/157681548/015ca82d-64d5-4506-a4d4-48acec17a7da)
- 상대의 이름을 검색하여 채팅방을 생성 할 수 있습니다.

![채팅보내기_1](https://github.com/Nawabali-project/Nawabali-BE/assets/157681548/0f535f2f-efa4-44d2-b73a-20cd95968402)
![알림짤](https://github.com/Nawabali-project/Nawabali-BE/assets/105621255/a20de69c-9bba-4a81-a7c7-01ac8ba4c115)
- 1:1 대화를 할 수 있습니다.

![채팅알림](https://github.com/Nawabali-project/Nawabali-BE/assets/157681548/627afa58-a336-4168-b726-fff822b495fc)
![알림짤](https://github.com/Nawabali-project/Nawabali-BE/assets/105621255/f961b00c-b847-41a2-8d95-a8bcd19a6e8b)
- 메세지가 오면 상단에 알림으로 표시되어 어떤 페이지에 있어도 메세지가 왔음을 알 수 있습니다. 채팅을 확인하면 알림이 사라지게 됩니다.

## 프로젝트 구조
<br>

```
빈칸
```
10 changes: 3 additions & 7 deletions appspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ os: linux

files:
- source: /
destination: /home/ubuntu/app/step3/zip/
destination: /home/ubuntu/app
overwrite: yes

permissions:
Expand All @@ -14,14 +14,10 @@ permissions:

hooks:
AfterInstall:
- location: scripts/stop.sh # 엔진엑스와 연결되어 있지 않은 스프링 부트를 종료합니다.
- location: scripts/stop.sh
timeout: 60
runas: ubuntu
ApplicationStart:
- location: scripts/start.sh # 엔진엑스와 연결되어 있지 않은 Port로 새 버전의 스프링 부트를 시작합니다.
timeout: 60
runas: ubuntu
ValidateService:
- location: scripts/health.sh # 새 스프링 부트가 정상적으로 실행됐는지 확인합니다.
- location: scripts/start.sh
timeout: 60
runas: ubuntu
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'com.nawabali'
version = '1.0.1-SNAPSHOT-' + new Date().format("yyyy-MM-dd-HHmmss")
version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = '17'
Expand All @@ -23,6 +23,9 @@ repositories {

dependencies {

// thumbnailator
implementation 'net.coobird:thumbnailator:0.4.14'

//cache
implementation 'org.springframework.boot:spring-boot-starter-cache'

Expand Down Expand Up @@ -80,8 +83,7 @@ dependencies {
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

// thumbnailator
implementation 'net.coobird:thumbnailator:0.4.14'

}

// Querydsl 설정부
Expand Down
46 changes: 12 additions & 34 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
#!/usr/bin/env bash

ABSPATH=$(readlink -f $0)
ABSDIR=$(dirname $ABSPATH)
source ${ABSDIR}/profile.sh
PROJECT_ROOT="/home/ubuntu/app"
JAR_FILE="$PROJECT_ROOT/build/libs/nawabali-0.0.1-SNAPSHOT.jar"

REPOSITORY=/home/ubuntu/app/step3
PROJECT_NAME=ZeroDowntimeDeployment
DEPLOY_LOG="$REPOSITORY/deploy.log"
APP_LOG="$PROJECT_ROOT/application.log"
ERROR_LOG="$PROJECT_ROOT/error.log"
DEPLOY_LOG="$PROJECT_ROOT/deploy.log"

TIME_NOW=$(date +%c)

echo "> Build 파일 복사"
echo "> cp $REPOSITORY/zip/*.jar $REPOSITORY/"
# build 파일 복사
echo "$TIME_NOW > $JAR_FILE 파일 복사" >> $DEPLOY_LOG
cp $PROJECT_ROOT/build/libs/*.jar $JAR_FILE

cp $REPOSITORY/zip/*.jar $REPOSITORY/
# jar 파일 실행
echo "$TIME_NOW > $JAR_FILE 파일 실행" >> $DEPLOY_LOG
nohup java -Duser.timezone=Asia/Seoul -jar $JAR_FILE > $APP_LOG 2> $ERROR_LOG &

echo "> 새 어플리케이션 배포"
JAR_NAME=$(ls -tr $REPOSITORY/*.jar | tail -n 1)

echo "> JAR Name: $JAR_NAME"

echo "> $JAR_NAME 에 실행권한 추가"

chmod +x $JAR_NAME

echo "> $JAR_NAME 실행"

IDLE_PROFILE=$(find_idle_profile)

echo "> $JAR_NAME 를 profile=$IDLE_PROFILE 로 실행합니다."

# 쉬고 있던 프로필로 jar파일을 백그라운드 실행
nohup java -jar \
-Dspring.config.location="classpath:/application.properties, /home/ubuntu/app/step3/zip/application-$IDLE_PROFILE.properties" \
-Dspring.profiles.active=$IDLE_PROFILE \
-Duser.timezone=Asia/Seoul \
$JAR_NAME > $REPOSITORY/application.log 2>&1 &

# Deploy 로그
echo "$TIME_NOW > $JAR_NAME 파일 실행" >> $DEPLOY_LOG
CURRENT_PID=$(pgrep -f $JAR_NAME)
CURRENT_PID=$(pgrep -f $JAR_FILE)
echo "$TIME_NOW > 실행된 프로세스 아이디 $CURRENT_PID 입니다." >> $DEPLOY_LOG
24 changes: 10 additions & 14 deletions scripts/stop.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
#!/usr/bin/env bash

ABSPATH=$(readlink -f $0)
ABSDIR=$(dirname $ABSPATH)
source ${ABSDIR}/profile.sh
PROJECT_ROOT="/home/ubuntu/app"
JAR_FILE="$PROJECT_ROOT/build/libs/nawabali-0.0.1-SNAPSHOT.jar"

DEPLOY_LOG="$PROJECT_ROOT/deploy.log"

IDLE_PORT=$(find_idle_port)
TIME_NOW=$(date +%c)
DEPLOY_LOG="/home/ubuntu/app/step3/deploy.log"

echo "> $IDLE_PORT 에서 구동중인 애플리케이션 pid 확인"
IDLE_PID=$(lsof -ti tcp:${IDLE_PORT})
# 현재 구동 중인 애플리케이션 pid 확인
CURRENT_PID=$(pgrep -f $JAR_FILE)

if [ -z ${IDLE_PID} ]
then
# 프로세스가 켜져 있으면 종료
if [ -z $CURRENT_PID ]; then
echo "$TIME_NOW > 현재 실행중인 애플리케이션이 없습니다" >> $DEPLOY_LOG
echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다."
else
echo "$TIME_NOW > 실행중인 $IDLE_PID 애플리케이션 종료 " >> $DEPLOY_LOG
echo "> kill -15 $IDLE_PID"
kill -15 ${IDLE_PID}
sleep 5
echo "$TIME_NOW > 실행중인 $CURRENT_PID 애플리케이션 종료 " >> $DEPLOY_LOG
kill -15 $CURRENT_PID
fi
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ public String kakaoLogin(@RequestParam String code,
HttpServletResponse response)
throws JsonProcessingException, IOException {

String accessToken = kakaoService.kakaoLogin(code, response);
kakaoService.kakaoLogin(code, response);

// return "redirect:https://www.dongnaebangnae.com/?accessToken=" + accessToken;
return "redirect:https://www.dongnaebangnae.com";
return "redirect:https://dongnaebangnae.vercel.app";
// return "redirect:https://www.dongnaebangnae.com";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class UserController {
private final UserService userService;

@PostMapping("/logout")
public ResponseEntity<String> logout(HttpServletRequest request, HttpServletResponse response){
return userService.logout(request, response);
public void logout( HttpServletResponse response){
userService.logout( response);
}

@PostMapping("/signup")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import com.nawabali.nawabali.global.tool.redis.RedisTool;
import com.nawabali.nawabali.repository.UserRepository;
import com.nawabali.nawabali.security.UserDetailsImpl;
import io.jsonwebtoken.Jwt;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseCookie;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
Expand Down Expand Up @@ -74,19 +74,11 @@ protected void successfulAuthentication(HttpServletRequest request, HttpServletR
log.info("user email : " + username, role);
log.info("accessCookie value : " + accessCookie.getValue());
log.info("refreshCookie value : " + refreshCookie.getValue());


response.addHeader(JwtUtil.AUTHORIZATION_HEADER, token);

// same-site 없는 버전
response.addCookie(accessCookie);
// response.addHeader("Set-Cookie", jwtUtil.createResponseCookie(token));
// response.addHeader(JwtUtil.AUTHORIZATION_HEADER, String.format("%s; Secure; HttpOnly; SameSite=None;",token));

// refresh 토큰 redis에 저장
// substring 제외
redisTool.setValues(token.substring(7), refreshCookie.getValue(), Duration.ofMillis(jwtUtil.REFRESH_EXPIRATION_TIME));
// redisTool.setValues(token, refreshCookie.getValue(), Duration.ofMillis(jwtUtil.REFRESH_EXPIRATION_TIME));


// 로그인 성공 메시지를 JSON 형태로 응답 본문에 추가
response.setContentType("application/json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ public class JwtAuthorizationFilter extends OncePerRequestFilter {

@Override
protected void doFilterInternal(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain) throws ServletException, IOException {
String bearerAccessToken = jwtUtil.getTokenFromCookieAndName(req, JwtUtil.AUTHORIZATION_HEADER);
log.info(bearerAccessToken);
String accessToken = jwtUtil.substringToken(bearerAccessToken);
// String accessToken = jwtUtil.getJwtFromHeader(req);
// log.info("accessToken : "+ accessToken);
// String accessToken = jwtUtil.getTokenFromCookieAndName(req, JwtUtil.AUTHORIZATION_HEADER);
String accessToken = jwtUtil.getJwtFromHeader(req);
log.info("accessToken : "+ accessToken);
if(StringUtils.hasText(accessToken)){
// 토큰 유무 확인
// accessToken = jwtUtil.substringToken(accessToken);
Expand All @@ -70,16 +68,15 @@ protected void doFilterInternal(HttpServletRequest req, HttpServletResponse res,
// 새로운 access, refresh Token 발행
String newAccessToken = jwtUtil.createAccessToken(email, role);
String newRefreshToken = jwtUtil.createRefreshToken(email);
Cookie newAccessCookie = jwtUtil.createAccessCookie(newAccessToken);
log.info("발급한 유저의 email : " + email);

res.addHeader(JwtUtil.AUTHORIZATION_HEADER, newAccessToken);
res.addCookie(newAccessCookie);
// res.addHeader(JwtUtil.AUTHORIZATION_HEADER, String.format("%s; Secure; HttpOnly; SameSite=None;",newAccessToken));

redisTool.deleteValues(accessToken);
log.info("기존 refreshToken 삭제 key :" + accessToken );
redisTool.setValues(jwtUtil.substringToken(newAccessToken), newRefreshToken, Duration.ofMillis(jwtUtil.REFRESH_EXPIRATION_TIME));
// redisTool.setValues(newAccessToken, newRefreshToken, Duration.ofMillis(jwtUtil.REFRESH_EXPIRATION_TIME));
log.info("refreshToken 재발급 완료 key : " + newAccessToken);
log.info("refreshToken 재발급 완료 key : " + jwtUtil.substringToken(newAccessToken));

try{
setAuthentication(info.getSubject());
Expand Down
Loading