-
Notifications
You must be signed in to change notification settings - Fork 3
88 lines (74 loc) · 2.49 KB
/
Copy pathprod-cicd.yml
File metadata and controls
88 lines (74 loc) · 2.49 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
85
86
87
88
name: CI/CD Prod
on:
push:
branches: [ "main" ]
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: 1. Checkout source
uses: actions/checkout@v4
- name: 2. Set up JDK
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
- name: 3. Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: 4. Build JAR
run: ./gradlew clean build -x test
- name: 5. Docker login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
- name: 6. Build & Push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/server:prod-latest
cd:
runs-on: ubuntu-latest
needs: ci
steps:
- name: 1. Checkout source
uses: actions/checkout@v4
- name: 2. Create .env file
run: echo "${{ secrets.PROD_ENV }}" > .env
- name: 3. Upload .env to Prod Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_PUBLIC_IP }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
source: ".env"
target: "/home/ubuntu/stepbookstep-prod/docker/"
- name: 4. docker-compose.yml 전달
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_PUBLIC_IP }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
source: "./docker/docker-compose.prod.yml"
target: "/home/ubuntu/stepbookstep-prod/"
- name: 5. SSH to Prod Server and Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_PUBLIC_IP }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
command_timeout: 15m
script: |
cd /home/ubuntu/stepbookstep-prod/docker/
docker pull ${{ secrets.DOCKER_USERNAME }}/server:prod-latest
docker compose -f docker-compose.prod.yml down --timeout 60
docker compose -f docker-compose.prod.yml up -d