diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 78a893d1..e7a1e28e 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -10,9 +10,12 @@ on: env: PROJECT_NAME: nabi - BUCKET_NAME: nabi-ci-cd-bucket - CODE_DEPLOY_APP_NAME: nabi-cicd - DEPLOYMENT_GROUP_NAME: nabi-instance-group + BUCKET_NAME: team-01-bucket + CODE_DEPLOY_APP_NAME: team01-codedeploy + DEPLOYMENT_GROUP_NAME: team01-instance-group + +permissions: + contents: read # workflow는 한개 이상의 job을 가지며, 각 job은 여러 step에 따라 단계를 나눌 수 있음 jobs: @@ -20,12 +23,9 @@ jobs: 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 @@ -34,13 +34,12 @@ jobs: distribution: 'temurin' # application.properties를 프로젝트에 포함 - - name: add Application.yml - run: touch ./src/main/resources/application.yml - shell: bash + - name: Make application.properties + run: | + cd ./src/main/resources + touch ./application.properties - - name: copy Application.yml - run: - echo "${{ secrets.APPLICATION_YML }}" > ./application.yml + echo "${{ secrets.DATABASE_PROPERTIES }}" >> ./application.properties shell: bash - name: Setup MySQL @@ -64,7 +63,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 +74,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://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip + # Deploy 실행 - name: Code Deploy To EC2 instance run: aws deploy create-deployment 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 & 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 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)); - } - } -}