Skip to content

Commit c2ad40e

Browse files
authored
Merge branch 'BE/dev' into BE/feature/#951-member-refactor
2 parents c6448eb + 0fea106 commit c2ad40e

File tree

57 files changed

+622
-821
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+622
-821
lines changed

.github/workflows/be_cd-test.yml

+95-12
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040

4141
- name: Image build and push
4242
run: |
43-
docker build --build-arg PROFILE=test --build-arg DEPENDENCY=build/dependency -t ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:test-latest --platform linux/arm64 .
43+
docker build --build-arg PROFILE=test --build-arg DEPENDENCY=build/dependency -t ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:test-latest --platform linux/amd64 .
4444
docker push ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:test-latest
4545
4646
- name: Upload docker-compose yaml script to artifact
@@ -49,9 +49,9 @@ jobs:
4949
name: docker-compose
5050
path: ${{ github.workspace }}/backend/be_app-docker-compose.yml
5151

52-
deploy:
52+
deployA:
5353
environment: test
54-
runs-on: test-ec2-runner
54+
runs-on: test-ec2-runner-a
5555
needs: build
5656
defaults:
5757
run:
@@ -69,9 +69,11 @@ jobs:
6969
7070
- name: Extract secrets as .be_app-env file
7171
run: |
72+
echo $(pwd)
7273
chmod +x ./deploy.sh
74+
echo chmod ok
7375
source ./deploy.sh
74-
76+
echo source ok
7577
echo "BLUE_PORT=$BLUE_PORT" >> $GITHUB_ENV
7678
echo "GREEN_PORT=$GREEN_PORT" >> $GITHUB_ENV
7779
@@ -82,11 +84,12 @@ jobs:
8284
DOCKER_IMAGE_VERSION=test-latest
8385
8486
# DB Configuration secrets info from Github Secrets
85-
MASTER_DB_URL=${{ secrets.TEST_SERVER_DB_URL }}
87+
MYSQL_TIME_ZONE=${{ secrets.MYSQL_TIME_ZONE }}
88+
DB_BINDING_PORT=${{ secrets.DB_BINDING_PORT }}
89+
MASTER_DB_URL=${{ secrets.TEST_SERVER_MASTER_DB_URL }}
8690
MASTER_DB_USERNAME=${{ secrets.TEST_SERVER_DB_USERNAME }}
8791
MASTER_DB_PASSWORD=${{ secrets.TEST_SERVER_DB_PASSWORD }}
88-
89-
SLAVE_DB_URL=${{ secrets.TEST_SERVER_DB_URL }}
92+
SLAVE_DB_URL=${{ secrets.TEST_SERVER_SLAVE_DB_URL }}
9093
SLAVE_DB_USERNAME=${{ secrets.TEST_SERVER_DB_USERNAME }}
9194
SLAVE_DB_PASSWORD=${{ secrets.TEST_SERVER_DB_PASSWORD }}
9295
DDL_AUTO=${{ secrets.DDL_AUTO }}
@@ -97,7 +100,7 @@ jobs:
97100
CLIENT_REDIRECT_URI=${{ secrets.TEST_CLIENT_REDIRECT_URI }}
98101
JWT_KEY=${{ secrets.JWT_KEY}}
99102
100-
# Sticky Synchronize
103+
# INSTANCE NAME
101104
INSTANCE_NAME=${{ secrets.INSTANCE_A_NAME }}
102105
103106
# Server App
@@ -108,7 +111,7 @@ jobs:
108111
109112
- name: remove old spring-app image
110113
run: |
111-
sudo docker image rm -f coduo2024/springboot-app:test-latest;
114+
sudo docker image rm -f ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:test-latest;
112115
113116
- name: Start the new (green/blue) environment
114117
run: |
@@ -125,11 +128,91 @@ jobs:
125128
- name: Stop and remove the old environment
126129
run: |
127130
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml -p $BLUE_PORT down
128-
131+
129132
- name: Delete Dangling docker images
130133
run: |
131-
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml up -d
134+
sudo docker image prune -a -f
135+
136+
deployB:
137+
environment: test
138+
runs-on: test-ec2-runner-b
139+
needs: build
140+
defaults:
141+
run:
142+
working-directory: ./backend
143+
steps:
144+
- name: Set docker-compose YAML script to runner
145+
uses: actions/download-artifact@v4
146+
with:
147+
name: docker-compose
148+
path: ${{ github.workspace }}/backend
149+
150+
- name: Move docker-compose YAML
151+
run: |
152+
sudo mv be_app-docker-compose.yml ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/
153+
154+
- name: Extract secrets as .be_app-env file
155+
run: |
156+
echo $(pwd)
157+
chmod +x ./deploy.sh
158+
echo chmod ok
159+
source ./deploy.sh
160+
echo source ok
161+
echo "BLUE_PORT=$BLUE_PORT" >> $GITHUB_ENV
162+
echo "GREEN_PORT=$GREEN_PORT" >> $GITHUB_ENV
163+
164+
cat <<EOF > ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env
165+
166+
# Docker Hub info from Github Secrets
167+
DOCKER_REPO_NAME=${{ secrets.DOCKER_REPO_NAME }}
168+
DOCKER_IMAGE_VERSION=test-latest
169+
170+
# DB Configuration secrets info from Github Secrets
171+
MYSQL_TIME_ZONE=${{ secrets.MYSQL_TIME_ZONE }}
172+
DB_BINDING_PORT=${{ secrets.DB_BINDING_PORT }}
173+
MASTER_DB_URL=${{ secrets.TEST_SERVER_MASTER_DB_URL }}
174+
MASTER_DB_USERNAME=${{ secrets.TEST_SERVER_DB_USERNAME }}
175+
MASTER_DB_PASSWORD=${{ secrets.TEST_SERVER_DB_PASSWORD }}
176+
SLAVE_DB_URL=${{ secrets.TEST_SERVER_SLAVE_DB_URL }}
177+
SLAVE_DB_USERNAME=${{ secrets.TEST_SERVER_DB_USERNAME }}
178+
SLAVE_DB_PASSWORD=${{ secrets.TEST_SERVER_DB_PASSWORD }}
179+
DDL_AUTO=${{ secrets.DDL_AUTO }}
180+
181+
# OAUTH & JWT
182+
CLIENT_ID=${{ secrets.TEST_CLIENT_ID }}
183+
CLIENT_SECRET=${{ secrets.TEST_CLIENT_SECRET }}
184+
CLIENT_REDIRECT_URI=${{ secrets.TEST_CLIENT_REDIRECT_URI }}
185+
JWT_KEY=${{ secrets.JWT_KEY}}
186+
187+
# INSTANCE NAME
188+
INSTANCE_NAME=${{ secrets.INSTANCE_B_NAME }}
189+
190+
# Server App
191+
BLUE_SERVER_BINDING_PORT=${BLUE_PORT}
192+
GREEN_SERVER_BINDING_PORT=${GREEN_PORT}
193+
SERVER_LOGS_PATH=${{ secrets.SERVER_LOGS_PATH }}
194+
EOF
195+
196+
- name: remove old spring-app image
197+
run: |
198+
sudo docker image rm -f ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:test-latest;
132199
200+
- name: Start the new (green/blue) environment
201+
run: |
202+
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml -p $GREEN_PORT up -d
203+
204+
- name: Wait for new environment to be healthy
205+
run: |
206+
until curl -sf http://localhost:${GREEN_PORT}/api/actuator/health | grep "UP"; do sleep 5; done
207+
208+
- name: Reload NGINX
209+
run: |
210+
sudo systemctl reload nginx
211+
212+
- name: Stop and remove the old environment
213+
run: |
214+
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml -p $BLUE_PORT down
215+
133216
- name: Delete Dangling docker images
134217
run: |
135-
sudo docker image prune
218+
sudo docker image prune -a -f

