Skip to content

Commit

Permalink
Merge pull request #40 from MYONGSIK/develop
Browse files Browse the repository at this point in the history
main <- develop
  • Loading branch information
dldmsql authored Feb 7, 2023
2 parents 11e13c6 + c8207dc commit 72e4827
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/CD_Prod.yml
Original file line number Diff line number Diff line change
@@ -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)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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());
// }
}

0 comments on commit 72e4827

Please sign in to comment.