Skip to content

Commit

Permalink
Mafia-together ver 2.0 prod deploy (#165)
Browse files Browse the repository at this point in the history
* Update README.md

* Update README.md

* [feature] 전체적으로 디스코드를 연동한다. (#135)

* chore: CI/CD에도 깃허브 연동 추가

* chore: FeignClient 의존성 추가

* feat: Service 구성

* feat: Exception Handler에 연결

* chore: discord 적용

* chore: 문구 수정

* chore: build.gradle 코드들과 컨벤션 일치

* refactor: 코드 정리

* refactor: Component Annotation 제거

* fix : 게임 종료 이후 sse 구독자에게 wait 발행

* feat : redis lock 구현

* test : lobby 동시입장 테스트 구현

* feat : RedissonMultiLock을 통해 다중락 동시성 문제 해결

* refactor : 필요없는 출력 제거

* refactor : testService 접근자 변경

* refactor : RedisLockAspect 이름 변경

* refactor : aspect 내 static 변수 접근자 변경

* refactor : @link를 통한 대상 링크 수정

* docs : @exception을 통해 예외사항 정리

* feat : @TestComponent를 통해 테스트 환경에서 어노테이션이 적용안되던 것을 수정

* refactor: change field name [contents --> content] (#141)

* #142 - 대기방에서 SSE를 통해 인원을 받아온다. (#143)

* refactor: findByCodeAndName 메서드 추가

* feat: ParticipantJoinEvent 추가하여 접속 시 SSE 요청 보낼 수 있도록 설정

* test: InMemorySseEmitterRepository Test 추가

* test: EventListener Test 추가

* test: LobbyInfoResponse Test 수정 및, EventListener MockBean 처리를 통해 에러 해결

* refactor: 패키지 이동

* refactor: 예외 변경

* refactor: Suppress 추가하여 Ascii Code Error 해결

* refactor: Lobby에 isMaster 구현

* hotfix : 참가자가 sse구독전에 요청하던 에러 수정 (#148)

* feat: 직업 스킬 사용을 웹소켓으로 변경 (#146)

* feat: 직업 스킬 사용을 웹소켓으로 변경

* refactor: JobController 통일 및 테스트 수정

* #144 - SSE를 Game에서 분리한다

* refactor : SSE 로직 Game에서 분리

* refactor : SSE event publish 로직 bean을 통해 common으로 이동

* refactor : sse disconnect 로직 common으로 이동

* refactor : SseRepository 명 Session 변경 및 infra package로 이동

* Test : SseEventPublisher 테스트 작성

* test : SseAspectTest 구현

* refactor : 상수 함수 내부 변수로 변경

* refactor : final 키워드 추가 및 SseEventBuilder import 추가

* refactor : 메서드 네임 수정 및 Sse 생성 매서드 위치 이동

* refactor : aspect test 수정

* refactor : aspect test method 모킹

* refactor : mockito 버전 문제 해결

* #150 - 레거시 코드 제거 (#151)

* refactor: status 제거

* refactor: Mafia 결과 조회 제거 및 v2 명시 제거

* refactor: Http 통신 제거 및 버전 표식 제거

* refactor: 테스트 수정

* chore: 404 알림 제외 처리 (#153)

* #155 - ci 라벨 삭제 및 빌드 오류 수정 (#156)

* chore: ci시 라벨 체크 삭제

* fix: import 추가

* feat: NoResourceFoundException 에러 핸들링 추가 (#158)

* feat: 웹소켓 채팅 리팩터링 (#162)

* 직업 스킬 response 형식 변경 (#163)

* feat: 웹소켓 채팅 리팩터링

* feat: 웹소켓 스킬 response 변경

* Hotfix/#1 sse connect (#164)

* fix: 게임 종료시 sse connect 유지

* fix: 게임 상태 delete event 송신하지 않게 수정

---------

Co-authored-by: kpeel5839 <[email protected]>
Co-authored-by: Jae-Baek Song <[email protected]>
  • Loading branch information
3 people authored Dec 22, 2024
1 parent 3bc5277 commit b5db613
Show file tree
Hide file tree
Showing 60 changed files with 1,630 additions and 739 deletions.
71 changes: 68 additions & 3 deletions .github/workflows/backend-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ name: Java CI with Gradle

on:
pull_request:
branches: [dev]
branches: [ dev ]

permissions:
contents: read

jobs:
build:
if: contains(github.event.pull_request.labels.*.name, 'Backend')
runs-on: ubuntu-22.04
permissions:
pull-requests: write
Expand All @@ -20,7 +19,7 @@ jobs:
with:
fetch-depth: 3
token: ${{ secrets.SUBMODULE_TOKEN }}
submodules: true
submodules: true
- run: git log --pretty=oneline

- name: JDK 21을 설치합니다.
Expand All @@ -34,3 +33,69 @@ jobs:

- name: Gradle을 통해 빌드합니다.
run: ./gradlew build

- name: 성공 메시지 전송
if: ${{ success() }}
uses: Ilshidur/[email protected]
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_GITHUB_WEBHOOK }}
DISCORD_USERNAME: Mafia-Together-BOT
DISCORD_AVATAR: https://i.namu.wiki/i/vMYV9DNseNCfKzaPIDshk7eG_7pAZm8BG6c2I_s6XXwyreDbpu3A1nDRUpbqvycQrRvgbSJeg15iXSSiGK5xyw.webp
DISCORD_EMBEDS: |
[
{
"author": {
"name": "${{ github.event.pull_request.user.login }}",
"url": "https://github.com/pknu-wap/WAPP/blob/main/image/icon.png?raw=true",
"icon_url": "${{ github.event.pull_request.user.avatar_url }}"
},
"title": "테스트 성공 ~ 파워 엉덩이 확인하자 ~ 🥰🥰 \n#${{ github.event.pull_request.number }} : ${{ github.event.pull_request.title }}",
"color": 10478271,
"description": "${{ github.event.pull_request.html_url }}",
"fields": [
{
"name": "Base Branch",
"value": "${{ github.base_ref }}",
"inline": true
},
{
"name": "Compare Branch",
"value": "${{ github.head_ref }}",
"inline": true
}
]
}
]
- name: 실패 메시지 전송
if: ${{ failure() }}
uses: Ilshidur/[email protected]
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_GITHUB_WEBHOOK }}
DISCORD_USERNAME: Mafia-Together-BOT
DISCORD_AVATAR: https://i.namu.wiki/i/vMYV9DNseNCfKzaPIDshk7eG_7pAZm8BG6c2I_s6XXwyreDbpu3A1nDRUpbqvycQrRvgbSJeg15iXSSiGK5xyw.webp
DISCORD_EMBEDS: |
[
{
"author": {
"name": "${{ github.event.pull_request.user.login }}",
"url": "https://github.com/pknu-wap/WAPP/blob/main/image/icon.png?raw=true",
"icon_url": "${{ github.event.pull_request.user.avatar_url }}"
},
"title": "테스트 실패... 달리 엉덩이 가져와 \n#${{ github.event.pull_request.number }} : ${{ github.event.pull_request.title }}",
"color": 13458524,
"description": "${{ github.event.pull_request.html_url }}",
"fields": [
{
"name": "Base Branch",
"value": "${{ github.base_ref }}",
"inline": true
},
{
"name": "Compare Branch",
"value": "${{ github.head_ref }}",
"inline": true
}
]
}
]
71 changes: 69 additions & 2 deletions .github/workflows/backend-dev-CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Dev CI/CD

on:
push:
branches: [dev]
branches: [ dev ]

permissions:
contents: read
Expand Down Expand Up @@ -38,6 +38,73 @@ jobs:
run: cp -f build/libs/*.jar /home/ubuntu/deploy/

- name: 배포 스크립트 실행
run: |
run: |
cd /home/ubuntu/deploy
sh deploy.sh
- name: 성공 메시지 전송
if: ${{ success() }}
uses: Ilshidur/[email protected]
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_GITHUB_WEBHOOK }}
DISCORD_USERNAME: Mafia-Together-BOT
DISCORD_AVATAR: https://i.namu.wiki/i/vMYV9DNseNCfKzaPIDshk7eG_7pAZm8BG6c2I_s6XXwyreDbpu3A1nDRUpbqvycQrRvgbSJeg15iXSSiGK5xyw.webp
DISCORD_EMBEDS: |
[
{
"author": {
"name": "${{ github.event.pull_request.user.login }}",
"url": "https://github.com/pknu-wap/WAPP/blob/main/image/icon.png?raw=true",
"icon_url": "${{ github.event.pull_request.user.avatar_url }}"
},
"title": "배포 성공 ~ 파워 엉덩이 확인하자 ~ 🥰🥰 \n#${{ github.event.pull_request.number }} : ${{ github.event.pull_request.title }}",
"color": 10478271,
"description": "${{ github.event.pull_request.html_url }}",
"fields": [
{
"name": "Base Branch",
"value": "${{ github.base_ref }}",
"inline": true
},
{
"name": "Compare Branch",
"value": "${{ github.head_ref }}",
"inline": true
}
]
}
]
- name: 실패 메시지 전송
if: ${{ failure() }}
uses: Ilshidur/[email protected]
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_GITHUB_WEBHOOK }}
DISCORD_USERNAME: Mafia-Together-BOT
DISCORD_AVATAR: https://i.namu.wiki/i/vMYV9DNseNCfKzaPIDshk7eG_7pAZm8BG6c2I_s6XXwyreDbpu3A1nDRUpbqvycQrRvgbSJeg15iXSSiGK5xyw.webp
DISCORD_EMBEDS: |
[
{
"author": {
"name": "${{ github.event.pull_request.user.login }}",
"url": "https://github.com/pknu-wap/WAPP/blob/main/image/icon.png?raw=true",
"icon_url": "${{ github.event.pull_request.user.avatar_url }}"
},
"title": "배포 실패... 달리 엉덩이 가져와 \n#${{ github.event.pull_request.number }} : ${{ github.event.pull_request.title }}",
"color": 13458524,
"description": "${{ github.event.pull_request.html_url }}",
"fields": [
{
"name": "Base Branch",
"value": "${{ github.base_ref }}",
"inline": true
},
{
"name": "Compare Branch",
"value": "${{ github.head_ref }}",
"inline": true
}
]
}
]
69 changes: 68 additions & 1 deletion .github/workflows/backend-prod-CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Prod CI/CD

on:
push:
branches: [prod]
branches: [ prod ]

permissions:
contents: read
Expand Down Expand Up @@ -58,3 +58,70 @@ jobs:
script: |
cd ~/deploy
sh deploy.sh
- name: 성공 메시지 전송
if: ${{ success() }}
uses: Ilshidur/[email protected]
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_GITHUB_WEBHOOK }}
DISCORD_USERNAME: Mafia-Together-BOT
DISCORD_AVATAR: https://i.namu.wiki/i/vMYV9DNseNCfKzaPIDshk7eG_7pAZm8BG6c2I_s6XXwyreDbpu3A1nDRUpbqvycQrRvgbSJeg15iXSSiGK5xyw.webp
DISCORD_EMBEDS: |
[
{
"author": {
"name": "${{ github.event.pull_request.user.login }}",
"url": "https://github.com/pknu-wap/WAPP/blob/main/image/icon.png?raw=true",
"icon_url": "${{ github.event.pull_request.user.avatar_url }}"
},
"title": "배포 성공 ~ 파워 엉덩이 확인하자 ~ 🥰🥰 \n#${{ github.event.pull_request.number }} : ${{ github.event.pull_request.title }}",
"color": 10478271,
"description": "${{ github.event.pull_request.html_url }}",
"fields": [
{
"name": "Base Branch",
"value": "${{ github.base_ref }}",
"inline": true
},
{
"name": "Compare Branch",
"value": "${{ github.head_ref }}",
"inline": true
}
]
}
]
- name: 실패 메시지 전송
if: ${{ failure() }}
uses: Ilshidur/[email protected]
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_GITHUB_WEBHOOK }}
DISCORD_USERNAME: Mafia-Together-BOT
DISCORD_AVATAR: https://i.namu.wiki/i/vMYV9DNseNCfKzaPIDshk7eG_7pAZm8BG6c2I_s6XXwyreDbpu3A1nDRUpbqvycQrRvgbSJeg15iXSSiGK5xyw.webp
DISCORD_EMBEDS: |
[
{
"author": {
"name": "${{ github.event.pull_request.user.login }}",
"url": "https://github.com/pknu-wap/WAPP/blob/main/image/icon.png?raw=true",
"icon_url": "${{ github.event.pull_request.user.avatar_url }}"
},
"title": "배포 실패... 달리 엉덩이 가져와 \n#${{ github.event.pull_request.number }} : ${{ github.event.pull_request.title }}",
"color": 13458524,
"description": "${{ github.event.pull_request.html_url }}",
"fields": [
{
"name": "Base Branch",
"value": "${{ github.base_ref }}",
"inline": true
},
{
"name": "Compare Branch",
"value": "${{ github.head_ref }}",
"inline": true
}
]
}
]
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@

## 기술 스택
---
![Skill](https://github.com/user-attachments/assets/e5b18101-c81d-4c54-9001-e9d5772c4c5f)
![Skill](https://github.com/user-attachments/assets/4695beb1-2ff3-4649-b6ee-80c67900a2a9)


## 인프라 아키텍쳐
---
![infra-architecture](https://github.com/user-attachments/assets/e7db379d-8218-47f1-995c-9fa7efd4ce38)
![infra-architecture](https://github.com/user-attachments/assets/ffc7e50e-a9b1-4168-9969-42f554551790)


## 실시간 통신
---
Expand Down
2 changes: 1 addition & 1 deletion backend-submodule
16 changes: 13 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,19 @@ repositories {
mavenCentral()
}

ext {
set('springCloudVersion', "2021.0.4")
}

dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.redisson:redisson-spring-boot-starter:3.37.0'
testImplementation 'org.testcontainers:testcontainers'

implementation 'org.springframework.boot:spring-boot-starter-validation'
Expand All @@ -35,11 +46,10 @@ dependencies {

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'

implementation 'org.springframework.boot:spring-boot-starter-websocket'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'

testImplementation 'org.mockito:mockito-core:5.10.0'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public class MafiaTogetherApplication {
public static void main(String[] args) {
SpringApplication.run(MafiaTogetherApplication.class, args);
}

}
50 changes: 30 additions & 20 deletions src/main/java/mafia/mafiatogether/chat/application/ChatService.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,61 @@
package mafia.mafiatogether.chat.application;

import java.time.Clock;
import java.util.List;

import lombok.RequiredArgsConstructor;
import mafia.mafiatogether.chat.application.dto.request.ChatRequest;
import mafia.mafiatogether.chat.application.dto.response.ChatResponse;
import mafia.mafiatogether.chat.domain.Chat;
import mafia.mafiatogether.chat.domain.ChatRepository;
import mafia.mafiatogether.chat.domain.Message;
import mafia.mafiatogether.common.exception.ExceptionCode;
import mafia.mafiatogether.common.exception.GameException;
import mafia.mafiatogether.job.domain.PlayerJob;
import mafia.mafiatogether.job.domain.PlayerJobRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.NoSuchElementException;
import java.util.function.Supplier;

@Service
@RequiredArgsConstructor
public class ChatService {

private final PlayerJobRepository playerJobRepository;
private final ChatRepository chatRepository;

@Transactional(readOnly = true)
public List<ChatResponse> findAllChat(final String code, final String name) {
final PlayerJob playerJobs = playerJobRepository.findById(code)
.orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE));
final Chat chat = chatRepository.findById(code)
.orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE));
final boolean isMafia = playerJobs.isMafia(name);
return chat.getMessages().stream()

return chat.getMessages()
.stream()
.map(message -> ChatResponse.of(
message,
message.getName().equals(name),
isMafia,
playerJobs.findJobByName(message.getName()).getJobType()
))
.toList();
message.getName().equals(name)
)).toList();
}

@Transactional
public void saveChat(final String code, final String name, final ChatRequest chatRequest) {
final Chat chat = chatRepository.findById(code)
.orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE));
final Message message = Message.ofChat(name, chatRequest.content());
public Message enter(final String name, final String code) {
return saveChat(code, () -> Message.fromEnter(name));
}

@Transactional
public Message leave(final String name, final String code) {
return saveChat(code, () -> Message.fromLeave(name));
}

@Transactional
public Message chat(final String name, final String code, final String content) {
return saveChat(code, () -> Message.ofChat(name, content));
}

private Message saveChat(final String code, Supplier<Message> messageFunction) {
Chat chat = chatRepository.findById(code)
.orElseThrow(NoSuchElementException::new);
Message message = messageFunction.get();
chat.saveMessage(message);
chatRepository.save(chat);
return message;
}


}
Loading

0 comments on commit b5db613

Please sign in to comment.