-
Notifications
You must be signed in to change notification settings - Fork 2
84 lines (71 loc) · 2.63 KB
/
cd.yml
File metadata and controls
84 lines (71 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: CD
# develop 브랜치에 push(merge)되면 실행
on:
push:
branches:
- develop
# 테스트 결과 작성을 위해 쓰기권한 추가
permissions: write-all
jobs:
build:
runs-on: ubuntu-latest
steps:
# 1. 코드 체크아웃
- uses: actions/checkout@v4
# 2. JDK 17 설정
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# 3. Gradle 캐싱
- name: Gradle Caching
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# 4. Gradlew 실행 권한 부여
- name: Grant Execute Permission For Gradlew
run: chmod +x gradlew
# 5. Gradle 빌드 (테스트 제외)
- name: Build With Gradle
run: ./gradlew build -x test
# 6. Docker 이미지 빌드 & Push
- name: Docker build & Push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker buildx build --platform linux/amd64 -t ${{ secrets.DOCKER_USERNAME }}/symtalk-be --push .
docker buildx build --platform linux/amd64 -t ${{ secrets.DOCKER_USERNAME }}/nginx --push -f dockerfile-nginx .
# 7. docker-compose.prod.yml을 EC2로 복사
- name: Copy docker-compose.prod.yml to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_PRIVATE_KEY }}
source: "docker-compose.prod.yml"
target: "/home/ubuntu/compose/"
overwrite: true
# 8. Docker Compose로 배포
- name: Deploy with Docker compose
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script: |
cd /home/ubuntu/compose
# Docker Compose V2 플러그인 설치 확인
if ! docker compose version > /dev/null 2>&1; then
echo "Installing Docker Compose V2 plugin..."
sudo apt-get update
sudo apt-get install -y docker-compose-plugin
fi
docker compose -f docker-compose.prod.yml down || true
docker pull ${{ secrets.DOCKER_USERNAME }}/symtalk-be
docker pull ${{ secrets.DOCKER_USERNAME }}/nginx
docker compose -f docker-compose.prod.yml up -d