From 45905397eb3c657b8fe51501edd4dc4962dcd973 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 16:08:22 +0900 Subject: [PATCH 01/60] Deploy to EC2 test1 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c1b09b5..5b3b83a 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -심심하다 +심심하다2 From 2dbbd31b566372289475544108b121c9e1f60326 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 16:11:11 +0900 Subject: [PATCH 02/60] Deploy to EC2 test2 --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 50dccb4..550753a 100644 --- a/readme.md +++ b/readme.md @@ -1 +1 @@ -배포 연습 +배포 연습2 From 59b73c60d1dad9083fb19dd717c702bdccb55ab6 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 16:12:10 +0900 Subject: [PATCH 03/60] Deploy to EC2 test3 --- .../java/com/devwiki/leafy/controller/user/UserController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java index bc19525..c13f573 100644 --- a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java +++ b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java @@ -50,7 +50,7 @@ public ResponseEntity getUserById(@PathVariable Long userId) { * @return 추가된 사용자 정보 */ @PostMapping("") - public ResponseEntity addUser(@RequestBody UserRequestDto userRequestDto) { + public ResponseEntity addUser(@Valid @RequestBody UserRequestDto userRequestDto) { UserResponseDto addedUserResponseDto = userService.createUser(userRequestDto); return new ResponseEntity<>(addedUserResponseDto, HttpStatus.CREATED); } From 508545e496eb27de7528ead855c2e4043337343b Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 16:15:42 +0900 Subject: [PATCH 04/60] Deploy to EC2 test4 --- leafy-backend/Dockerfile | 2 +- readme.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/leafy-backend/Dockerfile b/leafy-backend/Dockerfile index 7d2449c..3c4d2da 100644 --- a/leafy-backend/Dockerfile +++ b/leafy-backend/Dockerfile @@ -16,7 +16,7 @@ COPY . /app RUN gradle clean build --no-daemon # 런타임 이미지로 OpenJDK 11-jre-slim 지정 -FROM openjdk:11-jre-slim +FROM eclipse-temurin:11-jre # 애플리케이션을 실행할 작업 디렉토리를 생성 WORKDIR /app diff --git a/readme.md b/readme.md index 550753a..89fa3f3 100644 --- a/readme.md +++ b/readme.md @@ -1 +1 @@ -배포 연습2 +배포 연습4 From 58eca337b989cc8eef658a72c7e4217912284fff Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 16:17:18 +0900 Subject: [PATCH 05/60] Deploy to EC2 test5 --- leafy-backend/Dockerfile | 2 +- readme.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/leafy-backend/Dockerfile b/leafy-backend/Dockerfile index 3c4d2da..47d6896 100644 --- a/leafy-backend/Dockerfile +++ b/leafy-backend/Dockerfile @@ -1,5 +1,5 @@ # 빌드 이미지로 OpenJDK 11 & Gradle을 지정 -FROM gradle:7.6.1-jdk11 AS build +FROM eclipse-temurin:11-jre AS build # 소스코드를 복사할 작업 디렉토리를 생성 WORKDIR /app diff --git a/readme.md b/readme.md index 89fa3f3..2453e9c 100644 --- a/readme.md +++ b/readme.md @@ -1 +1 @@ -배포 연습4 +배포 연습5 From 717c69c4d45077b2205d97af1fff8ce8da190990 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 16:26:35 +0900 Subject: [PATCH 06/60] =?UTF-8?q?clipse-temurin:11=20=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- leafy-backend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leafy-backend/Dockerfile b/leafy-backend/Dockerfile index 47d6896..3c4d2da 100644 --- a/leafy-backend/Dockerfile +++ b/leafy-backend/Dockerfile @@ -1,5 +1,5 @@ # 빌드 이미지로 OpenJDK 11 & Gradle을 지정 -FROM eclipse-temurin:11-jre AS build +FROM gradle:7.6.1-jdk11 AS build # 소스코드를 복사할 작업 디렉토리를 생성 WORKDIR /app From 67b7a38d4eb0d919aea6b602b72f92a5c9a5dbbe Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 16:28:29 +0900 Subject: [PATCH 07/60] =?UTF-8?q?gradle:jdk11=20=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- leafy-backend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leafy-backend/Dockerfile b/leafy-backend/Dockerfile index 3c4d2da..f722a28 100644 --- a/leafy-backend/Dockerfile +++ b/leafy-backend/Dockerfile @@ -1,5 +1,5 @@ # 빌드 이미지로 OpenJDK 11 & Gradle을 지정 -FROM gradle:7.6.1-jdk11 AS build +FROM gradle:jdk11 AS build # 소스코드를 복사할 작업 디렉토리를 생성 WORKDIR /app From 9d34901831521d28da2e6416fa286c287e2095c8 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 16:29:36 +0900 Subject: [PATCH 08/60] =?UTF-8?q?cicd=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/leafy-backend-build-and-push.yml | 2 +- .github/workflows/leafy-frontend-build-and-push.yml | 2 +- .github/workflows/leafy-postgres-build-and-push.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index d192fd7..5d6755c 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -39,4 +39,4 @@ jobs: # Dockerfile의 경로입니다. push: true # 이미지를 레지스트리에 푸시합니다. tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ github.sha }} - platforms: linux/amd64,linux/arm64,windows/amd64 + platforms: linux/amd64,linux/arm64 diff --git a/.github/workflows/leafy-frontend-build-and-push.yml b/.github/workflows/leafy-frontend-build-and-push.yml index 5a0bbb8..0a702ba 100644 --- a/.github/workflows/leafy-frontend-build-and-push.yml +++ b/.github/workflows/leafy-frontend-build-and-push.yml @@ -40,5 +40,5 @@ jobs: push: true # 이미지를 레지스트리에 푸시합니다. tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:${{ github.sha }} - platforms: linux/amd64,linux/arm64,windows/amd64 + platforms: linux/amd64,linux/arm64 diff --git a/.github/workflows/leafy-postgres-build-and-push.yml b/.github/workflows/leafy-postgres-build-and-push.yml index b2fbd08..aeb88bf 100644 --- a/.github/workflows/leafy-postgres-build-and-push.yml +++ b/.github/workflows/leafy-postgres-build-and-push.yml @@ -41,5 +41,5 @@ jobs: # 이미지를 레지스트리에 푸시합니다. tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:${{ github.sha }} - platforms: linux/amd64,linux/arm64,windows/amd64 + platforms: linux/amd64,linux/arm64 From e89c51d404549856eb1d42c6917bd9a5e3770e5e Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 16:31:32 +0900 Subject: [PATCH 09/60] =?UTF-8?q?eclipse-temurin:11-jre=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- leafy-backend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leafy-backend/Dockerfile b/leafy-backend/Dockerfile index f722a28..f3392ae 100644 --- a/leafy-backend/Dockerfile +++ b/leafy-backend/Dockerfile @@ -15,7 +15,7 @@ COPY . /app # Gradle 빌드를 실행하여 JAR 파일 생성 RUN gradle clean build --no-daemon -# 런타임 이미지로 OpenJDK 11-jre-slim 지정 +# 런타임 이미지로 eclipse-temurin 11 JRE를 지정 FROM eclipse-temurin:11-jre # 애플리케이션을 실행할 작업 디렉토리를 생성 From 444e2caf739b25724086f23b775f503d7bd54021 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 16:50:25 +0900 Subject: [PATCH 10/60] =?UTF-8?q?valiid=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/devwiki/leafy/controller/user/UserController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java index c13f573..bc19525 100644 --- a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java +++ b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java @@ -50,7 +50,7 @@ public ResponseEntity getUserById(@PathVariable Long userId) { * @return 추가된 사용자 정보 */ @PostMapping("") - public ResponseEntity addUser(@Valid @RequestBody UserRequestDto userRequestDto) { + public ResponseEntity addUser(@RequestBody UserRequestDto userRequestDto) { UserResponseDto addedUserResponseDto = userService.createUser(userRequestDto); return new ResponseEntity<>(addedUserResponseDto, HttpStatus.CREATED); } From 9c57f119f90796c36b162d4ece74ed2a6abfa6ac Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 17:09:11 +0900 Subject: [PATCH 11/60] =?UTF-8?q?cicd=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-on-ec2.yml | 4 ++-- .github/workflows/leafy-backend-build-and-push.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-on-ec2.yml b/.github/workflows/deploy-on-ec2.yml index a237292..243905a 100644 --- a/.github/workflows/deploy-on-ec2.yml +++ b/.github/workflows/deploy-on-ec2.yml @@ -2,7 +2,7 @@ name: Deploy to EC2 on: workflow_run: - workflows: ["Backend Build and Push", "Frontend Build and Push"] + workflows: ["Backend-CI-Workflow", "Frontend Build and Push"] types: - completed branches: @@ -11,7 +11,7 @@ on: jobs: # --- 백엔드 배포 전용 Job --- deploy-backend: - if: ${{ github.event.workflow_run.workflow.name == 'Backend Build and Push' && github.event.workflow_run.conclusion == 'success' }} + if: ${{ github.event.workflow_run.workflow.name == 'Backend-CI-Workflow' && github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest steps: - name: Deploy Backend to EC2 instance diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index 5d6755c..30f7c44 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -1,4 +1,4 @@ -name: Backend Build and Push +name: Backend-CI-Workflow on: push: From 5a034514a7040be515e1e2b62ba75cfda089fb98 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 17:09:38 +0900 Subject: [PATCH 12/60] =?UTF-8?q?=EB=90=98=EB=9D=BC=20=EC=A0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/devwiki/leafy/controller/user/UserController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java index bc19525..c13f573 100644 --- a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java +++ b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java @@ -50,7 +50,7 @@ public ResponseEntity getUserById(@PathVariable Long userId) { * @return 추가된 사용자 정보 */ @PostMapping("") - public ResponseEntity addUser(@RequestBody UserRequestDto userRequestDto) { + public ResponseEntity addUser(@Valid @RequestBody UserRequestDto userRequestDto) { UserResponseDto addedUserResponseDto = userService.createUser(userRequestDto); return new ResponseEntity<>(addedUserResponseDto, HttpStatus.CREATED); } From 419bd894009744b2402ad7e3198e6a0f251085de Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 18:01:42 +0900 Subject: [PATCH 13/60] fast test --- .github/workflows/deploy-on-ec2.yml | 14 ++++++++++++-- .github/workflows/fast-test-ci.yml | 13 +++++++++++++ .github/workflows/leafy-backend-build-and-push.yml | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/fast-test-ci.yml diff --git a/.github/workflows/deploy-on-ec2.yml b/.github/workflows/deploy-on-ec2.yml index 243905a..0708a4b 100644 --- a/.github/workflows/deploy-on-ec2.yml +++ b/.github/workflows/deploy-on-ec2.yml @@ -2,16 +2,26 @@ name: Deploy to EC2 on: workflow_run: - workflows: ["Backend-CI-Workflow", "Frontend Build and Push"] + workflows: ["Backend Build and Push", "Frontend Build and Push"] types: - completed branches: - '08-cicd' jobs: + # --- 디버깅을 위한 Job --- + debug-event: + runs-on: ubuntu-latest + steps: + - name: Print workflow run event details + run: | + echo "이벤트를 발생시킨 워크플로우의 이름: --->${{ github.event.workflow_run.workflow.name }}<---" + echo "워크플로우의 결론: ${{ github.event.workflow_run.conclusion }}" + echo "전체 이벤트 내용:" + echo "${{ toJSON(github.event) }}" # --- 백엔드 배포 전용 Job --- deploy-backend: - if: ${{ github.event.workflow_run.workflow.name == 'Backend-CI-Workflow' && github.event.workflow_run.conclusion == 'success' }} + if: ${{ github.event.workflow_run.workflow.name == 'Backend Build and Push' && github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest steps: - name: Deploy Backend to EC2 instance diff --git a/.github/workflows/fast-test-ci.yml b/.github/workflows/fast-test-ci.yml new file mode 100644 index 0000000..be6ee9b --- /dev/null +++ b/.github/workflows/fast-test-ci.yml @@ -0,0 +1,13 @@ +# .github/workflows/fast-test-ci.yml + +name: Backend Build and Push # <-- 실제 CI 워크플로우의 name과 똑같이 만듭니다. + +on: + workflow_dispatch: # 수동 실행 버튼 추가 + +jobs: + fake-build: + runs-on: ubuntu-latest + steps: + - name: Fake build step + run: echo "This is a fast test CI run. It will succeed in 5 seconds." diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index 30f7c44..5d6755c 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -1,4 +1,4 @@ -name: Backend-CI-Workflow +name: Backend Build and Push on: push: From 694717c49578e3a0a0449088770c714c9ba453ed Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 18:09:01 +0900 Subject: [PATCH 14/60] permissions contents: read --- .github/workflows/fast-test-ci.yml | 3 +++ .github/workflows/leafy-backend-build-and-push.yml | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/fast-test-ci.yml b/.github/workflows/fast-test-ci.yml index be6ee9b..06f0c30 100644 --- a/.github/workflows/fast-test-ci.yml +++ b/.github/workflows/fast-test-ci.yml @@ -5,6 +5,9 @@ name: Backend Build and Push # <-- 실제 CI 워크플로우의 name과 똑같 on: workflow_dispatch: # 수동 실행 버튼 추가 +permissions: # <-- 이 블록을 추가합니다. + contents: read + jobs: fake-build: runs-on: ubuntu-latest diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index 5d6755c..273cc84 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -4,10 +4,12 @@ on: push: branches: - 08-cicd - # 08-cicd 브랜치에 push될 때 워크플로우가 실행됩니다. paths: - 'leafy-backend/**' - + +permissions: # <-- 이 블록을 추가합니다. + contents: read + jobs: build-and-push: runs-on: ubuntu-latest From 4c86aa39654181e367f6ed7a1da13f512a911f4f Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 18:18:01 +0900 Subject: [PATCH 15/60] =?UTF-8?q?=ED=86=B5=ED=95=A9=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leafy-backend-build-and-push.yml | 119 +++++++++++++----- 1 file changed, 85 insertions(+), 34 deletions(-) diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index 273cc84..9385819 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -1,44 +1,95 @@ -name: Backend Build and Push +# .github/workflows/leafy-backend-build-and-push.yml + +name: Backend CI/CD on: push: branches: - - 08-cicd + - '08-cicd' paths: - 'leafy-backend/**' - -permissions: # <-- 이 블록을 추가합니다. - contents: read + - '.github/workflows/leafy-backend-build-and-push.yml' jobs: - build-and-push: - runs-on: ubuntu-latest - # 가장 최신의 Ubuntu 러너를 사용합니다. - + # --- 1. 빌드 및 푸시 Job --- + build: + runs-on: ubuntu-latest + outputs: + sha_tag: ${{ steps.get_sha.outputs.sha }} steps: - - name: Checkout Repository - uses: actions/checkout@v2 - # 현재 리포지토리를 체크아웃합니다. + - name: Checkout Repository + uses: actions/checkout@v4 + - name: Get short commit sha + id: get_sha + run: echo "sha=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and Push Docker Image + uses: docker/build-push-action@v5 + with: + context: ./leafy-backend + file: ./leafy-backend/Dockerfile + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ steps.get_sha.outputs.sha }} + platforms: linux/amd64,linux/arm64 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - # Docker Buildx를 설정합니다. - - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - # GitHub Secret에서 Docker Hub 사용자 이름을 가져옵니다. - password: ${{ secrets.DOCKERHUB_TOKEN }} - # GitHub Secret에서 Docker Hub 액세스 토큰을 가져옵니다. - - - name: Build and Push - uses: docker/build-push-action@v2 - with: - context: ./leafy-backend - # Dockerfile이 있는 위치입니다. - file: ./leafy-backend/Dockerfile - # Dockerfile의 경로입니다. - push: true # 이미지를 레지스트리에 푸시합니다. - tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ github.sha }} - platforms: linux/amd64,linux/arm64 + # --- 2. 배포 Job --- + deploy: + needs: build + runs-on: ubuntu-latest + steps: + - name: Deploy to EC2 instance + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} + script: | + export IMAGE_TAG=${{ needs.build.outputs.sha_tag }} + export IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:$IMAGE_TAG + echo "Deploying image: $IMAGE_NAME" + + if [ ! -f docker-compose.yml ]; then + echo "Creating initial docker-compose.yml" + cat << EOF > docker-compose.yml + version: '3.8' + services: + leafy-postgres: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest + volumes: ["leafy_data:/var/lib/postgresql/data"] + restart: always + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + leafy-backend: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:initial + restart: on-failure + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/postgres + - SPRING_DATASOURCE_USERNAME=postgres + - SPRING_DATASOURCE_PASSWORD=postgres + depends_on: + leafy-postgres: { condition: service_healthy } + leafy-front: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:initial + restart: on-failure + ports: ["80:80"] + depends_on: ["leafy-backend"] + volumes: + leafy_data: + EOF + fi + + sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:.*|image: \$IMAGE_NAME|g" docker-compose.yml + + docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" + docker-compose pull leafy-backend + docker-compose up -d --remove-orphans + docker image prune -af From fbe45e695b5b58e62276bdaa2adf1913b95f99a0 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 18:38:42 +0900 Subject: [PATCH 16/60] =?UTF-8?q?=EB=8B=A4=EC=8B=9C=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20take=2010?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/devwiki/leafy/controller/user/UserController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java index c13f573..bc19525 100644 --- a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java +++ b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java @@ -50,7 +50,7 @@ public ResponseEntity getUserById(@PathVariable Long userId) { * @return 추가된 사용자 정보 */ @PostMapping("") - public ResponseEntity addUser(@Valid @RequestBody UserRequestDto userRequestDto) { + public ResponseEntity addUser(@RequestBody UserRequestDto userRequestDto) { UserResponseDto addedUserResponseDto = userService.createUser(userRequestDto); return new ResponseEntity<>(addedUserResponseDto, HttpStatus.CREATED); } From 2f643c615e205227dd9965deff95314bf2b9be3c Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 18:52:40 +0900 Subject: [PATCH 17/60] =?UTF-8?q?=EB=8B=A4=EC=8B=9C=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20take=2011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/leafy-backend-build-and-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index 9385819..84b1e45 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -84,7 +84,7 @@ jobs: depends_on: ["leafy-backend"] volumes: leafy_data: - EOF + EOF fi sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:.*|image: \$IMAGE_NAME|g" docker-compose.yml From 9db6af0458f3ea5bb188c93421bcd36900ec3bc3 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 19:33:08 +0900 Subject: [PATCH 18/60] =?UTF-8?q?=EB=8B=A4=EC=8B=9C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20take=2012?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-on-ec2.yml | 152 ------------------ .github/workflows/fast-test-ci.yml | 16 -- .../leafy-backend-build-and-push.yml | 54 +++---- .../leafy-frontend-build-and-push.yml | 80 +++++---- ...-build-and-push.yml => postgres-build.yml} | 0 5 files changed, 76 insertions(+), 226 deletions(-) delete mode 100644 .github/workflows/deploy-on-ec2.yml delete mode 100644 .github/workflows/fast-test-ci.yml rename .github/workflows/{leafy-postgres-build-and-push.yml => postgres-build.yml} (100%) diff --git a/.github/workflows/deploy-on-ec2.yml b/.github/workflows/deploy-on-ec2.yml deleted file mode 100644 index 0708a4b..0000000 --- a/.github/workflows/deploy-on-ec2.yml +++ /dev/null @@ -1,152 +0,0 @@ -name: Deploy to EC2 - -on: - workflow_run: - workflows: ["Backend Build and Push", "Frontend Build and Push"] - types: - - completed - branches: - - '08-cicd' - -jobs: - # --- 디버깅을 위한 Job --- - debug-event: - runs-on: ubuntu-latest - steps: - - name: Print workflow run event details - run: | - echo "이벤트를 발생시킨 워크플로우의 이름: --->${{ github.event.workflow_run.workflow.name }}<---" - echo "워크플로우의 결론: ${{ github.event.workflow_run.conclusion }}" - echo "전체 이벤트 내용:" - echo "${{ toJSON(github.event) }}" - # --- 백엔드 배포 전용 Job --- - deploy-backend: - if: ${{ github.event.workflow_run.workflow.name == 'Backend Build and Push' && github.event.workflow_run.conclusion == 'success' }} - runs-on: ubuntu-latest - steps: - - name: Deploy Backend to EC2 instance - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USERNAME }} - key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} - script: | - # EC2에 docker-compose.yml이 없다면 초기 버전을 생성 - if [ ! -f docker-compose.yml ]; then - echo "Creating initial docker-compose.yml" - cat << EOF > docker-compose.yml - version: '3.8' - services: - leafy-postgres: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest - volumes: - - leafy_data:/var/lib/postgresql/data - restart: always - healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] - interval: 5s - timeout: 5s - retries: 5 - leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:initial - restart: on-failure - environment: - - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/postgres - - SPRING_DATASOURCE_USERNAME=postgres - - SPRING_DATASOURCE_PASSWORD=postgres - depends_on: - leafy-postgres: - condition: service_healthy - leafy-front: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:initial - restart: on-failure - ports: - - "80:80" - depends_on: - - leafy-backend - volumes: - leafy_data: - EOF - fi - - # 1. 백엔드 이미지 태그만 최신 버전으로 변경 - export BACKEND_IMAGE=${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ github.event.workflow_run.head_sha }} - sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:.*|image: \$BACKEND_IMAGE|g" docker-compose.yml - - echo "Docker Hub Login..." - docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" - - echo "Pulling updated backend image..." - docker-compose pull leafy-backend - - echo "Restarting services..." - docker-compose up -d --remove-orphans - - echo "Pruning old images..." - docker image prune -af - - # --- 프론트엔드 배포 전용 Job --- - deploy-frontend: - if: ${{ github.event.workflow_run.workflow.name == 'Frontend Build and Push' && github.event.workflow_run.conclusion == 'success' }} - runs-on: ubuntu-latest - steps: - - name: Deploy Frontend to EC2 instance - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USERNAME }} - key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} - script: | - # EC2에 docker-compose.yml이 없다면 초기 버전을 생성 (위와 동일) - if [ ! -f docker-compose.yml ]; then - echo "Creating initial docker-compose.yml" - cat << EOF > docker-compose.yml - version: '3.8' - services: - leafy-postgres: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest - volumes: - - leafy_data:/var/lib/postgresql/data - restart: always - healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] - interval: 5s - timeout: 5s - retries: 5 - leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:initial - restart: on-failure - environment: - - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/postgres - - SPRING_DATASOURCE_USERNAME=postgres - - SPRING_DATASOURCE_PASSWORD=postgres - depends_on: - leafy-postgres: - condition: service_healthy - leafy-front: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:initial - restart: on-failure - ports: - - "80:80" - depends_on: - - leafy-backend - volumes: - leafy_data: - EOF - fi - - # 1. 프론트엔드 이미지 태그만 최신 버전으로 변경 - export FRONTEND_IMAGE=${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:${{ github.event.workflow_run.head_sha }} - sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:.*|image: \$FRONTEND_IMAGE|g" docker-compose.yml - - echo "Docker Hub Login..." - docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" - - echo "Pulling updated frontend image..." - docker-compose pull leafy-frontend - - echo "Restarting services..." - docker-compose up -d --remove-orphans - - echo "Pruning old images..." - docker image prune -af diff --git a/.github/workflows/fast-test-ci.yml b/.github/workflows/fast-test-ci.yml deleted file mode 100644 index 06f0c30..0000000 --- a/.github/workflows/fast-test-ci.yml +++ /dev/null @@ -1,16 +0,0 @@ -# .github/workflows/fast-test-ci.yml - -name: Backend Build and Push # <-- 실제 CI 워크플로우의 name과 똑같이 만듭니다. - -on: - workflow_dispatch: # 수동 실행 버튼 추가 - -permissions: # <-- 이 블록을 추가합니다. - contents: read - -jobs: - fake-build: - runs-on: ubuntu-latest - steps: - - name: Fake build step - run: echo "This is a fast test CI run. It will succeed in 5 seconds." diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index 84b1e45..da4128c 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -57,33 +57,33 @@ jobs: if [ ! -f docker-compose.yml ]; then echo "Creating initial docker-compose.yml" cat << EOF > docker-compose.yml - version: '3.8' - services: - leafy-postgres: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest - volumes: ["leafy_data:/var/lib/postgresql/data"] - restart: always - healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] - interval: 5s - timeout: 5s - retries: 5 - leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:initial - restart: on-failure - environment: - - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/postgres - - SPRING_DATASOURCE_USERNAME=postgres - - SPRING_DATASOURCE_PASSWORD=postgres - depends_on: - leafy-postgres: { condition: service_healthy } - leafy-front: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:initial - restart: on-failure - ports: ["80:80"] - depends_on: ["leafy-backend"] - volumes: - leafy_data: + version: '3.8' + services: + leafy-postgres: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest + volumes: ["leafy_data:/var/lib/postgresql/data"] + restart: always + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + leafy-backend: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:initial + restart: on-failure + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/postgres + - SPRING_DATASOURCE_USERNAME=postgres + - SPRING_DATASOURCE_PASSWORD=postgres + depends_on: + leafy-postgres: { condition: service_healthy } + leafy-front: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:initial + restart: on-failure + ports: ["80:80"] + depends_on: ["leafy-backend"] + volumes: + leafy_data: EOF fi diff --git a/.github/workflows/leafy-frontend-build-and-push.yml b/.github/workflows/leafy-frontend-build-and-push.yml index 0a702ba..49c132d 100644 --- a/.github/workflows/leafy-frontend-build-and-push.yml +++ b/.github/workflows/leafy-frontend-build-and-push.yml @@ -7,38 +7,56 @@ on: # 08-cicd 브랜치에 push될 때 워크플로우가 실행됩니다. paths: - 'leafy-frontend/**' + - '.github/workflows/leafy-frontend-build-and-push.yml' jobs: - build-and-push: - runs-on: ubuntu-latest - # 가장 최신의 Ubuntu 러너를 사용합니다. - + # --- 1. 빌드 및 푸시 Job --- + build: + runs-on: ubuntu-latest + outputs: + sha_tag: ${{ steps.get_sha.outputs.sha }} steps: - - name: Checkout Repository - uses: actions/checkout@v2 - # 현재 리포지토리를 체크아웃합니다. - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - # Docker Buildx를 설정합니다. - - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - # GitHub Secret에서 Docker Hub 사용자 이름을 가져옵니다. - password: ${{ secrets.DOCKERHUB_TOKEN }} - # GitHub Secret에서 Docker Hub 액세스 토큰을 가져옵니다. - - - name: Build and Push - uses: docker/build-push-action@v2 - with: - context: ./leafy-frontend - # Dockerfile이 있는 위치입니다. - file: ./leafy-frontend/Dockerfile - # Dockerfile의 경로입니다. - push: true - # 이미지를 레지스트리에 푸시합니다. - tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:${{ github.sha }} - platforms: linux/amd64,linux/arm64 + - name: Checkout Repository + uses: actions/checkout@v4 + - name: Get short commit sha + id: get_sha + run: echo "sha=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and Push Docker Image + uses: docker/build-push-action@v5 + with: + context: ./leafy-frontend + file: ./leafy-frontend/Dockerfile + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:${{ steps.get_sha.outputs.sha }} + platforms: linux/amd64 + # --- 2. 배포 Job --- + deploy: + needs: build + runs-on: ubuntu-latest + steps: + - name: Deploy to EC2 instance + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} + script: | + export IMAGE_TAG=${{ needs.build.outputs.sha_tag }} + export IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:$IMAGE_TAG + + echo "Deploying image: $IMAGE_NAME" + + sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:.*|image: \$IMAGE_NAME|g" docker-compose.yml + + docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" + docker-compose pull leafy-frontend + docker-compose up -d --remove-orphans + docker image prune -af diff --git a/.github/workflows/leafy-postgres-build-and-push.yml b/.github/workflows/postgres-build.yml similarity index 100% rename from .github/workflows/leafy-postgres-build-and-push.yml rename to .github/workflows/postgres-build.yml From 32b14a62759f7abf82d588b7daab25da83b3c8bf Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 20:39:47 +0900 Subject: [PATCH 19/60] =?UTF-8?q?=EB=8B=A4=EC=8B=9C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20take=2015?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/devwiki/leafy/controller/user/UserController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java index bc19525..c13f573 100644 --- a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java +++ b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java @@ -50,7 +50,7 @@ public ResponseEntity getUserById(@PathVariable Long userId) { * @return 추가된 사용자 정보 */ @PostMapping("") - public ResponseEntity addUser(@RequestBody UserRequestDto userRequestDto) { + public ResponseEntity addUser(@Valid @RequestBody UserRequestDto userRequestDto) { UserResponseDto addedUserResponseDto = userService.createUser(userRequestDto); return new ResponseEntity<>(addedUserResponseDto, HttpStatus.CREATED); } From 99acd0c7d3585cef19bf2bb14d21318b88a9814a Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 22:06:19 +0900 Subject: [PATCH 20/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2016?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 70 +++++++++++++++++++ .../leafy-backend-build-and-push.yml | 6 +- .github/workflows/postgres-build.yml | 59 +++++++--------- leafy-postgresql/Dockerfile | 4 -- 4 files changed, 98 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/initial-setup.yml diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml new file mode 100644 index 0000000..b6e9357 --- /dev/null +++ b/.github/workflows/initial-setup.yml @@ -0,0 +1,70 @@ +# .github/workflows/initial-setup.yml + +name: Initial EC2 Setup + +on: + workflow_dispatch: + inputs: + postgres_tag: + description: '배포할 Postgres 이미지 태그 (commit sha)' + required: true + +jobs: + setup: + runs-on: ubuntu-latest + steps: + - name: Setup EC2 instance + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} + script: | + # Docker 및 Docker Compose 설치 + if ! command -v docker &> /dev/null; then + echo "Installing Docker..." + sudo apt-get update && sudo apt-get install -y docker.io + sudo systemctl start docker && sudo systemctl enable docker + sudo usermod -aG docker ${{ secrets.EC2_USERNAME }} + sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + fi + + # docker-compose.yml 파일 생성 + cat << 'EOF' > docker-compose.yml + version: '3.8' + services: + leafy-postgres: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:${{ github.event.inputs.postgres_tag || 'latest' }} + environment: + - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} + - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} + - POSTGRES_DB=postgres # DB 이름은 보통 고정값이므로 직접 입력 + ports: + - "5432:5432" + volumes: + - leafy_data:/var/lib/postgresql/data + restart: always + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + leafy-backend: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:initial + restart: on-failure + depends_on: + leafy-postgres: { condition: service_healthy } + leafy-front: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:initial + restart: on-failure + ports: ["80:80"] + depends_on: ["leafy-backend"] + volumes: + leafy_data: + EOF + + # Postgres 서비스 시작 + docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" + docker-compose pull leafy-postgres + docker-compose up -d diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index da4128c..7b34482 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -72,9 +72,9 @@ jobs: image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:initial restart: on-failure environment: - - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/postgres - - SPRING_DATASOURCE_USERNAME=postgres - - SPRING_DATASOURCE_PASSWORD=postgres + - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} + - SPRING_DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} + - SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} depends_on: leafy-postgres: { condition: service_healthy } leafy-front: diff --git a/.github/workflows/postgres-build.yml b/.github/workflows/postgres-build.yml index aeb88bf..7911f67 100644 --- a/.github/workflows/postgres-build.yml +++ b/.github/workflows/postgres-build.yml @@ -1,45 +1,36 @@ +# .github/workflows/postgres-build.yml + name: Postgres Build and Push on: push: branches: - - 08-cicd - # 08-cicd 브랜치에 push될 때 워크플로우가 실행됩니다. + - '08-cicd' paths: - 'leafy-postgresql/**' + - '.github/workflows/postgres-build.yml' jobs: build-and-push: - runs-on: ubuntu-latest - # 가장 최신의 Ubuntu 러너를 사용합니다. - + runs-on: ubuntu-latest steps: - - name: Checkout Repository - uses: actions/checkout@v2 - # 현재 리포지토리를 체크아웃합니다. - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - # Docker Buildx를 설정합니다. - - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - # GitHub Secret에서 Docker Hub 사용자 이름을 가져옵니다. - password: ${{ secrets.DOCKERHUB_TOKEN }} - # GitHub Secret에서 Docker Hub 액세스 토큰을 가져옵니다. - - - name: Build and Push - uses: docker/build-push-action@v2 - with: - context: ./leafy-postgresql - # Dockerfile이 있는 위치입니다. - file: ./leafy-postgresql/Dockerfile - # Dockerfile의 경로입니다. - push: true - # 이미지를 레지스트리에 푸시합니다. - tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:${{ github.sha }} - - platforms: linux/amd64,linux/arm64 - + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and Push + uses: docker/build-push-action@v5 + with: + context: ./leafy-postgresql + file: ./leafy-postgresql/Dockerfile + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:${{ github.sha }} + platforms: linux/amd64,linux/arm64 diff --git a/leafy-postgresql/Dockerfile b/leafy-postgresql/Dockerfile index 32a00bc..4c4c6ec 100644 --- a/leafy-postgresql/Dockerfile +++ b/leafy-postgresql/Dockerfile @@ -7,10 +7,6 @@ COPY ./init/init.sql /docker-entrypoint-initdb.d/ #postgresql.conf파일을 /etc/postgresql/postgresql.conf 로 복사, 기본 설정 파일을 덮어쓰기하여 새로운 설정 적용 COPY ./config/postgresql.conf /etc/postgresql/custom.conf -#계정정보 설정 -ENV POSTGRES_USER=myuser -ENV POSTGRES_PASSWORD=mypassword -ENV POSTGRES_DB=mydb EXPOSE 5432 From bcef1f5424d67fd6935d1a4586b2e00d4e4abd45 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 22:13:42 +0900 Subject: [PATCH 21/60] =?UTF-8?q?init=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 36 ++++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index b6e9357..c7b10f1 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -1,5 +1,4 @@ # .github/workflows/initial-setup.yml - name: Initial EC2 Setup on: @@ -20,26 +19,29 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} script: | - # Docker 및 Docker Compose 설치 + # --- 1. Docker 및 Docker Compose 설치 (Ubuntu 기준) --- if ! command -v docker &> /dev/null; then echo "Installing Docker..." - sudo apt-get update && sudo apt-get install -y docker.io - sudo systemctl start docker && sudo systemctl enable docker + sudo apt-get update + sudo apt-get install -y docker.io + sudo systemctl start docker + sudo systemctl enable docker sudo usermod -aG docker ${{ secrets.EC2_USERNAME }} sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose fi - # docker-compose.yml 파일 생성 + # --- 2. docker-compose.yml 파일 생성 (검증된 버전) --- + echo "Creating docker-compose.yml..." cat << 'EOF' > docker-compose.yml version: '3.8' services: leafy-postgres: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:${{ github.event.inputs.postgres_tag || 'latest' }} - environment: - - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} - - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} - - POSTGRES_DB=postgres # DB 이름은 보통 고정값이므로 직접 입력 + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:${{ github.event.inputs.postgres_tag }} + environment: + - POSTGRES_USER={{ secrets.DATABASE_USER }} + - POSTGRES_PASSWORD={{ secrets.DATABASE_PASSWORD }} + - POSTGRES_DB={{ secrets.DATABASE_NAME }} ports: - "5432:5432" volumes: @@ -54,17 +56,23 @@ jobs: image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:initial restart: on-failure depends_on: - leafy-postgres: { condition: service_healthy } + leafy-postgres: + condition: service_healthy leafy-front: image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:initial restart: on-failure - ports: ["80:80"] - depends_on: ["leafy-backend"] + ports: + - "80:80" + depends_on: + - leafy-backend volumes: leafy_data: EOF - # Postgres 서비스 시작 + # --- 3. Postgres 서비스 시작 --- + echo "Starting Postgres service..." docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" docker-compose pull leafy-postgres docker-compose up -d + + echo "Initial setup complete. Postgres is running." From 40253a01a6a215fe6edfbe5bd9f4ee483fb7523d Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 22:20:13 +0900 Subject: [PATCH 22/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2017?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/devwiki/leafy/controller/user/UserController.java | 2 +- leafy-frontend/src/App.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java index c13f573..bc19525 100644 --- a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java +++ b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java @@ -50,7 +50,7 @@ public ResponseEntity getUserById(@PathVariable Long userId) { * @return 추가된 사용자 정보 */ @PostMapping("") - public ResponseEntity addUser(@Valid @RequestBody UserRequestDto userRequestDto) { + public ResponseEntity addUser(@RequestBody UserRequestDto userRequestDto) { UserResponseDto addedUserResponseDto = userService.createUser(userRequestDto); return new ResponseEntity<>(addedUserResponseDto, HttpStatus.CREATED); } diff --git a/leafy-frontend/src/App.vue b/leafy-frontend/src/App.vue index 2805b0f..c448630 100644 --- a/leafy-frontend/src/App.vue +++ b/leafy-frontend/src/App.vue @@ -2,7 +2,7 @@

안녕하세요, {{ user.name }}님!

-

어제는 즐거운 식물 관리하셨나요?

+

오늘도 즐거운 식물 관리하세요.

LEAFY From b06d68a6e5b79e1c10689c847342ae0a6078cedc Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 22:23:26 +0900 Subject: [PATCH 23/60] =?UTF-8?q?set=20up=20=EC=88=98=EC=A0=95=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index c7b10f1..84a779a 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -1,4 +1,3 @@ -# .github/workflows/initial-setup.yml name: Initial EC2 Setup on: @@ -19,7 +18,7 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} script: | - # --- 1. Docker 및 Docker Compose 설치 (Ubuntu 기준) --- + # --- 1. Docker 및 Docker Compose 설치 --- if ! command -v docker &> /dev/null; then echo "Installing Docker..." sudo apt-get update @@ -31,7 +30,7 @@ jobs: sudo chmod +x /usr/local/bin/docker-compose fi - # --- 2. docker-compose.yml 파일 생성 (검증된 버전) --- + # --- 2. docker-compose.yml 파일 생성 --- echo "Creating docker-compose.yml..." cat << 'EOF' > docker-compose.yml version: '3.8' @@ -39,9 +38,9 @@ jobs: leafy-postgres: image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:${{ github.event.inputs.postgres_tag }} environment: - - POSTGRES_USER={{ secrets.DATABASE_USER }} - - POSTGRES_PASSWORD={{ secrets.DATABASE_PASSWORD }} - - POSTGRES_DB={{ secrets.DATABASE_NAME }} + - POSTGRES_USER=${{ DATASOURCE_USERNAME }} + - POSTGRES_PASSWORD=${{ DATASOURCE_PASSWORD }} + - POSTGRES_DB=${{ DATASOURCE_DBNAME }} ports: - "5432:5432" volumes: @@ -72,7 +71,9 @@ jobs: # --- 3. Postgres 서비스 시작 --- echo "Starting Postgres service..." docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" - docker-compose pull leafy-postgres - docker-compose up -d - echo "Initial setup complete. Postgres is running." + # sudo를 추가하여 권한 문제 해결 + sudo docker-compose pull leafy-postgres + sudo docker-compose up -d + + echo "Initial setup complete. Services are starting." From 92f7d6932cf601d6d6d9aaecfd46ca395b3849ce Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 22:24:28 +0900 Subject: [PATCH 24/60] =?UTF-8?q?set=20up=20=EC=88=98=EC=A0=95=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 6 +++--- readme.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index 84a779a..4908902 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -38,9 +38,9 @@ jobs: leafy-postgres: image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:${{ github.event.inputs.postgres_tag }} environment: - - POSTGRES_USER=${{ DATASOURCE_USERNAME }} - - POSTGRES_PASSWORD=${{ DATASOURCE_PASSWORD }} - - POSTGRES_DB=${{ DATASOURCE_DBNAME }} + - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} + - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} + - POSTGRES_DB=${{ secrets.DATASOURCE_DBNAME }} ports: - "5432:5432" volumes: diff --git a/readme.md b/readme.md index 2453e9c..5b3b83a 100644 --- a/readme.md +++ b/readme.md @@ -1 +1 @@ -배포 연습5 +심심하다2 From 327516a3cde0ee444b8130fa3c3bd116b98cb4b5 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 22:32:26 +0900 Subject: [PATCH 25/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2018?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leafy-frontend-build-and-push.yml | 54 ++++++++++++++++--- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/.github/workflows/leafy-frontend-build-and-push.yml b/.github/workflows/leafy-frontend-build-and-push.yml index 49c132d..a181f09 100644 --- a/.github/workflows/leafy-frontend-build-and-push.yml +++ b/.github/workflows/leafy-frontend-build-and-push.yml @@ -1,16 +1,15 @@ name: Frontend Build and Push +# .github/workflows/frontend-cicd.yml on: push: branches: - - 08-cicd - # 08-cicd 브랜치에 push될 때 워크플로우가 실행됩니다. + - '08-cicd' paths: - 'leafy-frontend/**' - '.github/workflows/leafy-frontend-build-and-push.yml' jobs: - # --- 1. 빌드 및 푸시 Job --- build: runs-on: ubuntu-latest outputs: @@ -37,7 +36,6 @@ jobs: tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:${{ steps.get_sha.outputs.sha }} platforms: linux/amd64 - # --- 2. 배포 Job --- deploy: needs: build runs-on: ubuntu-latest @@ -53,10 +51,50 @@ jobs: export IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:$IMAGE_TAG echo "Deploying image: $IMAGE_NAME" + + # docker-compose.yml 파일이 없을 경우를 대비한 초기 생성 스크립트 추가 + if [ ! -f docker-compose.yml ]; then + echo "Creating initial docker-compose.yml" + cat << 'EOF' > docker-compose.yml + version: '3.8' + services: + leafy-postgres: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest + ports: + - "5432:5432" + environment: + - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} + - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} + - POSTGRES_DB=postgres + volumes: + - leafy_data:/var/lib/postgresql/data + restart: always + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + leafy-backend: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:initial + restart: on-failure + depends_on: + leafy-postgres: + condition: service_healthy + leafy-front: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:initial + restart: on-failure + ports: + - "80:80" + depends_on: + - leafy-backend + volumes: + leafy_data: + EOF + fi sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:.*|image: \$IMAGE_NAME|g" docker-compose.yml - docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" - docker-compose pull leafy-frontend - docker-compose up -d --remove-orphans - docker image prune -af + sudo docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" + sudo docker-compose pull leafy-frontend + sudo docker-compose up -d --remove-orphans + sudo docker image prune -af From 6b479e9688709f2fd2d6daf8d6c212d6b45cd75c Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 22:37:24 +0900 Subject: [PATCH 26/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2019?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leafy-frontend-build-and-push.yml | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/.github/workflows/leafy-frontend-build-and-push.yml b/.github/workflows/leafy-frontend-build-and-push.yml index a181f09..1f9812a 100644 --- a/.github/workflows/leafy-frontend-build-and-push.yml +++ b/.github/workflows/leafy-frontend-build-and-push.yml @@ -56,40 +56,40 @@ jobs: if [ ! -f docker-compose.yml ]; then echo "Creating initial docker-compose.yml" cat << 'EOF' > docker-compose.yml - version: '3.8' - services: - leafy-postgres: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest - ports: - - "5432:5432" - environment: - - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} - - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} - - POSTGRES_DB=postgres - volumes: - - leafy_data:/var/lib/postgresql/data - restart: always - healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] - interval: 5s - timeout: 5s - retries: 5 - leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:initial - restart: on-failure - depends_on: - leafy-postgres: - condition: service_healthy - leafy-front: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:initial - restart: on-failure - ports: - - "80:80" - depends_on: - - leafy-backend - volumes: - leafy_data: - EOF + version: '3.8' + services: + leafy-postgres: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest + ports: + - "5432:5432" + environment: + - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} + - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} + - POSTGRES_DB=postgres + volumes: + - leafy_data:/var/lib/postgresql/data + restart: always + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + leafy-backend: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:initial + restart: on-failure + depends_on: + leafy-postgres: + condition: service_healthy + leafy-front: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:initial + restart: on-failure + ports: + - "80:80" + depends_on: + - leafy-backend + volumes: + leafy_data: + EOF fi sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:.*|image: \$IMAGE_NAME|g" docker-compose.yml From c1657c3b2741c73e5f4fb7ea1755206ccf210694 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 22:47:13 +0900 Subject: [PATCH 27/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2020?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/devwiki/leafy/controller/user/UserController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java index bc19525..c13f573 100644 --- a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java +++ b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java @@ -50,7 +50,7 @@ public ResponseEntity getUserById(@PathVariable Long userId) { * @return 추가된 사용자 정보 */ @PostMapping("") - public ResponseEntity addUser(@RequestBody UserRequestDto userRequestDto) { + public ResponseEntity addUser(@Valid @RequestBody UserRequestDto userRequestDto) { UserResponseDto addedUserResponseDto = userService.createUser(userRequestDto); return new ResponseEntity<>(addedUserResponseDto, HttpStatus.CREATED); } From 6d12fe41249160ac6ba6f8ddc71e97f8873cc4bf Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 23:04:25 +0900 Subject: [PATCH 28/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2021?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/postgres-build.yml | 5 ++++- leafy-postgresql/init/init.sql | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/postgres-build.yml b/.github/workflows/postgres-build.yml index 7911f67..5ab36a9 100644 --- a/.github/workflows/postgres-build.yml +++ b/.github/workflows/postgres-build.yml @@ -32,5 +32,8 @@ jobs: context: ./leafy-postgresql file: ./leafy-postgresql/Dockerfile push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:${{ github.sha }} + tags: | + ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:${{ github.sha }} + ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest + platforms: linux/amd64,linux/arm64 diff --git a/leafy-postgresql/init/init.sql b/leafy-postgresql/init/init.sql index df6acfa..812544d 100644 --- a/leafy-postgresql/init/init.sql +++ b/leafy-postgresql/init/init.sql @@ -56,7 +56,7 @@ CREATE TABLE plant_logs ( -- $2a$10$ke3IM6noeWfQtX6POjZHl.49gSolYbqfrSTIn8sOQubdwjP2IT94q = password789 INSERT INTO users (name, email, password, gender, birth_date) VALUES ('John', 'john123@qmail.com', '$2a$10$vYR4pPQqR/oZcUDZfXrahecEejQHY0kLkDB5s.FctPRMcEMh1PYhG', 'M', '1988-05-01'), -('Juna', 'juna123@qmail.com', '$2a$10$vYR4pPQqR/oZcUDZfXrahecEejQHY0kLkDB5s.FctPRMcEMh1PYhG', 'F', '2001-01-24'), +('Juna', 'juna123@qmail.com', '$2a$10$vYR4pPQqR/oZcUDZfXrahecEejQHY0kLkDB5s.FctPRMcEMh1PYhG', 'M', '2001-01-24'), ('Peter', 'peter789@qmail.com', '$2a$10$vYR4pPQqR/oZcUDZfXrahecEejQHY0kLkDB5s.FctPRMcEMh1PYhG', 'M', '1981-12-25'), ('Susan', 'susan321@qmail.com', '$2a$10$vYR4pPQqR/oZcUDZfXrahecEejQHY0kLkDB5s.FctPRMcEMh1PYhG', 'F', '1990-06-02'), ('David', 'david654@qmail.com', '$2a$10$vYR4pPQqR/oZcUDZfXrahecEejQHY0kLkDB5s.FctPRMcEMh1PYhG', 'M', '1992-03-11'), From 046feef44b04400f54e4abeed34fa98fed2a97c4 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 23:05:42 +0900 Subject: [PATCH 29/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2022=20-=20Initial=20EC2=20Setup=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index 4908902..5efcf54 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -2,10 +2,7 @@ name: Initial EC2 Setup on: workflow_dispatch: - inputs: - postgres_tag: - description: '배포할 Postgres 이미지 태그 (commit sha)' - required: true + jobs: setup: @@ -36,7 +33,7 @@ jobs: version: '3.8' services: leafy-postgres: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:${{ github.event.inputs.postgres_tag }} + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest environment: - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} From ff42590d412ef8b75ec8ca3ed4b5e4505c3c6ea0 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 23:09:42 +0900 Subject: [PATCH 30/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2025=20-=20edit=20sudo=20docker-compose=20pull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index 5efcf54..90280cc 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -70,7 +70,7 @@ jobs: docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" # sudo를 추가하여 권한 문제 해결 - sudo docker-compose pull leafy-postgres + sudo docker-compose pull sudo docker-compose up -d echo "Initial setup complete. Services are starting." From 728dd1212c3da76374b36dafc613952475c0f339 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 23:14:24 +0900 Subject: [PATCH 31/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2026=20-=20compose=EC=97=90=EC=84=9C=20front=20back=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index 90280cc..4f0ab9c 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -37,7 +37,6 @@ jobs: environment: - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} - - POSTGRES_DB=${{ secrets.DATASOURCE_DBNAME }} ports: - "5432:5432" volumes: @@ -48,19 +47,6 @@ jobs: interval: 5s timeout: 5s retries: 5 - leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:initial - restart: on-failure - depends_on: - leafy-postgres: - condition: service_healthy - leafy-front: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:initial - restart: on-failure - ports: - - "80:80" - depends_on: - - leafy-backend volumes: leafy_data: EOF @@ -70,7 +56,7 @@ jobs: docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" # sudo를 추가하여 권한 문제 해결 - sudo docker-compose pull - sudo docker-compose up -d + sudo docker-compose pull leafy-postgres + sudo docker-compose up -d leafy-postgres echo "Initial setup complete. Services are starting." From e956ab8c39bb536541e794efe2bf46075389dda9 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 23:16:46 +0900 Subject: [PATCH 32/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2027=20-=20backend=20=EB=B0=B0=ED=8F=AC=20=EC=8B=9C=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/devwiki/leafy/controller/user/UserController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java index c13f573..fcf5216 100644 --- a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java +++ b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java @@ -13,6 +13,7 @@ import javax.validation.Valid; import java.util.List; + @RestController @RequestMapping("/api/v1/users") @RequiredArgsConstructor From dde9d01a7f37344332f3bccb96cc65b5eb83f3b6 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Sun, 21 Sep 2025 23:57:23 +0900 Subject: [PATCH 33/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2028=20-=20front=20=EB=B0=B0=ED=8F=AC=20=EC=8B=9C=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- leafy-frontend/src/App.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leafy-frontend/src/App.vue b/leafy-frontend/src/App.vue index c448630..19aac0f 100644 --- a/leafy-frontend/src/App.vue +++ b/leafy-frontend/src/App.vue @@ -2,7 +2,7 @@

안녕하세요, {{ user.name }}님!

-

오늘도 즐거운 식물 관리하세요.

+

오늘도 즐거운 식물 관리하세요 !!

LEAFY From c0b8a9474aa3d57e48330cf88a81c676dc91a32a Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 00:18:12 +0900 Subject: [PATCH 34/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2029=20-=20front=20backend=20=EB=B0=B0=ED=8F=AC=20=EC=8B=9C?= =?UTF-8?q?=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leafy-backend-build-and-push.yml | 18 ++++-------- .../leafy-frontend-build-and-push.yml | 28 ++++++++----------- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index 7b34482..58cc373 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -50,13 +50,8 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} script: | - export IMAGE_TAG=${{ needs.build.outputs.sha_tag }} - export IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:$IMAGE_TAG - echo "Deploying image: $IMAGE_NAME" - - if [ ! -f docker-compose.yml ]; then - echo "Creating initial docker-compose.yml" - cat << EOF > docker-compose.yml + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:latest + cat << 'EOF' > docker-compose.yml version: '3.8' services: leafy-postgres: @@ -69,7 +64,7 @@ jobs: timeout: 5s retries: 5 leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:initial + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ needs.build.outputs.sha_tag }} restart: on-failure environment: - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} @@ -78,18 +73,17 @@ jobs: depends_on: leafy-postgres: { condition: service_healthy } leafy-front: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:initial + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:latest restart: on-failure ports: ["80:80"] depends_on: ["leafy-backend"] volumes: leafy_data: EOF - fi - - sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:.*|image: \$IMAGE_NAME|g" docker-compose.yml + docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" docker-compose pull leafy-backend docker-compose up -d --remove-orphans + docker image prune -af diff --git a/.github/workflows/leafy-frontend-build-and-push.yml b/.github/workflows/leafy-frontend-build-and-push.yml index 1f9812a..f2c9cd7 100644 --- a/.github/workflows/leafy-frontend-build-and-push.yml +++ b/.github/workflows/leafy-frontend-build-and-push.yml @@ -1,6 +1,5 @@ name: Frontend Build and Push # .github/workflows/frontend-cicd.yml - on: push: branches: @@ -33,7 +32,7 @@ jobs: context: ./leafy-frontend file: ./leafy-frontend/Dockerfile push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:${{ steps.get_sha.outputs.sha }} + tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:${{ steps.get_sha.outputs.sha }},${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:latest platforms: linux/amd64 deploy: @@ -47,15 +46,8 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} script: | - export IMAGE_TAG=${{ needs.build.outputs.sha_tag }} - export IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:$IMAGE_TAG - - echo "Deploying image: $IMAGE_NAME" - - # docker-compose.yml 파일이 없을 경우를 대비한 초기 생성 스크립트 추가 - if [ ! -f docker-compose.yml ]; then - echo "Creating initial docker-compose.yml" - cat << 'EOF' > docker-compose.yml + echo "Creating/Updating docker-compose.yml with latest frontend image..." + cat << EOF > docker-compose.yml version: '3.8' services: leafy-postgres: @@ -75,13 +67,17 @@ jobs: timeout: 5s retries: 5 leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:initial + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest restart: on-failure + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/postgres + - SPRING_DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} + - SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} depends_on: leafy-postgres: condition: service_healthy leafy-front: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:initial + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:${{ needs.build.outputs.sha_tag }} restart: on-failure ports: - "80:80" @@ -90,10 +86,8 @@ jobs: volumes: leafy_data: EOF - fi - - sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:.*|image: \$IMAGE_NAME|g" docker-compose.yml - + + echo "Starting services..." sudo docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" sudo docker-compose pull leafy-frontend sudo docker-compose up -d --remove-orphans From d50d141a126095899d18f9b5baa23c03e7c658f5 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 00:38:03 +0900 Subject: [PATCH 35/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2030=20-=20=EB=8B=A4=EC=8B=9C=20=EB=B0=B0=ED=8F=AC=20=EC=8B=9C?= =?UTF-8?q?=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 1 + .github/workflows/leafy-frontend-build-and-push.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index 4f0ab9c..20c6981 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -37,6 +37,7 @@ jobs: environment: - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} + - POSTGRES_DB=${{ secrets.DATASOURCE_URL }} ports: - "5432:5432" volumes: diff --git a/.github/workflows/leafy-frontend-build-and-push.yml b/.github/workflows/leafy-frontend-build-and-push.yml index f2c9cd7..8acaded 100644 --- a/.github/workflows/leafy-frontend-build-and-push.yml +++ b/.github/workflows/leafy-frontend-build-and-push.yml @@ -70,7 +70,7 @@ jobs: image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest restart: on-failure environment: - - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/postgres + - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} - SPRING_DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} - SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} depends_on: From e7001f06d6c384e685127fc3978bb43efab1979f Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 00:57:43 +0900 Subject: [PATCH 36/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2031=20-=20=EB=B0=B1=EC=97=94=EB=93=9C=20=EB=B0=B0=ED=8F=AC=20?= =?UTF-8?q?=EC=8B=9C=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/devwiki/leafy/controller/user/UserController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java index fcf5216..c13f573 100644 --- a/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java +++ b/leafy-backend/src/main/java/com/devwiki/leafy/controller/user/UserController.java @@ -13,7 +13,6 @@ import javax.validation.Valid; import java.util.List; - @RestController @RequestMapping("/api/v1/users") @RequiredArgsConstructor From d9788397f78a158ce93598dd6bfcd3063ddeb60b Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 01:25:15 +0900 Subject: [PATCH 37/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2032=20-=20initial-setup.yml=20=EC=88=98=EC=A0=95=20-=20?= =?UTF-8?q?=EB=B0=B1=20=ED=94=84=EB=A1=A0=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index 20c6981..06afef6 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -48,6 +48,21 @@ jobs: interval: 5s timeout: 5s retries: 5 + leafy-backend: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest + restart: on-failure + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} + - SPRING_DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} + - SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} + - SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT=org.hibernate.dialect.PostgreSQLDialect + depends_on: + leafy-postgres: { condition: service_healthy } + leafy-front: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:latest + restart: on-failure + ports: ["80:80"] + depends_on: [- leafy-backend] volumes: leafy_data: EOF @@ -57,7 +72,7 @@ jobs: docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" # sudo를 추가하여 권한 문제 해결 - sudo docker-compose pull leafy-postgres - sudo docker-compose up -d leafy-postgres + sudo docker-compose pull + sudo docker-compose up -d echo "Initial setup complete. Services are starting." From cf1b9002b7ed9a769844931d9e564ccf93f87c28 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 01:54:49 +0900 Subject: [PATCH 38/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2033=20-=20....?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leafy-backend-build-and-push.yml | 20 +++++++++++++------ .../leafy-frontend-build-and-push.yml | 14 ++++++++++--- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index 58cc373..a9fb366 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -50,7 +50,12 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} script: | - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:latest + + # --- 1. docker-compose.yml 파일이 없으면 새로 생성 --- + if [ ! -f docker-compose.yml ]; then + echo "Creating initial docker-compose.yml" + cat << 'EOF' > docker-compose.yml + cat << 'EOF' > docker-compose.yml version: '3.8' services: @@ -81,9 +86,12 @@ jobs: leafy_data: EOF - - docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" - docker-compose pull leafy-backend - docker-compose up -d --remove-orphans + # --- 2. 백엔드 이미지 태그만 수정 --- + export IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ needs.build.outputs.sha_tag }} + sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:.*|image: \$IMAGE_NAME|g" docker-compose.yml + - docker image prune -af + sudo docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" + sudo docker-compose pull leafy-backend + sudo docker-compose up -d --remove-orphans + sudo docker image prune -af diff --git a/.github/workflows/leafy-frontend-build-and-push.yml b/.github/workflows/leafy-frontend-build-and-push.yml index 8acaded..51af873 100644 --- a/.github/workflows/leafy-frontend-build-and-push.yml +++ b/.github/workflows/leafy-frontend-build-and-push.yml @@ -46,8 +46,11 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} script: | - echo "Creating/Updating docker-compose.yml with latest frontend image..." - cat << EOF > docker-compose.yml + + # --- 1. docker-compose.yml 파일이 없으면 새로 생성 --- + if [ ! -f docker-compose.yml ]; then + echo "Creating initial docker-compose.yml" + cat << 'EOF' > docker-compose.yml version: '3.8' services: leafy-postgres: @@ -57,7 +60,7 @@ jobs: environment: - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} - - POSTGRES_DB=postgres + - POSTGRES_DB=${{ secrets.DATASOURCE_URL }} volumes: - leafy_data:/var/lib/postgresql/data restart: always @@ -88,6 +91,11 @@ jobs: EOF echo "Starting services..." + + export IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:${{ needs.build.outputs.sha_tag }} + # 프론트엔드 이미지 태그만 수정 + sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:.*|image: \$IMAGE_NAME|g" docker-compose.yml + sudo docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" sudo docker-compose pull leafy-frontend sudo docker-compose up -d --remove-orphans From 2f79dd01767b9210bb01f1c432c17e542c8b45e4 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 02:01:33 +0900 Subject: [PATCH 39/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2034?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leafy-frontend-build-and-push.yml | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/.github/workflows/leafy-frontend-build-and-push.yml b/.github/workflows/leafy-frontend-build-and-push.yml index 51af873..b3ee8b8 100644 --- a/.github/workflows/leafy-frontend-build-and-push.yml +++ b/.github/workflows/leafy-frontend-build-and-push.yml @@ -51,44 +51,45 @@ jobs: if [ ! -f docker-compose.yml ]; then echo "Creating initial docker-compose.yml" cat << 'EOF' > docker-compose.yml - version: '3.8' - services: - leafy-postgres: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest - ports: - - "5432:5432" - environment: - - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} - - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} - - POSTGRES_DB=${{ secrets.DATASOURCE_URL }} - volumes: - - leafy_data:/var/lib/postgresql/data - restart: always - healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] - interval: 5s - timeout: 5s - retries: 5 - leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest - restart: on-failure - environment: - - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} - - SPRING_DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} - - SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} - depends_on: - leafy-postgres: - condition: service_healthy - leafy-front: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:${{ needs.build.outputs.sha_tag }} - restart: on-failure - ports: - - "80:80" - depends_on: - - leafy-backend - volumes: - leafy_data: - EOF + version: '3.8' + services: + leafy-postgres: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest + ports: + - "5432:5432" + environment: + - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} + - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} + - POSTGRES_DB=${{ secrets.DATASOURCE_URL }} + volumes: + - leafy_data:/var/lib/postgresql/data + restart: always + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + leafy-backend: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest + restart: on-failure + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} + - SPRING_DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} + - SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} + depends_on: + leafy-postgres: + condition: service_healthy + leafy-front: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:${{ needs.build.outputs.sha_tag }} + restart: on-failure + ports: + - "80:80" + depends_on: + - leafy-backend + volumes: + leafy_data: + EOF + fi echo "Starting services..." From 2921bcefacbe30caf1b1254f828732298b50e281 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 02:51:11 +0900 Subject: [PATCH 40/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2035=20-init=20setup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 36 +++++++++++++++-------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index 06afef6..50d70fa 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -1,9 +1,10 @@ +# .github/workflows/initial-setup.yml + name: Initial EC2 Setup on: workflow_dispatch: - jobs: setup: runs-on: ubuntu-latest @@ -18,18 +19,17 @@ jobs: # --- 1. Docker 및 Docker Compose 설치 --- if ! command -v docker &> /dev/null; then echo "Installing Docker..." - sudo apt-get update - sudo apt-get install -y docker.io - sudo systemctl start docker - sudo systemctl enable docker + sudo apt-get update && sudo apt-get install -y docker.io + sudo systemctl start docker && sudo systemctl enable docker sudo usermod -aG docker ${{ secrets.EC2_USERNAME }} sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose fi - # --- 2. docker-compose.yml 파일 생성 --- + # --- 2. docker-compose.yml 파일 생성 (healthcheck 수정) --- echo "Creating docker-compose.yml..." - cat << 'EOF' > docker-compose.yml + # 'EOF'에서 작은따옴표를 제거해야 secrets 변수가 확장됩니다. + cat << EOF > docker-compose.yml version: '3.8' services: leafy-postgres: @@ -44,7 +44,8 @@ jobs: - leafy_data:/var/lib/postgresql/data restart: always healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] + # healthcheck 사용자를 secret 값으로 동적으로 변경 + test: ["CMD-SHELL", "pg_isready -U ${{ secrets.DATASOURCE_USERNAME }}"] interval: 5s timeout: 5s retries: 5 @@ -57,22 +58,23 @@ jobs: - SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} - SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT=org.hibernate.dialect.PostgreSQLDialect depends_on: - leafy-postgres: { condition: service_healthy } + leafy-postgres: + condition: service_healthy leafy-front: image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:latest restart: on-failure - ports: ["80:80"] - depends_on: [- leafy-backend] + ports: + - "80:80" + depends_on: + - leafy-backend volumes: leafy_data: EOF - # --- 3. Postgres 서비스 시작 --- - echo "Starting Postgres service..." - docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" - - # sudo를 추가하여 권한 문제 해결 + # --- 3. 서비스 시작 --- + echo "Starting services..." + sudo docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" sudo docker-compose pull sudo docker-compose up -d - echo "Initial setup complete. Services are starting." + echo "Initial setup complete." From f1b0bbc62011bc554e44b1ef0dbfd757d994f630 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 02:54:32 +0900 Subject: [PATCH 41/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2036?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leafy-backend-build-and-push.yml | 59 ++++++++++--------- leafy-frontend/src/App.vue | 2 +- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index a9fb366..d09f485 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -56,35 +56,36 @@ jobs: echo "Creating initial docker-compose.yml" cat << 'EOF' > docker-compose.yml - cat << 'EOF' > docker-compose.yml - version: '3.8' - services: - leafy-postgres: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest - volumes: ["leafy_data:/var/lib/postgresql/data"] - restart: always - healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] - interval: 5s - timeout: 5s - retries: 5 - leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ needs.build.outputs.sha_tag }} - restart: on-failure - environment: - - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} - - SPRING_DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} - - SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} - depends_on: - leafy-postgres: { condition: service_healthy } - leafy-front: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:latest - restart: on-failure - ports: ["80:80"] - depends_on: ["leafy-backend"] - volumes: - leafy_data: - EOF + cat << 'EOF' > docker-compose.yml + version: '3.8' + services: + leafy-postgres: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest + volumes: ["leafy_data:/var/lib/postgresql/data"] + restart: always + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + leafy-backend: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ needs.build.outputs.sha_tag }} + restart: on-failure + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} + - SPRING_DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} + - SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} + depends_on: + leafy-postgres: { condition: service_healthy } + leafy-front: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:latest + restart: on-failure + ports: ["80:80"] + depends_on: ["leafy-backend"] + volumes: + leafy_data: + EOF + fi # --- 2. 백엔드 이미지 태그만 수정 --- export IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ needs.build.outputs.sha_tag }} diff --git a/leafy-frontend/src/App.vue b/leafy-frontend/src/App.vue index 19aac0f..8bf8d2f 100644 --- a/leafy-frontend/src/App.vue +++ b/leafy-frontend/src/App.vue @@ -2,7 +2,7 @@

