diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..d089d69 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,43 @@ +name: CD + +on: + push: + branches: + - main # main 브랜치 push 시 자동 배포 + workflow_dispatch: # 수동 실행 + +permissions: + contents: read + +env: + IMAGE: ${{ secrets.DOCKER_USERNAME }}/leftoversflirting + +jobs: + deploy: + name: Deploy to Server + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + # SSH로 서버에 접속해 배포 + - name: Deploy over SSH + uses: appleboy/ssh-action@v1.2.0 + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USER }} + key: ${{ secrets.SERVER_SSH_KEY }} + port: 22 + script: | + echo "[1/3] Pull latest Docker image..." + docker pull ${{ env.IMAGE }}:latest + + echo "[2/3] Restart container with new image..." + docker stop leftoversflirting || true + docker rm leftoversflirting || true + docker run -d --name leftoversflirting \ + -p 8080:8080 \ + ${{ env.IMAGE }}:latest + + echo "[3/3] Cleanup unused images..." + docker image prune -f \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1d0d5c0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,68 @@ +name: CI with Gradle + +on: + pull_request: + branches: ["main"] + push: + branches: ["main"] + workflow_dispatch: + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +env: + JAVA_VERSION: '21' + IMAGE: ${{ secrets.DOCKER_USERNAME }}/leftoversflirting + +jobs: + build: # 1) 빌드 전용 Job — PR과 push 모두 실행 + name: Build + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Temurin JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: ${{ env.JAVA_VERSION }} + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build JAR + run: ./gradlew bootJar -x test --no-daemon + + docker-push: + name: Docker Build & Push + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' + needs: build + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build & Push image + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: | + ${{ env.IMAGE }}:latest + ${{ env.IMAGE }}:${{ github.sha }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..71d8cc1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM eclipse-temurin:21-jre +WORKDIR /app +COPY build/libs/*.jar /app/app.jar +ENTRYPOINT ["java","-jar","/app/app.jar"] \ No newline at end of file diff --git a/src/main/java/com/example/Centralthon/domain/menu/exception/MenuErrorCode.java b/src/main/java/com/example/Centralthon/domain/menu/exception/MenuErrorCode.java deleted file mode 100644 index fe5c192..0000000 --- a/src/main/java/com/example/Centralthon/domain/menu/exception/MenuErrorCode.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.example.Centralthon.domain.menu.exception; - -import com.example.Centralthon.global.response.code.BaseResponseCode; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum MenuErrorCode implements BaseResponseCode { - MENU_NOT_FOUND("MENU_NOT_FOUND_404_1",404,"반경 내에 반찬 매물이 없습니다."); - - private final String code; - private final int httpStatus; - private final String message; -} diff --git a/src/main/java/com/example/Centralthon/domain/menu/exception/MenuNotFoundException.java b/src/main/java/com/example/Centralthon/domain/menu/exception/MenuNotFoundException.java deleted file mode 100644 index 8dbb4d1..0000000 --- a/src/main/java/com/example/Centralthon/domain/menu/exception/MenuNotFoundException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.example.Centralthon.domain.menu.exception; - -import com.example.Centralthon.global.exception.BaseException; - -public class MenuNotFoundException extends BaseException { - public MenuNotFoundException() { - super(MenuErrorCode.MENU_NOT_FOUND); - } -} diff --git a/src/main/java/com/example/Centralthon/domain/menu/service/MenuServiceImpl.java b/src/main/java/com/example/Centralthon/domain/menu/service/MenuServiceImpl.java index 12fc7f1..e404bd3 100644 --- a/src/main/java/com/example/Centralthon/domain/menu/service/MenuServiceImpl.java +++ b/src/main/java/com/example/Centralthon/domain/menu/service/MenuServiceImpl.java @@ -1,7 +1,6 @@ package com.example.Centralthon.domain.menu.service; import com.example.Centralthon.domain.menu.entity.Menu; -import com.example.Centralthon.domain.menu.exception.MenuNotFoundException; import com.example.Centralthon.domain.menu.repository.MenuRepository; import com.example.Centralthon.domain.menu.web.dto.NearbyMenusRes; import com.example.Centralthon.global.util.geo.BoundingBox;