backend/be_app-docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ services:
22
springboot-green:
33
container_name: coduo_springboot-app-${GREEN_SERVER_BINDING_PORT}
44
image: ${DOCKER_REPO_NAME}/springboot-app:${DOCKER_IMAGE_VERSION}
5-
platform: linux/arm64
5+
platform: linux/amd64
66
ports:
77
- "${GREEN_SERVER_BINDING_PORT}:${GREEN_SERVER_BINDING_PORT}"
88
volumes:

backend/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ dependencies {
5959
implementation 'io.jsonwebtoken:jjwt:0.12.6'
6060
implementation 'io.jsonwebtoken:jjwt-impl:0.12.6'
6161

62+
// Web Socket
63+
implementation 'org.springframework.boot:spring-boot-starter-websocket'
64+
6265
// Test
6366
testImplementation 'org.springframework.boot:spring-boot-starter-test'
6467
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

backend/src/main/java/site/coduo/common/config/web/WebMvcConfig.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public void addCorsMappings(final CorsRegistry registry) {
2323
registry.addMapping("/**")
2424
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "HEAD")
2525
.allowedOrigins("http://localhost:3000", "https://coduo.site", "https://test.coduo.site",
26-
"https://api-test.coduo.site", "https://api.coduo.site")
26+
"https://api-test.coduo.site", "https://api.coduo.site",
27+
"ws://test.coduo.site", "wss://test.coduo.site",
28+
"ws://api-test.coduo.site", "wss://api-test.coduo.site")
2729
.allowCredentials(true);
2830
}
2931
}

