Skip to content

Commit

Permalink
chore: frontend 3001로 변경, dockerfile 오류수정, elk모듈
Browse files Browse the repository at this point in the history
  • Loading branch information
kjeongh committed Jan 19, 2023
1 parent aa6f05e commit 7b76487
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "elk"]
path = elk
url = https://github.com/0BVer/logging-example.git
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ public ResponseEntity<ResultResponse> createChatRoom (
@PathVariable Long postId,
@Parameter(hidden = true) @LoginUser User loginUser) {

//채팅 신청 기록이 있을 경우 생성 실패
if(chatRoomService.isUserChatted(loginUser.getId())) {
log.error("이미 채팅 기록이 있음 -> 채팅방으로 리다이렉트시키면 좋을듯");
throw new RuntimeException();
}

ChatRoom createdChatRoom = chatRoomService.createChatRoom(postId, loginUser); // loginUser = mentor
if (createdChatRoom == null) {
return ResponseEntity.ok(ResultResponse.of(ResultCode.CHATROOM_CREATE_SUCCESS, false));
}

return ResponseEntity.ok(ResultResponse.of(ResultCode.CHATROOM_CREATE_SUCCESS, createdChatRoom));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
import com.rising.backend.domain.post.repository.PostRepository;
import com.rising.backend.domain.user.domain.User;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

@Service
@RequiredArgsConstructor
@Slf4j
public class ChatRoomService {

private final ChatRoomRepository chatRoomRepository;
Expand All @@ -23,6 +27,17 @@ public class ChatRoomService {
public ChatRoom createChatRoom(Long postId, User mentor) {
Post post = postRepository.findById(postId).orElseThrow();

//채팅 신청 기록이 있을 경우 생성 실패
if(isUserChatted(mentor.getId())) {
log.error("이미 채팅 기록이 있음 -> 채팅방으로 리다이렉트시키면 좋을듯");
throw new RuntimeException(); // 추후 수정
}

if(isUserPostCreated(mentor.getId(), post.getUser().getId())) {
log.error("자신의 글에서 채팅방 생성 불가능");
return null;
}

return chatRoomRepository.save(chatRoomMapper.toChatRoomEntity(post, mentor));
}

Expand All @@ -35,4 +50,8 @@ public boolean isUserChatted(Long userId) {
return false; // 수정
}

public boolean isUserPostCreated(Long userId, Long postUserId) {
return Objects.equals(postUserId, userId);
}

}
82 changes: 82 additions & 0 deletions docker-compose.elk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# docker-compose.prod 와 함께 실행 해야 합니다. # need to run with docker-compose.prod
# docker compose -f docker-compose.prod.yml -f docker-compose.logging.yml up --build

# changeme 로 설정된 임시 패스워드를 변경하여 사용하시길 바랍니다. # need to change temp password 'changeme'

version: '3.7'

services:
elasticsearch:
build:
context: ./elk/elasticsearch
args:
ELASTIC_VERSION: 8.5.2
volumes:
- ./elk/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro,Z
- elasticsearch:/usr/share/elasticsearch/data:Z
ports:
- 9200:9200
- 9300:9300
environment:
node.name: elasticsearch
ES_JAVA_OPTS: -Xms512m -Xmx512m
# Bootstrap password.
# Used to initialize the keystore during the initial startup of
# Elasticsearch. Ignored on subsequent runs.
ELASTIC_PASSWORD: changeme
# Use single node discovery in order to disable production mode and avoid bootstrap checks.
# see: https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html
discovery.type: single-node
restart: unless-stopped

logstash:
build:
context: ./elk/logstash
args:
ELASTIC_VERSION: 8.5.2
volumes:
- ./elk/logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml:ro,Z
- ./elk/logstash/pipeline:/usr/share/logstash/pipeline:ro,Z
ports:
- 5044:5044
- 50000:50000/tcp
- 50000:50000/udp
- 9600:9600
environment:
LS_JAVA_OPTS: -Xms256m -Xmx256m
LOGSTASH_INTERNAL_PASSWORD: changeme
depends_on:
- elasticsearch
restart: unless-stopped

kibana:
build:
context: ./elk/kibana
args:
ELASTIC_VERSION: 8.5.2
volumes:
- ./elk/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml:ro,Z
ports:
- 5601:5601
environment:
KIBANA_SYSTEM_PASSWORD: changeme
depends_on:
- elasticsearch
restart: unless-stopped

filebeat:
build:
context: ./elk/filebeat
args:
ELASTIC_VERSION: 8.5.2
entrypoint: "filebeat -e -strict.perms=false"
volumes:
- ./elk/filebeat/config/filebeat.yml:/usr/share/filebeat/filebeat.yml
- ./nginx/log:/var/log/nginx # nginx log path (require same option on nginx container)
depends_on:
- logstash
- elasticsearch
- kibana

volumes:
elasticsearch:
14 changes: 8 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ services:

frontend:
container_name: frontend_con
build: ./frontend
build:
context: ./frontend
dockerfile: Dockerfile
command: ["npm", "start"]
# ports:
# - "3000:3000"
# expose:
# - 3000
ports:
- "3001:3001"
expose:
- 3000
# networks:
# - frontend-net

Expand All @@ -79,7 +81,7 @@ services:
image: nginx:latest
restart: on-failure
build:
dockerfile: dockerfile
dockerfile: Dockerfile
context: ./nginx
ports:
- "80:80"
Expand Down
1 change: 1 addition & 0 deletions elk
Submodule elk added at 1edc49
28 changes: 6 additions & 22 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
FROM node:18.12.1

USER root
FROM node:16 as builder

WORKDIR /frontend
COPY . /frontend

# 개발
RUN npm install --force

# 배포
# RUN yarn
# RUN yarn --ignore-platform

# Make variable API_URL to put uri into url
# uri 변수 형태로 받아서 url에 넣어 작동하도록 함
ENV REACT_APP_HOST_IP_ADDRESS $API_URL
ENV REACT_APP_BACKEND_URL $REACT_APP_BACKEND_URL
COPY /package.json .

COPY . ./
RUN npm i --force

# 개발
# docker-compose.yml 파일에 npm start 작성할거면 지워도 됨
#RUN npm start
RUN npm cache clear --force

# 배포
# RUN yarn run build
COPY ./ ./

EXPOSE 3000
RUN npm run build
12 changes: 6 additions & 6 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ http {
server backend:8080; #서비스명
}

upstream client {
server frontend:3000;
}

server {
listen 80;
server_name localhost;
charset utf-8;

# /경로로 오는 호출은 프론트엔드로 포워딩
location / {
proxy_pass http://client/;
root /usr/share/nginx/html;
index index.html;
expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
try_files $uri$args $uri$args/ $uri $uri/ /index.html;
}

# /api 경로로 오는 요청을 백엔드 upstream 의 /api 경로로 포워딩
Expand Down

0 comments on commit 7b76487

Please sign in to comment.