Skip to content

Commit b6c2bad

Browse files
committed
refactor: CI/CD 스크립트 수정
1 parent 033ca3b commit b6c2bad

File tree

2 files changed

+14
-58
lines changed

2 files changed

+14
-58
lines changed

.github/workflows/dev_deploy.yml

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ name: Java CI with Docker
33
on:
44
push:
55
branches: [ develop ] # develop 브랜치에 push될 때 실행
6-
paths-ignore:
7-
- '**.md'
8-
- 'docs/**'
9-
- '.gitignore'
10-
116

127
permissions:
138
contents: read
@@ -19,17 +14,6 @@ jobs:
1914
# 1) 워크플로우 실행 전 기본적으로 체크아웃 필요
2015
- uses: actions/checkout@v3
2116

22-
# Gradle 의존성에 대한 캐싱 추가 (매 빌드마다 의존성을 다시 다운로드하게 되어 빌드 시간이 길어지는 걸 방지)
23-
- name: Cache Gradle packages
24-
uses: actions/cache@v3
25-
with:
26-
path: |
27-
~/.gradle/caches
28-
~/.gradle/wrapper
29-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
30-
restore-keys: |
31-
${{ runner.os }}-gradle-
32-
3317
# 2) JDK 17 버전 설치
3418
- name: Set up JDK 17
3519
uses: actions/setup-java@v3
@@ -41,11 +25,6 @@ jobs:
4125
- name: Grant execute permission for gradlew
4226
run: chmod +x ./gradlew
4327

44-
- name: Make .env file
45-
run: |
46-
# .env 파일 생성 및 환경 변수 추가
47-
echo "${{ secrets.ENV }}" > .env
48-
4928
# 4) Gradle 빌드
5029
- name: Build with Gradle
5130
run: ./gradlew clean build
@@ -57,27 +36,13 @@ jobs:
5736
username: ${{ secrets.DOCKER_USERNAME }}
5837
password: ${{ secrets.DOCKER_PASSWORD }}
5938

60-
# 7) Docker Compose 빌드 및 푸시
61-
- name: Build and push with Docker Compose
62-
env:
63-
# DOCKER_IMAGE_NAME을 'latest' 대신 Git Commit SHA로 설정
64-
DOCKER_IMAGE_NAME: ${{ secrets.DOCKER_USERNAME }}/withmorning:${{ github.sha }}
65-
run: |
66-
echo "Building and pushing: $DOCKER_IMAGE_NAME"
67-
docker compose -f docker-compose.yml build app
68-
docker compose -f docker-compose.yml push app
69-
70-
71-
# 9) docker-compose-dev.yml 파일을 EC2로 복사
72-
- name: Copy docker-compose.yml to EC2
73-
uses: appleboy/scp-action@v0.1.7 # scp-action을 사용하여 파일을 EC2로 복사
39+
# 5) Docker 이미지 빌드 및 푸시
40+
- name: Build and push Docker image
41+
uses: docker/build-push-action@v3
7442
with:
75-
host: ${{ secrets.EC2_HOST }}
76-
username: ${{ secrets.EC2_USERNAME }}
77-
key: ${{ secrets.EC2_PRIVATE_KEY }}
78-
source: "docker-compose.yml" # Runner의 현재 작업 디렉토리에 있는 파일
79-
target: "/home/ubuntu/" # EC2 인스턴스의 대상 디렉토리 (파일이 복사될 위치)
80-
43+
context: .
44+
push: true
45+
tags: ${{ secrets.DOCKER_USERNAME }}/withmorning:latest # Docker Hub에 올릴 이미지 태그
8146

8247
# 6) EC2에 배포
8348
- name: Deploy to EC2
@@ -87,10 +52,12 @@ jobs:
8752
username: ${{ secrets.EC2_USERNAME }}
8853
key: ${{ secrets.EC2_PRIVATE_KEY }}
8954
script: |
90-
55+
# 0. docker compose 파일 가져오기
56+
curl -o docker-compose.yml https://raw.githubusercontent.com/WithMorning/Backend/refs/heads/develop/docker-compose.yml
57+
# 1. EC2 서버에 .env 파일을 새로 생성합니다.
9158
# GitHub Secrets의 값을 가져와 파일에 한 줄씩 씁니다.
9259
cat << EOF > .env
93-
DOCKER_IMAGE_NAME=${{ secrets.DOCKER_USERNAME }}/withmorning:${{ github.sha }}
60+
DOCKER_IMAGE_NAME=${{ secrets.DOCKER_USERNAME }}/withmorning:latest
9461
DB_URL=${{ secrets.DB_URL }}
9562
DB_USER=${{ secrets.DB_USER }}
9663
DB_PASS=${{ secrets.DB_PASS }}
@@ -106,20 +73,12 @@ jobs:
10673
FROM_NUMBER=${{ secrets.FROM_NUMBER }}
10774
EOF
10875
109-
# 4. .env 파일의 변수들을 현재 셸 환경으로 로드 (가장 중요!)
110-
export $(grep -v '^#' .env | xargs)
111-
112-
# 1. Docker Hub 로그인
113-
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
114-
11576
# 2. Auth key, firebase key 생성
11677
echo "${{ secrets.FIREBASE_SERVICE_KEY }}" > firebase-service-account.json
11778
echo "${{ secrets.AUTH_KEY_P8 }}" > authkey.p8
11879
119-
80+
# 4. .env 파일의 변수들을 현재 셸 환경으로 로드 (가장 중요!)
81+
export $(grep -v '^#' .env | xargs)
12082
# 2. Docker Compose 실행
121-
docker compose pull
122-
docker compose down
123-
docker compose up -d
124-
125-
docker image prune -af
83+
docker-compose down
84+
docker-compose up -d

docker-compose.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ version: '3.8' # Docker Compose 파일 버전
33
services:
44
# Spring Boot 애플리케이션 서비스
55
app:
6-
build:
7-
context: .
8-
dockerfile: Dockerfile
96
image: ${DOCKER_IMAGE_NAME}
107
container_name: withmorning-app
118
ports:

0 commit comments

Comments
 (0)