diff --git a/.github/script/deploy.sh b/.github/script/deploy.sh deleted file mode 100644 index b072f5e..0000000 --- a/.github/script/deploy.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# 현재 실행 중인 JAR 프로세스를 찾고 종료합니다. -CURRENT_PID=$(pgrep -f .jar) -echo "$CURRENT_PID" -if [ -z $CURRENT_PID ]; then - echo "no process" -else - echo "kill $CURRENT_PID" - kill -9 $CURRENT_PID - sleep 3 -fi - -# 새로운 JAR 파일의 경로를 설정하고 실행 권한을 부여합니다. -JAR_PATH="/home/ec2-user/cicd/*.jar" -echo "jar path : $JAR_PATH" -chmod +x $JAR_PATH - -# 새로운 JAR 파일을 백그라운드에서 실행합니다. -nohup java -jar $JAR_PATH > /dev/null 2> /dev/null < /dev/null & -echo "jar file deploy success" diff --git a/.github/workflows/dev_deploy.yml b/.github/workflows/dev_deploy.yml index 0c2135e..a72cf62 100644 --- a/.github/workflows/dev_deploy.yml +++ b/.github/workflows/dev_deploy.yml @@ -46,6 +46,27 @@ jobs: - name: Build With Gradle run: ./gradlew build -x test + # 디렉토리 생성 + - name: Create deploy directory + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.EC2_HOST }} + username: ubuntu + key: ${{ secrets.EC2_SSH_KEY }} + script: | + mkdir -p /home/ubuntu/deploy + + # docker-compose 복사 + - name: Copy docker-compose.yml + uses: appleboy/scp-action@master + with: + host: ${{ secrets.EC2_HOST }} + username: ubuntu + key: ${{ secrets.EC2_SSH_KEY }} + source: "docker-compose.yml" + target: "/home/ubuntu/deploy/" + + # Docker 이미지를 빌드합니다. - name: docker image build run: docker build -t qormoon/fiurinee_docker . @@ -62,41 +83,32 @@ jobs: run: docker push qormoon/fiurinee_docker - # 빌드된 JAR 파일을 원격 서버에 복사합니다. - - name: Copy jar file to remote - uses: appleboy/scp-action@master - with: - username: ec2-user - host: ${{ secrets.EC2_HOST }} - key: ${{ secrets.EC2_SSH_KEY }} - source: "./build/libs/*.jar" - target: "/home/ec2-user/cicd" - strip_components: 2 + # 새로 빌드된 Docker 이미지를 EC2 서버에 배포하는 작업을 정의 + deploy: + needs: build-docker-image # build-docker-image 작업이 완료된 후에 실행됩니다. + runs-on: ubuntu-latest # 워크플로우가 실행될 환경을 지정합니다. - # 배포 스크립트를 원격 서버에 복사합니다. - - name: Copy deploy script file to remote - uses: appleboy/scp-action@master - with: - username: ec2-user - host: ${{ secrets.EC2_HOST }} - key: ${{ secrets.EC2_SSH_KEY }} - source: ".github/scripts/deploy.sh" - target: "/home/ec2-user/cicd" + steps: - # 배포 스크립트를 원격 서버에서 실행합니다. - - name: Execute deploy script + # EC2 서버에 SSH로 접속하여 Docker 이미지를 pull하고 컨테이너를 재시작 + - name: Deploy to EC2 uses: appleboy/ssh-action@master with: - username: ec2-user - host: ${{ secrets.EC2_HOST }} - key: ${{ secrets.EC2_SSH_KEY }} - script_stop: true + host: ${{ secrets.EC2_HOST }} # EC2 서버의 호스트 주소 + username: ubuntu + key: ${{ secrets.EC2_SSH_KEY }} # EC2 서버에 접근하기 위한 SSH 개인 키 script: | - chmod +x /home/ec2-user/cicd/deploy.sh - sh /home/ec2-user/cicd/deploy.sh - - + echo "DB_URL=${{ secrets.DB_URL }}" >> ~/deploy/.env + echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> ~/deploy/.env + echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> ~/deploy/.env + echo "AWS_ACCESSKEY=${{ secrets.AWS_ACCESSKEY }}" >> ~/deploy/.env + echo "AWS_SECRETKEY=${{ secrets.AWS_SECRETKEY }}" >> ~/deploy/.env + echo "AWS_BUCKET=${{ secrets.AWS_BUCKET }}" >> ~/deploy/.env + sudo docker-compose -f ~/deploy/docker-compose.yml pull + sudo docker-compose -f ~/deploy/docker-compose.yml up -d + sudo docker image prune -f + # # 배포 # - name: Deploy @@ -111,35 +123,3 @@ jobs: # sudo docker pull qormoon/fiurinee_docker # sudo docker run -d -p 8080:8080 qormoon/fiurinee_docker # sudo docker image prune -f - -# # 새로 빌드된 Docker 이미지를 EC2 서버에 배포하는 작업을 정의합니다. -# deploy: -# needs: build-docker-image # build-docker-image 작업이 완료된 후에 실행됩니다. -# runs-on: ubuntu-latest # 워크플로우가 실행될 환경을 지정합니다. -# -# steps: -# # EC2 서버에 SSH로 접속하여 Docker 이미지를 pull하고 컨테이너를 재시작 -# - name: Deploy to EC2 -# uses: appleboy/ssh-action@master -# with: -# host: ${{ secrets.EC2_HOST }} # EC2 서버의 호스트 주소 -# username: ubuntu -# key: ${{ secrets.EC2_SSH_KEY }} # EC2 서버에 접근하기 위한 SSH 개인 키 -# script: | -# # Docker Hub에서 최신 이미지를 pull 합니다. -# sudo docker pull qormoon/fiurinee_docker -# # 기존 컨테이너를 중지합니다. -# sudo docker stop fiurinee || true -# # 기존 컨테이너를 제거합니다. -# sudo docker rm fiurinee || true -# # 새 컨테이너를 실행하면서 환경 변수를 전달합니다. -# sudo docker run -d -p 8080:8080 --name fiurinee \ -# -e DB_URL=jdbc:postgresql://database-fiurinee.czyqweykwib4.ap-northeast-2.rds.amazonaws.com:5432/fiurinee \ -# -e DB_USERNAME=${{ secrets.DB_USERNAME }} \ -# -e DB_PASSWORD=${{ secrets.DB_PASSWORD }} \ -# -e AWS_ACCESSKEY=${{ secrets.AWS_ACCESSKEY }} \ -# -e AWS_SECRETKEY=${{ secrets.AWS_SECRETKEY }} \ -# -e AWS_BUCKET=${{ secrets.AWS_BUCKET }} \ -# -e hibernate_ddl_auto=update \ -# -v fiurinee_data:/var/lib/postgresql/data \ -# qormoon/fiurinee_docker diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a58edc4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: '3.8' + +services: + app: + image: qormoon/fiurinee_docker + ports: + - "8080:8080" + environment: + DB_URL: ${DB_URL} + DB_USERNAME: ${DB_USERNAME} + DB_PASSWORD: ${DB_PASSWORD} + AWS_ACCESSKEY: ${AWS_ACCESSKEY} + AWS_SECRETKEY: ${AWS_SECRETKEY} + AWS_BUCKET: ${AWS_BUCKET} + hibernate_ddl_auto: update + REDIS_HOST: redis + depends_on: + - redis + + redis: + image: "redis:latest" + ports: + - "6379:6379" + diff --git a/src/main/java/com/example/fiurinee/domain/anniversary/controller/api/AnniversaryApi.java b/src/main/java/com/example/fiurinee/domain/anniversary/controller/api/AnniversaryApi.java index 10a20d5..0e47cd8 100644 --- a/src/main/java/com/example/fiurinee/domain/anniversary/controller/api/AnniversaryApi.java +++ b/src/main/java/com/example/fiurinee/domain/anniversary/controller/api/AnniversaryApi.java @@ -34,10 +34,10 @@ public interface AnniversaryApi { @ApiResponse(responseCode = "401", description = "인증 실패") @ApiResponse(responseCode = "404", description = "사용자를 찾을 수 없음") @PostMapping("/member/{id}/anniversary") - ResponseEntity addAnniversary(@PathVariable Long id, @RequestBody AnniversaryRequestDTO request); + ResponseEntity addAnniversary(@Parameter(name = "id", description = "멤버아이디")@PathVariable Long id, @RequestBody AnniversaryRequestDTO request); @Operation( - summary = "기념일 수정", + summary = "기념일 수정입니닷", description = "사용자의 기념일을 수정합니다.", security = @SecurityRequirement(name = "bearerAuth") )