-
Notifications
You must be signed in to change notification settings - Fork 1
85 lines (72 loc) ยท 2.93 KB
/
Copy pathdeploy.yml
File metadata and controls
85 lines (72 loc) ยท 2.93 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
name: Deploy Backend
# ๐ deploy ๋ธ๋์น๋ก push๋ ๋๋ง๋ค CI/CD ์๋ ์คํ.
on:
push:
branches:
- deploy
workflow_dispatch: # GitHub UI์์ ์๋ ์คํ ๊ฐ๋ฅ
permissions:
contents: read
jobs:
build-and-deploy:
runs-on: ubuntu-latest # GitHub Actions๊ฐ ์คํ๋๋ ๊ฐ์๋จธ์ ํ๊ฒฝ
steps:
# 1๏ธโฃ ๋ ํฌ์งํ ๋ฆฌ ์ฝ๋ ์ฒดํฌ์์
- name: Checkout repository
uses: actions/checkout@v3
# 2๏ธโฃ JDK 21 ์ค์น, Gradle ์บ์ฑ ์ ์ฉ
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
cache: gradle
# create application-database.yml
- name: create application.yml file
run: |
touch ./src/main/resources/application-prod.yml
echo "${{ secrets.APPLICATION_DEV_YML }}" >> src/main/resources/application-prod.yml
# 3๏ธโฃ gradlew ์คํ ๊ถํ ๋ถ์ฌ
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# 4๏ธโฃ ํ
์คํธ ์๋ตํ๊ณ Spring Boot Jar ๋น๋
- name: Build without tests
run: ./gradlew bootJar -x test
# 5๏ธโฃ AWS ์ ๊ทผ์ ์ํ ์ก์ธ์ค ํค/์ํฌ๋ฆฟ ํค ์ค์
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
# 6๏ธโฃ ECR ๋ก๊ทธ์ธ โ Docker Push ๊ถํ ํ๋
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
# ์บ์ ๊ธฐ๋ฅ์ ์ํด buildx ๋๋ผ์ด๋ฒ container ๋ชจ๋๋ก ๋ณ๊ฒฝ
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker-container
driver-opts: image=moby/buildkit:latest
# 7๏ธโฃ Docker ์ด๋ฏธ์ง ๋น๋ + ECR์ Push / ๋ ์ด์ด ์บ์ฑ -> ๋น ๋ฅธ ๋น๋ ์๋
- name: Build and push Docker image (ARM64 only)
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/arm64
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/techpost-backend:latest
cache-from: type=gha
cache-to: type=gha,mode=max, ignore-error=true
# 8๏ธโฃ EC2์ SSH ์ ์ ํ deploy.sh ์คํ โ ์๋ ๋ฐฐํฌ
- name: Deploy to EC2 using SSH
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.EC2_HOST }} # EC2 ํผ๋ธ๋ฆญ IP
username: ubuntu # EC2 ๊ธฐ๋ณธ ์ ์
key: ${{ secrets.EC2_SSH_KEY }} # GitHub Secrets์ ์ ์ฅ๋ PEM ํค
script: |
cd /home/ubuntu
chmod +x deploy.sh # deploy.sh ์คํ ๊ถํ ๋ณด์ฅ
./deploy.sh # ๐ฅ ์๋ ๋ฐฐํฌ ์คํ