-
Notifications
You must be signed in to change notification settings - Fork 1
73 lines (56 loc) · 1.98 KB
/
CICD.yml
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
name: Java CICD with Gradle
on:
push:
branches: [ "main" ]
jobs:
ci:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Create .env file
run: |
echo "${{ secrets.ENV_FILE_CONTENTS }}" > .env
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
- name: Build with Gradle Wrapper
run: ./gradlew build -x test
# Docker 이미지 Build
- name: docker image build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/ivory-backend .
# DockerHub Login (push 하기 위해)
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# Docker hub 로 push
- name: Docker Hub push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/ivory-backend
cd:
needs: ci
runs-on: self-hosted
steps:
# 1. 기존의 컨테이너를 중지시킵니다
- name: Stop backend service
run: sudo docker stop Ivory-Backend
# 2. backend 서비스 컨테이너 제거
- name: Remove backend container
run: sudo docker rm Ivory-Backend
# 3. backend 이미지 제거
- name: Remove backend image
run: sudo docker rmi ${{ secrets.DOCKERHUB_USERNAME }}/ivory-backend
# 5. Git 최신 상태로 업데이트 (git pull)
- name: Pull latest changes
run: |
cd /home/ec2-user/2024_DANPOONG_TEAM_15_BE
git pull origin main
# 6. 최신 이미지를 컨테이너화하여 실행시킵니다
- name: Run new containers with docker-compose
run: sudo docker-compose -f /home/ec2-user/2024_DANPOONG_TEAM_15_BE/docker-compose.prod.yml up --build -d