diff --git a/.github/workflows/CD_Prod.yml b/.github/workflows/CD_Prod.yml new file mode 100644 index 0000000..4be97e8 --- /dev/null +++ b/.github/workflows/CD_Prod.yml @@ -0,0 +1,83 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle + +name: Java CD with Gradle + +on: + pull_request: + branches: [ "main" ] + +permissions: write-all + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + # 1) 워크플로우 실행 전 기본적으로 체크아웃 필요 + - uses: actions/checkout@v3 + + # 2) JDK 11 버전 설치 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + # 3) Gradle Caching + - name: Gradle Cashing + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + # 4) Gradle 권한 부여 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + # 5) Build exclude test package + #- name: Build with gradle + # run: ./gradlew build -x test + + # 6) Set for yml + - name: Make application-secret.yml + run: | + cd ./src/main/resources + touch ./application-secret.yml + echo "${{ secrets.PROPERTIES_TEST }}" > ./application-secret.yml + shell: bash + + # 7) 빌드 + - name: Build with gradle + run: ./gradlew bootJar + + # 8) Docker 빌드 & 푸쉬 + - name: docker build and push + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -f Dockerfile -t myongsik_prod1 . + docker tag myongsik_prod1 ${{ secrets.DOCKER_USERNAME }}/myongsik + docker push ${{ secrets.DOCKER_USERNAME }}/myongsik + + # 9) Deploy + - name: Deploy + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_KEY }} + script: | + docker stop myongsik_prod1 + docker rm myongsik_prod1 + sudo docker pull ${{ secrets.DOCKER_USERNAME }}/myongsik + sudo docker run -d --name myongsik_prod1 -v /etc/localtime:/etc/localtime:ro -e JAVA_OPTS=-Djasypt.encryptor.password=${{ secrets.YML_PASSWORD }} -e TZ=Asia/Seoul -e ENVIRONMENT_VALUE=-Dspring.profiles.active=prod -p 8081:8080 ${{ secrets.DOCKER_USERNAME }}/myongsik:latest + docker rmi -f $(docker images -f "dangling=true" -q) diff --git a/.github/workflows/CI-Dev.yml b/.github/workflows/CI_Dev.yml similarity index 100% rename from .github/workflows/CI-Dev.yml rename to .github/workflows/CI_Dev.yml diff --git a/src/test/java/com/example/myongsick/domain/food/service/FoodServiceImplTest.java b/src/test/java/com/example/myongsick/domain/food/service/FoodServiceImplTest.java new file mode 100644 index 0000000..62ca74b --- /dev/null +++ b/src/test/java/com/example/myongsick/domain/food/service/FoodServiceImplTest.java @@ -0,0 +1,43 @@ +package com.example.myongsick.domain.food.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +import com.example.myongsick.domain.food.dto.response.WeekFoodResponse; +import com.example.myongsick.domain.food.repository.DinnerRepository; +import com.example.myongsick.domain.food.repository.LunchRepository; +import com.example.myongsick.domain.food.repository.WeekRepository; +import java.util.List; +import java.util.NoSuchElementException; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +@SpringBootTest +class FoodServiceImplTest { + + @Autowired FoodServiceImpl foodService; + @Autowired WeekRepository weekRepository; + @Autowired DinnerRepository dinnerRepository; + @Autowired LunchRepository lunchRepository; + + @Test + @DisplayName("주간 식단 조회시, 값이 없는 경우 - 예외") + void 주간식단조회_NoSuchElement() { + // given + + // when + + // then + assertThrows(NoSuchElementException.class, () -> foodService.getWeekFoods()); + } + +// @Test +// @DisplayName("주간 식단 조회시, 값이 없는 경우 - 실패") +// void 주간식단조회_실패() { +// assertThrows(IndexOutOfBoundsException.class, () -> foodService.getWeekFoods()); +// } +} \ No newline at end of file