Skip to content

Commit

Permalink
Merge pull request #29 from Tave-13th-Project-Team-4-Fiurinee/feature…
Browse files Browse the repository at this point in the history
…/ci-cd

chore: 수정
  • Loading branch information
qormoon authored Jun 25, 2024
2 parents 92b81f7 + 374aaa8 commit a4f98ab
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 84 deletions.
21 changes: 0 additions & 21 deletions .github/script/deploy.sh

This file was deleted.

102 changes: 41 additions & 61 deletions .github/workflows/dev_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand All @@ -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
Expand All @@ -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
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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"

Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public interface AnniversaryApi {
@ApiResponse(responseCode = "401", description = "인증 실패")
@ApiResponse(responseCode = "404", description = "사용자를 찾을 수 없음")
@PostMapping("/member/{id}/anniversary")
ResponseEntity<Anniversary> addAnniversary(@PathVariable Long id, @RequestBody AnniversaryRequestDTO request);
ResponseEntity<Anniversary> addAnniversary(@Parameter(name = "id", description = "멤버아이디")@PathVariable Long id, @RequestBody AnniversaryRequestDTO request);

@Operation(
summary = "기념일 수정",
summary = "기념일 수정입니닷",
description = "사용자의 기념일을 수정합니다.",
security = @SecurityRequirement(name = "bearerAuth")
)
Expand Down

0 comments on commit a4f98ab

Please sign in to comment.