From 3a3f0322bf4682a329610811df0ab7ac3b18053d Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Fri, 17 Nov 2023 22:24:07 +0900 Subject: [PATCH 1/8] =?UTF-8?q?NABI-254--delete=20:=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../card/repository/CardRepositoryTest.java | 191 ------------------ 1 file changed, 191 deletions(-) delete mode 100644 src/test/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryTest.java diff --git a/src/test/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryTest.java b/src/test/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryTest.java deleted file mode 100644 index 6e7b587f..00000000 --- a/src/test/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryTest.java +++ /dev/null @@ -1,191 +0,0 @@ -package org.prgrms.nabimarketbe.domain.card.repository; - -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.prgrms.nabimarketbe.config.TestConfig; -import org.prgrms.nabimarketbe.domain.card.dto.response.wrapper.CardSuggestionResponseDTO; -import org.prgrms.nabimarketbe.domain.card.entity.Card; -import org.prgrms.nabimarketbe.domain.card.entity.TradeType; -import org.prgrms.nabimarketbe.domain.category.entity.Category; -import org.prgrms.nabimarketbe.domain.category.entity.CategoryEnum; -import org.prgrms.nabimarketbe.domain.category.repository.CategoryRepository; -import org.prgrms.nabimarketbe.domain.item.entity.Item; -import org.prgrms.nabimarketbe.domain.item.entity.PriceRange; -import org.prgrms.nabimarketbe.domain.item.repository.ItemRepository; -import org.prgrms.nabimarketbe.domain.suggestion.entity.SuggestionType; -import org.prgrms.nabimarketbe.domain.user.entity.User; -import org.prgrms.nabimarketbe.domain.user.repository.UserRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.context.annotation.Import; -import org.springframework.test.util.ReflectionTestUtils; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@Slf4j -@DataJpaTest -@Import(TestConfig.class) -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -class CardRepositoryTest { - @Autowired - private UserRepository userRepository; - - @Autowired - private CardRepository cardRepository; - - @Autowired - private CategoryRepository categoryRepository; - - @Autowired - private ItemRepository itemRepository; - - private static Long userId = 1L; - - @BeforeAll - void suggestionUserSetting() { - User user = User.builder() - .accountId("c") - .nickname("choi") - .imageUrl("xxx") - .provider("KAKAO") - .role("ROLE_USER") - .build(); - ReflectionTestUtils.setField(user, "userId", userId); - userRepository.save(user); - - Category category = new Category(CategoryEnum.ELECTRONICS); - categoryRepository.save(category); - - // under Item - Item itemFromChoiUnder = Item.builder() - .itemName("lg pad") - .priceRange(PriceRange.PRICE_RANGE_THREE) - .category(category) - .build(); - - Card cardFromChoiUnder = Card.builder() - .cardTitle("choi's card") - .thumbNailImage("xxx") - .content("xxx") - .tradeArea("seoul") - .poke(true) - .tradeType(TradeType.DIRECT_DEALING) - .item(itemFromChoiUnder) - .user(user) - .build(); - ReflectionTestUtils.setField(cardFromChoiUnder, "cardId", 1L); - - itemRepository.save(itemFromChoiUnder); - cardRepository.save(cardFromChoiUnder); - - // Over Item - Item itemFromChoiOver = Item.builder() - .itemName("lg TV") - .priceRange(PriceRange.PRICE_RANGE_FIVE) - .category(category) - .build(); - - Card cardFromChoiOver = Card.builder() - .cardTitle("choi's card") - .thumbNailImage("xxx") - .content("xxx") - .tradeArea("seoul") - .poke(true) - .tradeType(TradeType.DIRECT_DEALING) - .item(itemFromChoiOver) - .user(user) - .build(); - ReflectionTestUtils.setField(cardFromChoiOver, "cardId", 2L); - - itemRepository.save(itemFromChoiOver); - cardRepository.save(cardFromChoiOver); - } - - @Test - void 제안_가능한_카드_조회_찔러보기_허용인_경우() { - // given - Long suggestionUserId = userId; // 제안하고 있는 유저 id - - // 제안 대상이 되는 카드의 정보 - PriceRange targetCardPriceRange = PriceRange.PRICE_RANGE_FOUR; - Boolean targetCardPokeAvailable = true; // 찔러보기 혀용 - - // 반환 예상 값 - List expectCardList = new ArrayList<>(); - CardSuggestionResponseDTO card1 = new CardSuggestionResponseDTO(); - ReflectionTestUtils.setField(card1, "cardId", 1L); - ReflectionTestUtils.setField(card1, "thumbNail", "xxx"); - ReflectionTestUtils.setField(card1, "itemName", "lg pad"); - ReflectionTestUtils.setField(card1, "priceRange", PriceRange.PRICE_RANGE_THREE); - ReflectionTestUtils.setField(card1, "suggestionType", SuggestionType.POKE); - - CardSuggestionResponseDTO card2 = new CardSuggestionResponseDTO(); - ReflectionTestUtils.setField(card2, "cardId", 2L); - ReflectionTestUtils.setField(card2, "thumbNail", "xxx"); - ReflectionTestUtils.setField(card2, "itemName", "lg TV"); - ReflectionTestUtils.setField(card2, "priceRange", PriceRange.PRICE_RANGE_FIVE); - ReflectionTestUtils.setField(card2, "suggestionType", SuggestionType.OFFER); - - expectCardList.add(card1); - expectCardList.add(card2); - - // when - List actualCardList = cardRepository.getSuggestionAvailableCards( - suggestionUserId, - targetCardPriceRange, - targetCardPokeAvailable - ); - - // then - assertThat(expectCardList.size()).isEqualTo(actualCardList.size()); - - for (int i = 0; i < actualCardList.size(); i++) { - assertThat(expectCardList.get(i)) - .usingRecursiveComparison() - .isEqualTo(actualCardList.get(i)); - } - } - - @Test - void 제안_가능한_카드_조회_찔러보기_불가인_경우() { - // given - Long suggestionUserId = userId; // 제안하고 있는 유저 id - - // 제안 대상이 되는 카드의 정보 - PriceRange targetCardPriceRange = PriceRange.PRICE_RANGE_FOUR; - Boolean targetCardPokeAvailable = false; // 찔러보기 불가 - - // 반환 예상 값 - List expectCardList = new ArrayList<>(); - - CardSuggestionResponseDTO card1 = new CardSuggestionResponseDTO(); - ReflectionTestUtils.setField(card1, "cardId", 2L); - ReflectionTestUtils.setField(card1, "thumbNail", "xxx"); - ReflectionTestUtils.setField(card1, "itemName", "lg TV"); - ReflectionTestUtils.setField(card1, "priceRange", PriceRange.PRICE_RANGE_FIVE); - ReflectionTestUtils.setField(card1, "suggestionType", SuggestionType.OFFER); - - expectCardList.add(card1); - - // when - List actualCardList = cardRepository.getSuggestionAvailableCards( - suggestionUserId, - targetCardPriceRange, - targetCardPokeAvailable - ); - - // then - assertThat(expectCardList.size()).isEqualTo(actualCardList.size()); - - for (int i = 0; i < actualCardList.size(); i++) { - assertThat(expectCardList.get(i)) - .usingRecursiveComparison() - .isEqualTo(actualCardList.get(i)); - } - } -} From af152ca6a2c3007a2c4e38ef3b40b2836c87c7cc Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Fri, 17 Nov 2023 22:53:57 +0900 Subject: [PATCH 2/8] =?UTF-8?q?NABI-254--chore=20:=20CICD=20script=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/CICD.yml | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 78a893d1..290a8a36 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -10,22 +10,22 @@ on: env: PROJECT_NAME: nabi - BUCKET_NAME: nabi-ci-cd-bucket - CODE_DEPLOY_APP_NAME: nabi-cicd + BUCKET_NAME: team-01-bucket + CODE_DEPLOY_APP_NAME: nabi-market DEPLOYMENT_GROUP_NAME: nabi-instance-group +permissions: + contents: read + # workflow는 한개 이상의 job을 가지며, 각 job은 여러 step에 따라 단계를 나눌 수 있음 jobs: build: name: CI # 해당 jobs에서 아래의 steps들이 어떠한 환경에서 실행될 것인지를 지정 runs-on: ubuntu-20.04 - - # 해당 yml 내에서 사용할 key - value - steps: - # 작업에서 액세스할 수 있도록 $GITHUB_WORKSPACE에서 저장소를 체크아웃 + # 작업에서 액세스할 수 있도록 $GITHUB_WORKSPACE에서 저장소를 체크아웃 - uses: actions/checkout@v3 - name: Set up JDK 17 uses: actions/setup-java@v3 @@ -35,11 +35,8 @@ jobs: # application.properties를 프로젝트에 포함 - name: add Application.yml - run: touch ./src/main/resources/application.yml - shell: bash - - - name: copy Application.yml run: + touch ./src/main/resources/application.yml echo "${{ secrets.APPLICATION_YML }}" > ./application.yml shell: bash @@ -64,7 +61,7 @@ jobs: - name: Build with Gradle run: ./gradlew build shell: bash - + - name: Make zip file run: zip -r ./$GITHUB_SHA.zip . shell: bash @@ -75,15 +72,15 @@ jobs: aws-access-key-id: ${{ secrets.ACCESS_KEY }} aws-secret-access-key: ${{ secrets.SECRET_KEY }} aws-region: ap-northeast-2 - + # script files 복사 - name: Copy script run: cp ./scripts/*.sh ./deploy # S3에 빌드 결과 업로드 - name: Upload to S3 - run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip - + run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip + # Deploy 실행 - name: Code Deploy To EC2 instance run: aws deploy create-deployment From 669ef11dd9bfd57ad18bc9e34821c5966c1409d3 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Fri, 17 Nov 2023 22:55:26 +0900 Subject: [PATCH 3/8] =?UTF-8?q?NABI-254--chore=20:=20CICD=20script=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/CICD.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 290a8a36..dace6eba 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -36,7 +36,9 @@ jobs: # application.properties를 프로젝트에 포함 - name: add Application.yml run: - touch ./src/main/resources/application.yml + cd ./src/main/resources + touch ./application.yml + echo "${{ secrets.APPLICATION_YML }}" > ./application.yml shell: bash From 18f0f7b42f14ddba2147b67edfea59942ca5e0a8 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Fri, 17 Nov 2023 22:56:24 +0900 Subject: [PATCH 4/8] =?UTF-8?q?NABI-254--chore=20:=20CICD=20script=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index dace6eba..149c815a 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -35,7 +35,7 @@ jobs: # application.properties를 프로젝트에 포함 - name: add Application.yml - run: + run: | cd ./src/main/resources touch ./application.yml From ffee230e92bd55f94e5839c803296ad9bff59fc1 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Fri, 17 Nov 2023 23:04:56 +0900 Subject: [PATCH 5/8] =?UTF-8?q?NABI-254--chore=20:=20CICD=20script=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/CICD.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 149c815a..f47fd8b7 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -34,12 +34,12 @@ jobs: distribution: 'temurin' # application.properties를 프로젝트에 포함 - - name: add Application.yml + - name: Make application.properties run: | cd ./src/main/resources - touch ./application.yml - - echo "${{ secrets.APPLICATION_YML }}" > ./application.yml + touch ./application.properties + + echo "${{ secrets.DATABASE_PROPERTIES }}" >> ./application.properties shell: bash - name: Setup MySQL From d035ae4265b0a385346f4a552e499aa783b7ece4 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Fri, 17 Nov 2023 23:08:48 +0900 Subject: [PATCH 6/8] =?UTF-8?q?NABI-254--delete=20:=20=EB=AF=B8=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nabimarketbe/NabiMarketBeApplicationTest.java | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 src/test/java/org/prgrms/nabimarketbe/NabiMarketBeApplicationTest.java diff --git a/src/test/java/org/prgrms/nabimarketbe/NabiMarketBeApplicationTest.java b/src/test/java/org/prgrms/nabimarketbe/NabiMarketBeApplicationTest.java deleted file mode 100644 index aadb094f..00000000 --- a/src/test/java/org/prgrms/nabimarketbe/NabiMarketBeApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.prgrms.nabimarketbe; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -import static org.junit.jupiter.api.Assertions.*; - -@SpringBootTest -class NabiMarketBeApplicationTest { - @Test - void contextLoads() { - } -} \ No newline at end of file From 3dcd58e3f57f5d44b4106ca4271cc8ed539b1e0a Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Fri, 17 Nov 2023 23:16:26 +0900 Subject: [PATCH 7/8] =?UTF-8?q?NABI-254--chore=20:=20CICD=20script=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index f47fd8b7..09952925 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -81,7 +81,7 @@ jobs: # S3에 빌드 결과 업로드 - name: Upload to S3 - run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip + run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip # Deploy 실행 - name: Code Deploy To EC2 instance From 6768b95016d7ff9cc2f741d0cfaac690c1c228f8 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Fri, 17 Nov 2023 23:50:27 +0900 Subject: [PATCH 8/8] =?UTF-8?q?NABI-254--chore=20:=20CICD=20script,=20depl?= =?UTF-8?q?oy.sh=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/CICD.yml | 4 ++-- scripts/deploy.sh | 26 ++++++++++++-------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 09952925..e7a1e28e 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -11,8 +11,8 @@ on: env: PROJECT_NAME: nabi BUCKET_NAME: team-01-bucket - CODE_DEPLOY_APP_NAME: nabi-market - DEPLOYMENT_GROUP_NAME: nabi-instance-group + CODE_DEPLOY_APP_NAME: team01-codedeploy + DEPLOYMENT_GROUP_NAME: team01-instance-group permissions: contents: read diff --git a/scripts/deploy.sh b/scripts/deploy.sh index ed668ae8..1d4fda0b 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -1,24 +1,22 @@ -#!/bin/bash -BUILD_JAR=$(ls $REPOSITORY/build/libs/*.jar) -JAR_NAME=$(basename $BUILD_JAR) -echo "> build 파일명: $JAR_NAME" >> /home/ubuntu/action/deploy.log +#!/usr/bin/env bash -echo "> build 파일 복사" >> /home/ubuntu/action/deploy.log -DEPLOY_PATH=/home/ubuntu/action/ -cp $BUILD_JAR $DEPLOY_PATH +REPOSITORY=/home/ubuntu/nabi +cd $REPOSITORY -echo "> 현재 실행중인 애플리케이션 pid 확인" >> /home/ubuntu/action/deploy.log -CURRENT_PID=$(pgrep -f $JAR_NAME) +APP_NAME=nabi +JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep 'SNAPSHOT.jar' | tail -n 1) +JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME + +CURRENT_PID=$(pgrep -f $APP_NAME) if [ -z $CURRENT_PID ] then - echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ubuntu/action/deploy.log + echo "> 종료할 애플리케이션이 없습니다." else - echo "> kill -15 $CURRENT_PID" + echo "> kill -9 $CURRENT_PID" kill -15 $CURRENT_PID sleep 5 fi -DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME -echo "> DEPLOY_JAR 배포" >> /home/ubuntu/today/deploy.log -nohup java -jar $DEPLOY_JAR >> /home/ubuntu/today/deploy.log 2>/home/ubuntu/action/deploy_err.log & +echo "> Deploy - $JAR_PATH " +nohup java -jar $JAR_PATH > /dev/null 2> /dev/null < /dev/null &