Skip to content

Commit

Permalink
Merge branch 'develop' into refactor/Techit-Springles#208-index-page-…
Browse files Browse the repository at this point in the history
…api-controller
  • Loading branch information
ujumom committed Sep 8, 2023
2 parents 4aa3f90 + 19524c4 commit 50f67f4
Show file tree
Hide file tree
Showing 57 changed files with 2,124 additions and 1,064 deletions.
85 changes: 60 additions & 25 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,91 @@ name: Chatfia Dev CI/CD

on:
pull_request:
types: [closed]
types: [ closed ]
workflow_dispatch: # (2).수동 실행도 가능하도록

permissions:
contents: read

jobs:
secrets: inherit
build:
runs-on: ubuntu-latest # (3).OS환경
secrets: inherit

if: github.event.pull_request.merged == true && (github.event.pull_request.base.ref == 'main' || github.event.pull_request.base.ref == 'develop')

# 환경변수
env:
NAVER_MAIL_PASSWORD: ${{ secrets.NAVER_MAIL_PASSWORD }}
NAVER_MAIL_USERNAME: ${{ secrets.NAVER_MAIL_USERNAME }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
KAKAO_SNS_APP_KEY: ${{ secrets.KAKAO_SNS_APP_KEY }}
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}


steps:
- name: Checkout
uses: actions/checkout@v2 # (4).코드 check out
uses: actions/checkout@v2 # 코드 check out

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17 # (5).자바 설치
java-version: 17 # 자바 설치
distribution: 'adopt'

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash # (6).권한 부여
shell: bash # 권한 부여

- name: Build with Gradle
run: ./gradlew clean build -x test
shell: bash # (7).build 시작
shell: bash # build 시작

- name: Get current time
uses: 1466587594/get-current-time@v2
id: current-time-build
- name: Get current-time
uses: gerred/actions/current-time@master
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00" # (8).build 시점의 시간 확보

- name: Show Current Time
run: echo "CurrentTime=$"
run: echo "CurrentTime=${{ steps.current-time.outputs.time }}"
shell: bash # (9).확보한 시간 보여 주기

- name: Test with Gradle
run: ./gradlew --info test # (10).test 시작

- name: Get current time
uses: 1466587594/get-current-time@v2
- name: Get current time test
uses: gerred/actions/current-time@master
id: current-time-test
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00" # (11).test 시점의 시간 확보

- name: Show Current Time
run: echo "CurrentTime=$"
- name: Show Current Time test
run: echo "CurrentTime=$"{{ steps.current-time.outputs.time }}"
shell: bash # (12).확보한 시간 보여 주기

- name: Run string replace
uses: frabert/replace-string-action@master
id: format-time
with:
pattern: '[:\.]+'
string: "${{ steps.current-time-test.outputs.time }}"
replace-with: '-'
flags: 'g'

# 도커 로그인 + 빌드
- name: Docker build
run: |
docker login -u ${{ env.DOCKERHUB_USERNAME }} -p ${{ env.DOCKERHUB_TOKEN }}
docker build -t springles .
docker tag springles chatpiaspringles/springles:latest
docker push chatpiaspringles/springles:latest
- name: Generate deployment package
run: |
mkdir -p deploy
Expand All @@ -62,15 +96,16 @@ jobs:
cp -r .platform deploy/.platform
cd deploy && zip -r deploy.zip .
# - name: Beanstalk Deploy
# uses: einaregilsson/beanstalk-deploy@v21
# with:
# aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# application_name: chatfia-dev
# environment_name: chatfia-dev-env
# version_label: github-action-${{ steps.current-time.outputs.formattedTime }}
# region: ap-northeast-2
# deployment_package: deploy/deploy.zip
# wait_for_environment_recovery: 60