backend/src/main/java/site/coduo/pairroom/controller/PairRoomController.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import org.springframework.http.ResponseEntity;
1111
import org.springframework.web.bind.annotation.CookieValue;
12-
import org.springframework.web.bind.annotation.DeleteMapping;
1312
import org.springframework.web.bind.annotation.GetMapping;
1413
import org.springframework.web.bind.annotation.PatchMapping;
1514
import org.springframework.web.bind.annotation.PathVariable;
@@ -95,10 +94,18 @@ public ResponseEntity<PairRoomExistResponse> pairRoomExists(@RequestParam("acces
9594
return ResponseEntity.ok(response);
9695
}
9796

98-
@DeleteMapping("/pair-room/{accessCode}")
97+
@PatchMapping("/pair-room/{accessCode}/complete")
98+
public ResponseEntity<Void> completePairRoom(@PathVariable("accessCode") final String accessCode) {
99+
pairRoomService.completePairRoom(accessCode);
100+
return ResponseEntity.noContent()
101+
.build();
102+
}
103+
104+
@PatchMapping("/pair-room/{accessCode}/delete")
99105
public ResponseEntity<Void> deletePairRoom(@PathVariable("accessCode") final String accessCode) {
100106
pairRoomService.deletePairRoom(accessCode);
101-
return ResponseEntity.noContent().build();
107+
return ResponseEntity.noContent()
108+
.build();
102109
}
103110

104111
@GetMapping("/member/{accessCode}/exists")

backend/src/main/java/site/coduo/pairroom/controller/PairRoomExceptionHandler.java

+22-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
import site.coduo.common.controller.response.ApiErrorResponse;
1313
import site.coduo.pairroom.controller.error.PairRoomApiError;
1414
import site.coduo.pairroom.exception.DuplicatePairNameException;
15+
import site.coduo.pairroom.exception.InactivePairRoomException;
1516
import site.coduo.pairroom.exception.InvalidAccessCodeException;
1617
import site.coduo.pairroom.exception.InvalidNameFormatException;
18+
import site.coduo.pairroom.exception.InvalidPairRoomStatusException;
1719
import site.coduo.pairroom.exception.PairRoomException;
20+
import site.coduo.pairroom.exception.PairRoomMemberNotFoundException;
1821
import site.coduo.pairroom.exception.PairRoomNotFoundException;
19-
import site.coduo.pairroom.exception.InvalidPairRoomStatusException;
2022

2123
@Slf4j
2224
@RestControllerAdvice
@@ -31,6 +33,14 @@ public ResponseEntity<ApiErrorResponse> handleDuplicatePairNameException(final D
3133
.body(new ApiErrorResponse(PairRoomApiError.INVALID_PAIR_NAME.getMessage()));
3234
}
3335

36+
@ExceptionHandler(InactivePairRoomException.class)
37+
public ResponseEntity<ApiErrorResponse> handleInactivePairRoomException(final InactivePairRoomException e) {
38+
log.warn(e.getMessage());
39+
40+
return ResponseEntity.status(PairRoomApiError.INACTIVE_PAIR_ROOM.getHttpStatus())
41+
.body(new ApiErrorResponse(PairRoomApiError.INACTIVE_PAIR_ROOM.getMessage()));
42+
}
43+
3444
@ExceptionHandler(InvalidAccessCodeException.class)
3545
public ResponseEntity<ApiErrorResponse> handleInvalidAccessCodeException(final InvalidAccessCodeException e) {
3646
log.warn(e.getMessage());
@@ -49,7 +59,8 @@ public ResponseEntity<ApiErrorResponse> handleInvalidPropertiesFormatException(
4959
}
5060

5161
@ExceptionHandler(InvalidPairRoomStatusException.class)
52-
public ResponseEntity<ApiErrorResponse> handlePairRoomStatusNotFoundException(final InvalidPairRoomStatusException e) {
62+
public ResponseEntity<ApiErrorResponse> handlePairRoomStatusNotFoundException(
63+
final InvalidPairRoomStatusException e) {
5364
log.warn(e.getMessage());
5465

5566
return ResponseEntity.status(PairRoomApiError.INVALID_PROPERTIES_FORMAT.getHttpStatus())
@@ -64,6 +75,15 @@ public ResponseEntity<ApiErrorResponse> handlePairRoomNotFoundException(final Pa
6475
.body(new ApiErrorResponse(PairRoomApiError.PAIR_ROOM_NOT_FOUND.getMessage()));
6576
}
6677

78+
@ExceptionHandler(PairRoomMemberNotFoundException.class)
79+
public ResponseEntity<ApiErrorResponse> handlePairRoomMemberNotFoundException(
80+
final PairRoomMemberNotFoundException e) {
81+
log.warn(e.getMessage());
82+
83+
return ResponseEntity.status(PairRoomApiError.PAIR_ROOM_MEMBER_NOT_FOUND.getHttpStatus())
84+
.body(new ApiErrorResponse(PairRoomApiError.PAIR_ROOM_MEMBER_NOT_FOUND.getMessage()));
85+
}
86+
6787
@ExceptionHandler(PairRoomException.class)
6888
public ResponseEntity<ApiErrorResponse> handlePairRoomException(final PairRoomException e) {
6989
log.warn(e.getMessage());

backend/src/main/java/site/coduo/pairroom/controller/docs/PairRoomDocs.java

+7
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ ResponseEntity<Void> deletePairRoom(
8383
String accessCode
8484
);
8585

86+
@Operation(summary = "페어룸을 종료한다.")
87+
@ApiResponse(responseCode = "204", description = "페어룸 종료 성공")
88+
ResponseEntity<Void> completePairRoom(
89+
@Parameter(description = "페어룸 접근 코드", required = true)
90+
String accessCode
91+
);
92+
8693
@Operation(summary = "특정 회원이 특정 페어룸에 존재하는지 여부를 조회한다.")
8794
@ApiResponse(responseCode = "200", description = "회원 페어룸 참여 여부 조회 성공", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
8895
schema = @Schema(implementation = ExistMemberInPairRoomResponse.class)))

backend/src/main/java/site/coduo/pairroom/controller/error/PairRoomApiError.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public enum PairRoomApiError {
1313
INVALID_PAIR_NAME(HttpStatus.BAD_REQUEST, "올바르지 않은 페어 이름입니다."),
1414
INVALID_ACCESS_CODE(HttpStatus.BAD_REQUEST, "올바르지 않은 접근 코드입니다."),
1515
PAIR_ROOM_NOT_FOUND(HttpStatus.NOT_FOUND, "페어룸이 존재하지 않습니다."),
16-
INVALID_PROPERTIES_FORMAT(HttpStatus.BAD_REQUEST, "올바르지 않은 데이터 형식입니다.");
16+
PAIR_ROOM_MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "페어룸-멤버가 존재하지 않습니다."),
17+
INVALID_PROPERTIES_FORMAT(HttpStatus.BAD_REQUEST, "올바르지 않은 데이터 형식입니다."),
18+
INACTIVE_PAIR_ROOM(HttpStatus.BAD_REQUEST, "이미 종료되거나 삭제된 페어룸입니다.");
1719

1820
private final HttpStatus httpStatus;
1921
private final String message;

backend/src/main/java/site/coduo/pairroom/exception/DeletePairRoomException.java

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package site.coduo.pairroom.exception;
2+
3+
public class InactivePairRoomException extends PairRoomException {
4+
5+
public InactivePairRoomException(final String message) {
6+
super(message);
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package site.coduo.pairroom.exception;
2+
3+
public class NotFoundPairRoomSessionException extends PairRoomException {
4+
5+
public NotFoundPairRoomSessionException(final String message) {
6+
super(message);
7+
}
8+
}

backend/src/main/java/site/coduo/pairroom/repository/PairRoomEntity.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ public void swapNavigatorWithDriver() {
102102
this.driver = temp;
103103
}
104104

105-
public boolean isDelete() {
105+
public boolean isActive() {
106+
return status != PairRoomStatus.COMPLETED && status != PairRoomStatus.DELETED;
107+
}
108+
109+
public boolean isDeleted() {
106110
return status == PairRoomStatus.DELETED;
107111
}
108112

0 commit comments

Comments
 (0)