Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

발표를 위한 테스트 PR #171

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
107 changes: 107 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Order-Deploy

on:
push:
branches:
- WB-299-api-server
types:
- closed
paths:
- "order/**"
- "common/**"

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Check if the pull request was merged
id: check_pr_merged
run: |
# Check if the PR was merged
if [[ "${{ github.event.pull_request.merged }}" == "true" ]]; then
echo "pr_merged=true" >> $GITHUB_ENV
else
echo "pr_merged=false" >> $GITHUB_ENV
fi

- name: Run some action if the PR was merged
if: env.pr_merged == 'true'
run: |
echo "The pull request was merged. Running additional actions..."

- uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17

- name: 💾 Cache Gradle & Spring
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Set YML
run: |
cd common
ls -l
mkdir -p src/main/resources
echo "${{ secrets.APPLICATION_LOCAL}}" | base64 --decode > src/main/resources/application-local.yml
echo "${{ secrets.APPLICATION_LOCAL_DB }}" | base64 --decode > src/main/resources/application-local-db.yml
echo "${{ secrets.APPLICATION_LOCAL_TOKEN }}" | base64 --decode > src/main/resources/application-local-token.yml

echo "${{ secrets.DEPLOY }}" | base64 --decode > src/main/resources/application-deploy.yml
echo "${{ secrets.DEPLOY_DB }}" | base64 --decode > src/main/resources/application-deploy-db.yml
echo "${{ secrets.DEPLOY_JWT_TOKEN }}" | base64 --decode > src/main/resources/application-deploy-token.yml
echo "${{ secrets.FIREBASE }}" | base64 --decode > src/main/resources/firebase.json
find src
cd ..

# Gradle wrapper 파일 실행 권한주기
- name: Grant execute permission for gradlew
run: chmod +x gradlew

# 애플리케이션을 Build 한다.
- name: 🔧 Build Spring server
run: |
chmod +x ./gradlew
./gradlew clean order:build

# 도커로 빌드한다.
- name: Docker build
run: |
cd /home/runner/work/Team5-WatermelonClap-BE/Team5-WatermelonClap-BE/order
docker login -u ${{secrets.DOCKER_USERNAME}} -p ${{secrets.DOCKER_PASSWORD}}
docker build --no-cache --platform linux/arm64/v8 -t app .

docker tag app ${{secrets.DOCKER_USERNAME}}/watermelon-api-order:latest
docker push ${{secrets.DOCKER_USERNAME}}/watermelon-api-order:latest

# aws 에 업로드한다.
- name: deploy in aws
uses: appleboy/ssh-action@master
with:
key: ${{secrets.SSH_KEY}}
host: ${{secrets.SSH_API_ORDER_HOST}}
username: ${{secrets.SSH_USER}}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/watermelon-api-order:latest
docker tag ${{ secrets.DOCKER_USERNAME }}/watermelon-api-order:latest watermelon-api-order:latest
docker stop $(docker ps -a -q)

docker run -i -d --log-driver=awslogs --log-opt awslogs-region=ap-northeast-2 --log-opt awslogs-group=watermelon-cloudwatch --log-opt awslogs-stream=watermelon-order -p 8092:8092 watermelon-api-order:latest


docker rm $(docker ps --filter 'status=exited' -a -q)
# 실행 중이지 않으 모든 컨테인 삭제
docker image prune -a -f
# 사용하지않은 모든 이미지 삭제
1 change: 1 addition & 0 deletions gateway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {
implementation 'io.grpc:grpc-netty:1.56.0'
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation 'io.projectreactor.tools:blockhound:1.0.8.RELEASE'
}

ext {
Expand Down
3 changes: 3 additions & 0 deletions gateway/src/main/java/com/watermelon/GatewayApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import reactor.blockhound.BlockHound;

@SpringBootApplication
public class GatewayApplication {

public static void main(String[] args) {
// BlockHound.install();
SpringApplication.run(GatewayApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public HikariDataSource orderResultDataSource() {
hikariConfig.setUsername(username);
hikariConfig.setPassword(password);
hikariConfig.setMaximumPoolSize(maximumPoolSize);
hikariConfig.setConnectionTimeout(250L);
hikariConfig.setConnectionTimeout(30000L);
hikariConfig.setPoolName("orderResultPool");
//orderEventQuiz만을 위한 설정 0.1초마다 확인
return new HikariDataSource(hikariConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ public boolean isOrderApplyNotFullThenPlusCount(){
orderApplyCountRepository.save(orderApplyCount);
return true;
}
if(!this.currentOrderEvent.getOrderEventStatus().equals(OrderEventStatus.CLOSED)){
makeEventClose();
}

// 여기서 CLOSED로 바꿀지 언정 실제 DB에는 저장되지 않음(currentOrderEvent는 DB에서 꺼내온 정보가 아님)
// 이 CLOSED는 REDIS를 읽는 작업을 줄여주기 위한 변수용
this.currentOrderEvent.setOrderEventStatus(OrderEventStatus.CLOSED);

return false;
}
private void makeEventClose() {
this.currentOrderEvent.setOrderEventStatus(OrderEventStatus.CLOSED);
}

@Transactional
public void refreshOrderEventInProgress(OrderEvent orderEventFromDB){
//동일한 이벤트라면
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ public class OrderResultCommandService {

public ResponseApplyTicketDto createTokenAndMakeTicket(Long orderEventId) {
String applyToken = applyTokenProvider.createTokenByOrderEventId(JwtPayload.from(String.valueOf(orderEventId)));
for(int i=0;i<toGetConnectionCount;i++) {
try{
if(orderResultSaveService.isOrderApplyNotFullThenSaveConnectionOpen(applyToken)){ // 커넥션이 열리는 메소드
return ResponseApplyTicketDto.applySuccess(applyToken);
}
return ResponseApplyTicketDto.fullApply();
}
catch (CannotCreateTransactionException e){
e.printStackTrace();
if(currentOrderEventManageService.isOrderApplyFull()){
return ResponseApplyTicketDto.fullApply();
}
}
// for(int i=0;i<toGetConnectionCount;i++) {
// try{
// if(orderResultSaveService.isOrderApplyNotFullThenSaveConnectionOpen(applyToken)){ // 커넥션이 열리는 메소드
// return ResponseApplyTicketDto.applySuccess(applyToken);
// }
// return ResponseApplyTicketDto.fullApply();
// }
// catch (CannotCreateTransactionException e){
// if(currentOrderEventManageService.isOrderApplyFull()){
// return ResponseApplyTicketDto.fullApply();
// }
// }
// }
if(orderResultSaveService.isOrderApplyNotFullThenSaveConnectionOpen(applyToken)){ // 커넥션이 열리는 메소드
return ResponseApplyTicketDto.applySuccess(applyToken);
}
return ResponseApplyTicketDto.fullApply();
}
Expand All @@ -58,7 +60,7 @@ public ResponseApplyTicketDto createTokenAndMakeTicket(Long orderEventId) {
public ResponseApplyTicketDto makeApplyTicket(RequestAnswerDto requestAnswerDto, Long orderEventId, Long quizId) throws NotDuringEventPeriodException, WrongOrderEventFormatException{
currentOrderEventManageService.checkingInfoErrors(orderEventId,quizId);
// 퀴즈 틀릴 시에ApplyNotFullThenSave())
if(currentOrderEventManageService.isOrderApplyFull()){ //
if(currentOrderEventManageService.isOrderApplyFull()){
return ResponseApplyTicketDto.fullApply();
}
if(!currentOrderEventManageService.checkPrevious(requestAnswerDto.getAnswer()))
Expand Down
Loading