- name: Beanstalk Deploy
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: springles-dev
environment_name: Springles-dev-env
version_label: "the-simple-engineer-deployment-${{ steps.format-time.outputs.replaced }}"
region: ap-northeast-2
# deployment_package: docker-compose.yml
deployment_package: deploy/deploy.zip
wait_for_environment_recovery: 60
# use_existing_version_if_available: true
3 changes: 2 additions & 1 deletion .platform/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ events {
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

types_hash_max_size 2048;
types_hash_bucket_size 128;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
Expand Down
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM openjdk:17-jdk-slim-buster

#작업 dir
WORKDIR /app

# 파일 복사
COPY . /app

# 빌드 --exclude-task test 는 테스트 오류로 추가함
RUN ./gradlew build --exclude-task test

# 빌드된 jar 복사
COPY build/libs/Springles-0.0.1-SNAPSHOT.jar app.jar

EXPOSE 8080


CMD ["java", "-jar", "app.jar"]

#FROM nginx
#COPY --from=0 /app/build /usr/share/nginx/html
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: '3.8'
services:
development:
build:
context: .
dockerfile: Dockerfile
ports:
- '8080:8080'
beanstalk:
image: "chatpiaspringles/springles"
ports:
- "8080:8080"

mysql-docker:
image: mysql
ports:
- "3306:3306"
container_name: "docker-mysql"

redis-docker:
image: redis
command: redis-server --port 6379
container_name: "docker-redis"
labels:
- "name=redis"
- "mode=standalone"
ports:
- 6379:6379
4 changes: 2 additions & 2 deletions src/main/java/com/springles/config/MailConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
public class MailConfig {

// username, password 환경변수 설정 필요
@Value("${username}")
@Value("${NAVER_MAIL_USERNAME}")
private String username;
@Value("${password}")
@Value("${NAVER_MAIL_PASSWORD}")
private String password;

@Bean
Expand Down
41 changes: 26 additions & 15 deletions src/main/java/com/springles/config/WebSecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.springles.config;

//import com.springles.jwt.AccessTokenInterceptor;
//import com.springles.jwt.CORSFilter;
import com.springles.jwt.JwtExceptionFilter;
import com.springles.jwt.JwtTokenFilter;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
Expand All @@ -14,14 +16,23 @@
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.access.intercept.AuthorizationFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;

import static org.springframework.security.config.Customizer.withDefaults;

@Configuration
@RequiredArgsConstructor
public class WebSecurityConfig implements WebMvcConfigurer {

private final JwtTokenFilter jwtTokenFilter;
private final JwtExceptionFilter jwtExceptionFilter;

// private final AccessTokenInterceptor accessTokenInterceptor;
// @Override
// public void addInterceptors(InterceptorRegistry registry) {
Expand All @@ -34,22 +45,22 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(
authHttp -> authHttp
/** 아래 API를 제외한 나머지에 대해서는 인증이 필요 없도록 임시 세팅 (*추후 개발 완료 시 '실제 권한 코드'로 변경 필요) */
.requestMatchers(new AntPathRequestMatcher("/member/updateInfo")).authenticated()
.requestMatchers(new AntPathRequestMatcher("/member/signOut")).authenticated()
.requestMatchers(new AntPathRequestMatcher("/member/logout")).authenticated()
.requestMatchers(new AntPathRequestMatcher("/info/profile")).authenticated()
.requestMatchers(new AntPathRequestMatcher("/record", "GET")).authenticated()
.anyRequest().permitAll()
/** 실제 권한 코드 */
// .requestMatchers(new AntPathRequestMatcher("/v1/signup")).permitAll()
// .requestMatchers(new AntPathRequestMatcher("/member/signup")).permitAll()
// .requestMatchers(new AntPathRequestMatcher("/v1/login-page")).permitAll()
// .requestMatchers(new AntPathRequestMatcher("/v1/login")).permitAll()
// .requestMatchers(new AntPathRequestMatcher("/member/login")).permitAll()
// .requestMatchers(new AntPathRequestMatcher("/v1/login-page?error")).permitAll()
// .requestMatchers(new AntPathRequestMatcher("/css/*")).permitAll()
// .anyRequest().authenticated()
// 회원가입, 로그인, 아이디/비밀번호 찾기, 쿠키 저장 api·ui
.requestMatchers(new AntPathRequestMatcher("/v1/signup")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/v1/login")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/v1/login-page")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/v1/login-page?error")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/v1/vertification-id")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/v1/vertification-pw")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/member/signup")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/member/login")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/member/vertification/id")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/member/vertification/pw")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/cookie/*")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/css/*")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/images/*")).permitAll()
.anyRequest().authenticated()
)
.formLogin(
login -> login
Expand Down
37 changes: 34 additions & 3 deletions src/main/java/com/springles/config/WebSocketStompConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
Expand All @@ -27,7 +28,7 @@ public class WebSocketStompConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {

registry.addEndpoint("/chatting");
registry.addEndpoint("/chatting").setAllowedOrigins("*");
}


Expand All @@ -41,9 +42,9 @@ public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/topic",
"/sub/chat",
"/sub/gameStart",
"/sub/player",
"/sub/joinGame",
"/sub/exitGame"
"/sub/exitGame",
"/sub/gameRole"
);

// 발신
Expand Down Expand Up @@ -71,5 +72,35 @@ public MessageListenerAdapter dayEliminationListener(DayEliminationManager subsc
return new MessageListenerAdapter(subscriber, "sendMessage");
}

@Bean
public ChannelTopic topicStartFin() {
return new ChannelTopic("START_FIN");
}

@Bean
public ChannelTopic topicDayDiscussionFin() {
return new ChannelTopic("DAY_DISCUSSION_FIN");
}

@Bean
public ChannelTopic topicDayEliminationFin() {
return new ChannelTopic("DAY_ELIMINAION_FIN");
}

@Bean
public ChannelTopic topicDayToNightFin() {
return new ChannelTopic("DAY_TO_NIGHT_FIN");
}

@Bean
public ChannelTopic topicNightVoteFin() {
return new ChannelTopic("NIGHT_VOTE_FIN");
}

@Bean
public ChannelTopic topicEnd() {
return new ChannelTopic("END");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import com.springles.domain.dto.response.ResResult;
import com.springles.exception.CustomException;
import com.springles.exception.constants.ErrorCode;
import com.springles.jwt.JwtTokenUtils;
import com.springles.service.ChatRoomService;
import com.springles.service.CookieService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
Expand All @@ -31,13 +33,14 @@ public class ChatRoomController {

private final ChatRoomService chatRoomService;
private final MemberUiController memberUiController;
private final CookieService cookieService;

// 채팅방 생성
@Operation(summary = "채팅방 생성", description = "채팅방 생성")
@PostMapping(value = "/chatrooms")
public ResponseEntity<ResResult> createChatRoom(@Valid @RequestBody ChatRoomReqDTO chatRoomReqDTO, HttpServletRequest request, Authentication auth){

String accessToken = (String) request.getAttribute("accessToken");
String accessToken = cookieService.atkFromCookie(request);
MemberInfoResponse info = memberUiController.info(accessToken);
Long id = info.getId();
String memberName = info.getMemberName();
Expand Down Expand Up @@ -142,4 +145,12 @@ public String deleteChatRoom(
chatRoomService.deleteChatRoom(memberId, chatroomid);
return "redirect:/v1/chatrooms";
}

@GetMapping("/chatRooms/{roomId}")
public ChatRoomResponseDto findRoomInfo(
@PathVariable Long roomId
) {
return chatRoomService.findChatRoomByChatRoomId(roomId);
}

}
Loading

0 comments on commit 50f67f4

Please sign in to comment.