안녕하세요, {{ user.name }}님!

-

오늘도 즐거운 식물 관리하세요 !!

+

오늘도 즐거운 식물 관리하세요 !

LEAFY From ba18f711379785e96b2bc137257c40b4358f4433 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 03:07:55 +0900 Subject: [PATCH 42/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2037?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index 50d70fa..fe1ebf4 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -42,7 +42,7 @@ jobs: - "5432:5432" volumes: - leafy_data:/var/lib/postgresql/data - restart: always + restart: always₩ healthcheck: # healthcheck 사용자를 secret 값으로 동적으로 변경 test: ["CMD-SHELL", "pg_isready -U ${{ secrets.DATASOURCE_USERNAME }}"] @@ -50,7 +50,7 @@ jobs: timeout: 5s retries: 5 leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:f1b0bbc restart: on-failure environment: - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} @@ -61,7 +61,7 @@ jobs: leafy-postgres: condition: service_healthy leafy-front: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:latest + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend: restart: on-failure ports: - "80:80" From 8003b4712060606e820f82091b4ef806fab30a37 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 03:10:18 +0900 Subject: [PATCH 43/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2038?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index fe1ebf4..3d02dc0 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -25,11 +25,7 @@ jobs: sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose fi - - # --- 2. docker-compose.yml 파일 생성 (healthcheck 수정) --- - echo "Creating docker-compose.yml..." - # 'EOF'에서 작은따옴표를 제거해야 secrets 변수가 확장됩니다. - cat << EOF > docker-compose.yml + version: '3.8' services: leafy-postgres: From 8fcb4d7ecd2100b0c9518a41a26826205b8d4f41 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 03:13:36 +0900 Subject: [PATCH 44/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2039?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index 3d02dc0..ef46dd0 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -26,6 +26,8 @@ jobs: sudo chmod +x /usr/local/bin/docker-compose fi + echo "Creating docker-compose.yml..." + cat << EOF > docker-compose.yml version: '3.8' services: leafy-postgres: From 4c1a630b1f0cf956b1cae4c91461a3f0582bfec4 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 03:17:19 +0900 Subject: [PATCH 45/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2040?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index ef46dd0..39b8a3f 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -1,5 +1,4 @@ # .github/workflows/initial-setup.yml - name: Initial EC2 Setup on: @@ -25,30 +24,30 @@ jobs: sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose fi - + + # --- 2. docker-compose.yml 파일 생성 (검증된 버전) --- echo "Creating docker-compose.yml..." cat << EOF > docker-compose.yml version: '3.8' services: leafy-postgres: image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest + ports: + - "5432:5432" environment: - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} - - POSTGRES_DB=${{ secrets.DATASOURCE_URL }} - ports: - - "5432:5432" + - POSTGRES_DB=postgres volumes: - leafy_data:/var/lib/postgresql/data - restart: always₩ + restart: always healthcheck: - # healthcheck 사용자를 secret 값으로 동적으로 변경 test: ["CMD-SHELL", "pg_isready -U ${{ secrets.DATASOURCE_USERNAME }}"] interval: 5s timeout: 5s retries: 5 leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:f1b0bbc + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest restart: on-failure environment: - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} @@ -59,7 +58,7 @@ jobs: leafy-postgres: condition: service_healthy leafy-front: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:latest restart: on-failure ports: - "80:80" From 3b8f8b90ab468bd844eb84fe2e45543d56afb47a Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 03:19:18 +0900 Subject: [PATCH 46/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2040?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index 39b8a3f..0f29dbc 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -47,7 +47,7 @@ jobs: timeout: 5s retries: 5 leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:f1b0bbc restart: on-failure environment: - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} From d567b171365c5263080f021ebd5d6a019b9a5896 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 03:21:29 +0900 Subject: [PATCH 47/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2041=20=ED=94=84=EB=A1=A0=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- leafy-frontend/src/App.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leafy-frontend/src/App.vue b/leafy-frontend/src/App.vue index 8bf8d2f..19aac0f 100644 --- a/leafy-frontend/src/App.vue +++ b/leafy-frontend/src/App.vue @@ -2,7 +2,7 @@

안녕하세요, {{ user.name }}님!

-

오늘도 즐거운 식물 관리하세요 !

+

오늘도 즐거운 식물 관리하세요 !!

LEAFY From 27d7d9a300db3a5da6e19425c3c8975e67108b15 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 03:29:07 +0900 Subject: [PATCH 48/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2041=20=ED=94=84=EB=A1=A0=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/leafy-backend-build-and-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index d09f485..411f612 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -35,7 +35,7 @@ jobs: context: ./leafy-backend file: ./leafy-backend/Dockerfile push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ steps.get_sha.outputs.sha }} + tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ steps.get_sha.outputs.sha }},${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest platforms: linux/amd64,linux/arm64 # --- 2. 배포 Job --- From 8a4b2f3d80da1342fad71065198d0ec253aff989 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 11:02:14 +0900 Subject: [PATCH 49/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2042=20init=20=ED=99=98=EA=B2=BD=20=EB=B3=80=EC=88=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index 0f29dbc..e701157 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -62,6 +62,9 @@ jobs: restart: on-failure ports: - "80:80" + environment: + - BACKEND_HOST=leafy-backend + - BACKEND_PORT=8080 depends_on: - leafy-backend volumes: From 27f92bdd2025d6924162a8bf5889b9746207ffcc Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 11:10:58 +0900 Subject: [PATCH 50/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2043=20-=20backend=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/leafy-backend-build-and-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index 411f612..54506f0 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -36,7 +36,7 @@ jobs: file: ./leafy-backend/Dockerfile push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ steps.get_sha.outputs.sha }},${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64 # --- 2. 배포 Job --- deploy: From 1b52464776b88196b90122112a243fe9b9126bc4 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 11:19:17 +0900 Subject: [PATCH 51/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2044=20-=20backend=20=EC=88=98=EC=A0=952?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/leafy-backend-build-and-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index 54506f0..ed79d0f 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -56,12 +56,12 @@ jobs: echo "Creating initial docker-compose.yml" cat << 'EOF' > docker-compose.yml - cat << 'EOF' > docker-compose.yml version: '3.8' services: leafy-postgres: image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest volumes: ["leafy_data:/var/lib/postgresql/data"] + ports: ["5432:5432"] restart: always healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] From 886c2d61864497445dc9b82c8f7cdd1137f74819 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 11:26:36 +0900 Subject: [PATCH 52/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2045=20-=20backend=20=EC=88=98=EC=A0=953?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/leafy-backend-build-and-push.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index ed79d0f..f76faa5 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -50,21 +50,23 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} script: | - # --- 1. docker-compose.yml 파일이 없으면 새로 생성 --- if [ ! -f docker-compose.yml ]; then echo "Creating initial docker-compose.yml" cat << 'EOF' > docker-compose.yml - version: '3.8' services: leafy-postgres: image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest - volumes: ["leafy_data:/var/lib/postgresql/data"] ports: ["5432:5432"] + environment: + - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} + - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} + - POSTGRES_DB=${{ secrets.DATASOURCE_URL }} + volumes: [- leafy_data:/var/lib/postgresql/data] restart: always healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] + test: ["CMD-SHELL", "pg_isready -U ${{ secrets.DATASOURCE_USERNAME }}"] interval: 5s timeout: 5s retries: 5 From 475c4b5152fa6d3d413c59d11dec5f1e75bc4b5b Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 11:46:47 +0900 Subject: [PATCH 53/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2046=20-=20backend=20=EC=88=98=EC=A0=954?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leafy-backend-build-and-push.yml | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index f76faa5..fc5d038 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -53,40 +53,40 @@ jobs: # --- 1. docker-compose.yml 파일이 없으면 새로 생성 --- if [ ! -f docker-compose.yml ]; then echo "Creating initial docker-compose.yml" - cat << 'EOF' > docker-compose.yml - version: '3.8' - services: - leafy-postgres: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest - ports: ["5432:5432"] - environment: - - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} - - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} - - POSTGRES_DB=${{ secrets.DATASOURCE_URL }} - volumes: [- leafy_data:/var/lib/postgresql/data] - restart: always - healthcheck: - test: ["CMD-SHELL", "pg_isready -U ${{ secrets.DATASOURCE_USERNAME }}"] - interval: 5s - timeout: 5s - retries: 5 - leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ needs.build.outputs.sha_tag }} - restart: on-failure - environment: - - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} - - SPRING_DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} - - SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} - depends_on: - leafy-postgres: { condition: service_healthy } - leafy-front: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:latest - restart: on-failure - ports: ["80:80"] - depends_on: ["leafy-backend"] - volumes: - leafy_data: - EOF + cat << 'EOF' > docker-compose.yml + version: '3.8' + services: + leafy-postgres: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest + ports: ["5432:5432"] + environment: + - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} + - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} + - POSTGRES_DB=${{ secrets.DATASOURCE_URL }} + volumes: [- leafy_data:/var/lib/postgresql/data] + restart: always + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${{ secrets.DATASOURCE_USERNAME }}"] + interval: 5s + timeout: 5s + retries: 5 + leafy-backend: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ needs.build.outputs.sha_tag }} + restart: on-failure + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} + - SPRING_DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} + - SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} + depends_on: + leafy-postgres: { condition: service_healthy } + leafy-front: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:latest + restart: on-failure + ports: ["80:80"] + depends_on: ["leafy-backend"] + volumes: + leafy_data: + EOF fi # --- 2. 백엔드 이미지 태그만 수정 --- From f751923832f743a37cc0c91d2c5914f64ab6cb89 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 11:53:28 +0900 Subject: [PATCH 54/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2047=20-=20init=20backend=20latest=EB=A1=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index e701157..9f30643 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -47,7 +47,7 @@ jobs: timeout: 5s retries: 5 leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:f1b0bbc + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest restart: on-failure environment: - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} From d8bde20dcb349aa6f292e5758511f9d786f0f543 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 12:32:06 +0900 Subject: [PATCH 55/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2048=20-=20postgres=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/initial-setup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/initial-setup.yml b/.github/workflows/initial-setup.yml index 9f30643..d1c7f68 100644 --- a/.github/workflows/initial-setup.yml +++ b/.github/workflows/initial-setup.yml @@ -37,7 +37,7 @@ jobs: environment: - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} - - POSTGRES_DB=postgres + - POSTGRES_DB=${{ secrets.DATASOURCE_URL }} volumes: - leafy_data:/var/lib/postgresql/data restart: always From 38c950f26e6d1ed197bea01dbf4eff78bd9e3ce9 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 12:34:25 +0900 Subject: [PATCH 56/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2049=20-=20postgres=20=EC=88=98=EC=A0=952?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- leafy-postgresql/init/init.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leafy-postgresql/init/init.sql b/leafy-postgresql/init/init.sql index 812544d..e588e74 100644 --- a/leafy-postgresql/init/init.sql +++ b/leafy-postgresql/init/init.sql @@ -106,7 +106,7 @@ INSERT INTO user_plants (user_id, plant_id, plant_nickname) VALUES -- Plant_Logs 테이블에 데이터 삽입 INSERT INTO plant_logs (user_plant_id, log_date, note, watered) VALUES -(1, '2023-03-22', '관리가 어려워서 죽었습니다', false), +(1, '2023-03-22', '관리가 어려워서 죽게됐습니다.', false), (1, '2023-03-23', '새로운 아이비를 구입했습니다', true), (1, '2023-03-24', '1주일에 한 번 비료를 주기로 했습니다', false), (2, '2023-03-22', '잎이 탈색되어 있습니다', false), From 5680b6ecc24aecd4bb8f7d6be357d1da42d02897 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 12:43:40 +0900 Subject: [PATCH 57/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2050=20-=20front=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/leafy-frontend-build-and-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/leafy-frontend-build-and-push.yml b/.github/workflows/leafy-frontend-build-and-push.yml index b3ee8b8..0824472 100644 --- a/.github/workflows/leafy-frontend-build-and-push.yml +++ b/.github/workflows/leafy-frontend-build-and-push.yml @@ -65,7 +65,7 @@ jobs: - leafy_data:/var/lib/postgresql/data restart: always healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] + test: ["CMD-SHELL", "pg_isready -U ${{ secrets.DATASOURCE_USERNAME }}"] interval: 5s timeout: 5s retries: 5 From ef98d728fd0c44df7404798450260bdc1fc81516 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 12:46:38 +0900 Subject: [PATCH 58/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2051=20-=20front=20=EC=88=98=EC=A0=952?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leafy-frontend-build-and-push.yml | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/.github/workflows/leafy-frontend-build-and-push.yml b/.github/workflows/leafy-frontend-build-and-push.yml index 0824472..b43ae83 100644 --- a/.github/workflows/leafy-frontend-build-and-push.yml +++ b/.github/workflows/leafy-frontend-build-and-push.yml @@ -50,45 +50,45 @@ jobs: # --- 1. docker-compose.yml 파일이 없으면 새로 생성 --- if [ ! -f docker-compose.yml ]; then echo "Creating initial docker-compose.yml" - cat << 'EOF' > docker-compose.yml - version: '3.8' - services: - leafy-postgres: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest - ports: - - "5432:5432" - environment: - - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} - - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} - - POSTGRES_DB=${{ secrets.DATASOURCE_URL }} - volumes: - - leafy_data:/var/lib/postgresql/data - restart: always - healthcheck: - test: ["CMD-SHELL", "pg_isready -U ${{ secrets.DATASOURCE_USERNAME }}"] - interval: 5s - timeout: 5s - retries: 5 - leafy-backend: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest - restart: on-failure - environment: - - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} - - SPRING_DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} - - SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} - depends_on: - leafy-postgres: - condition: service_healthy - leafy-front: - image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:${{ needs.build.outputs.sha_tag }} - restart: on-failure - ports: - - "80:80" - depends_on: - - leafy-backend - volumes: - leafy_data: - EOF + cat << 'EOF' > docker-compose.yml + version: '3.8' + services: + leafy-postgres: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest + ports: + - "5432:5432" + environment: + - POSTGRES_USER=${{ secrets.DATASOURCE_USERNAME }} + - POSTGRES_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} + - POSTGRES_DB=${{ secrets.DATASOURCE_URL }} + volumes: + - leafy_data:/var/lib/postgresql/data + restart: always + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${{ secrets.DATASOURCE_USERNAME }}"] + interval: 5s + timeout: 5s + retries: 5 + leafy-backend: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:latest + restart: on-failure + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://leafy-postgres:5432/${{ secrets.DATASOURCE_URL }} + - SPRING_DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} + - SPRING_DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} + depends_on: + leafy-postgres: + condition: service_healthy + leafy-front: + image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-frontend:${{ needs.build.outputs.sha_tag }} + restart: on-failure + ports: + - "80:80" + depends_on: + - leafy-backend + volumes: + leafy_data: + EOF fi echo "Starting services..." From b529699f97a139f03310c2c505e871ebba2fdfc2 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 22:06:20 +0900 Subject: [PATCH 59/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2055=20-=20backend=20test=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + leafy-backend/build.gradle | 8 ++- .../leafy/dto/plant/PlantDetailDto.java | 33 +++++++---- .../devwiki/leafy/dto/plant/PlantMapper.java | 28 ++++----- .../leafy/service/plant/PlantServiceTest.java | 59 +++++++++++++++++++ 5 files changed, 101 insertions(+), 28 deletions(-) create mode 100644 .gitignore create mode 100644 leafy-backend/src/test/java/com/devwiki/leafy/service/plant/PlantServiceTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f10862a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.env diff --git a/leafy-backend/build.gradle b/leafy-backend/build.gradle index e5546f9..e5d01d6 100644 --- a/leafy-backend/build.gradle +++ b/leafy-backend/build.gradle @@ -24,13 +24,17 @@ dependencies { compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' annotationProcessor 'org.projectlombok:lombok' - testImplementation 'org.springframework.boot:spring-boot-starter-test' runtimeOnly 'org.postgresql:postgresql' implementation 'org.springframework.boot:spring-boot-starter-validation' - implementation 'org.springframework.security:spring-security-core:5.5.1' + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' testImplementation 'com.h2database:h2' + testImplementation 'org.springframework.security:spring-security-test' + implementation 'org.springframework.boot:spring-boot-starter-actuator' } diff --git a/leafy-backend/src/main/java/com/devwiki/leafy/dto/plant/PlantDetailDto.java b/leafy-backend/src/main/java/com/devwiki/leafy/dto/plant/PlantDetailDto.java index ac8e423..648787f 100644 --- a/leafy-backend/src/main/java/com/devwiki/leafy/dto/plant/PlantDetailDto.java +++ b/leafy-backend/src/main/java/com/devwiki/leafy/dto/plant/PlantDetailDto.java @@ -1,22 +1,31 @@ package com.devwiki.leafy.dto.plant; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; import java.time.LocalDateTime; +@NoArgsConstructor @Data +@Builder +@AllArgsConstructor public class PlantDetailDto { - private Long plantId; - private String plantName; - private String plantType; - private String plantDesc; - private String imageUrl; - private float temperatureLow; - private float temperatureHigh; - private float humidityLow; - private float humidityHigh; - private int wateringInterval; - private LocalDateTime createdAt; - private LocalDateTime updatedAt; + + private Long plantId; + private String plantName; + private String plantType; + private String plantDesc; + private String imageUrl; + private float temperatureLow; + private float temperatureHigh; + private float humidityLow; + private float humidityHigh; + private int wateringInterval; + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + + } diff --git a/leafy-backend/src/main/java/com/devwiki/leafy/dto/plant/PlantMapper.java b/leafy-backend/src/main/java/com/devwiki/leafy/dto/plant/PlantMapper.java index a1d8d68..0bd7911 100644 --- a/leafy-backend/src/main/java/com/devwiki/leafy/dto/plant/PlantMapper.java +++ b/leafy-backend/src/main/java/com/devwiki/leafy/dto/plant/PlantMapper.java @@ -7,20 +7,20 @@ public class PlantMapper { public static PlantDetailDto toDetailDto(Plant plant) { - PlantDetailDto plantDetailDto = new PlantDetailDto(); - plantDetailDto.setPlantId(plant.getPlantId()); - plantDetailDto.setPlantName(plant.getPlantName()); - plantDetailDto.setPlantType(plant.getPlantType()); - plantDetailDto.setPlantDesc(plant.getPlantDesc()); - plantDetailDto.setImageUrl(plant.getImageUrl()); - plantDetailDto.setTemperatureLow(plant.getTemperatureLow()); - plantDetailDto.setTemperatureHigh(plant.getTemperatureHigh()); - plantDetailDto.setHumidityLow(plant.getHumidityLow()); - plantDetailDto.setHumidityHigh(plant.getHumidityHigh()); - plantDetailDto.setWateringInterval(plant.getWateringInterval()); - plantDetailDto.setCreatedAt(plant.getCreatedAt()); - plantDetailDto.setUpdatedAt(plant.getUpdatedAt()); - return plantDetailDto; + return PlantDetailDto.builder() + .plantId(plant.getPlantId()) + .plantName(plant.getPlantName()) + .plantType(plant.getPlantType()) + .plantDesc(plant.getPlantDesc()) + .imageUrl(plant.getImageUrl()) + .temperatureLow(plant.getTemperatureLow()) + .temperatureHigh(plant.getTemperatureHigh()) + .humidityLow(plant.getHumidityLow()) + .humidityHigh(plant.getHumidityHigh()) + .wateringInterval(plant.getWateringInterval()) + .createdAt(plant.getCreatedAt()) + .updatedAt(plant.getUpdatedAt()) + .build(); } diff --git a/leafy-backend/src/test/java/com/devwiki/leafy/service/plant/PlantServiceTest.java b/leafy-backend/src/test/java/com/devwiki/leafy/service/plant/PlantServiceTest.java new file mode 100644 index 0000000..df4ef4d --- /dev/null +++ b/leafy-backend/src/test/java/com/devwiki/leafy/service/plant/PlantServiceTest.java @@ -0,0 +1,59 @@ +package com.devwiki.leafy.service.plant; + + +import static org.junit.jupiter.api.Assertions.*; + +import java.time.LocalDateTime; + +import org.junit.jupiter.api.BeforeEach; +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 com.devwiki.leafy.dto.plant.PlantDetailDto; +import com.devwiki.leafy.repository.plant.PlantRepository; +import com.devwiki.leafy.repository.user.UserRepository; + +@SpringBootTest +class PlantServiceTest { + + @Autowired + private PlantService plantService; + + @Autowired + private PlantRepository plantRepository; + + @Autowired + private UserRepository userRepository; + + @BeforeEach + void setUp() { + plantRepository.deleteAll(); + userRepository.deleteAll(); + } + + @Test + @DisplayName("식물 등록") + void test1() { + // given + PlantDetailDto dto = PlantDetailDto.builder() + .plantName("몬스테라") + .plantType("관엽식물") + .plantDesc("공기정화식물") + .imageUrl("https://example.com/monstera.jpg") + .temperatureLow(20.0f) + .temperatureHigh(30.0f) + .humidityLow(40.0f) + .humidityHigh(60.0f) + .wateringInterval(7) + .createdAt(LocalDateTime.now()) + .updatedAt(LocalDateTime.now()) + .build(); + // when + plantService.addPlant(dto); + // then + assertEquals(1, plantRepository.count()); + assertEquals("몬스테라", plantRepository.findAll().get(0).getPlantName()); + } +} From af4954eccb6b3f3ca80f081b592e5c5118216612 Mon Sep 17 00:00:00 2001 From: bagjuna Date: Mon, 22 Sep 2025 22:19:40 +0900 Subject: [PATCH 60/60] =?UTF-8?q?new=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20take?= =?UTF-8?q?=2056=20-=20backend=20=EB=B9=8C=EB=93=9C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/leafy-backend-build-and-push.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/leafy-backend-build-and-push.yml b/.github/workflows/leafy-backend-build-and-push.yml index fc5d038..af7cf4c 100644 --- a/.github/workflows/leafy-backend-build-and-push.yml +++ b/.github/workflows/leafy-backend-build-and-push.yml @@ -54,7 +54,6 @@ jobs: if [ ! -f docker-compose.yml ]; then echo "Creating initial docker-compose.yml" cat << 'EOF' > docker-compose.yml - version: '3.8' services: leafy-postgres: image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-postgres:latest @@ -90,10 +89,9 @@ jobs: fi # --- 2. 백엔드 이미지 태그만 수정 --- - export IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ needs.build.outputs.sha_tag }} - sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:.*|image: \$IMAGE_NAME|g" docker-compose.yml - - + sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:.*|image: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ needs.build.outputs.sha_tag }}|g" docker-compose.yml + + sudo docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" sudo docker-compose pull leafy-backend sudo docker-compose up -d --remove-orphans