-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (58 loc) · 1.95 KB
/
Copy pathdeploy.yml
File metadata and controls
67 lines (58 loc) · 1.95 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
name: Deploy to EC2
on:
push:
branches: [deploy]
permissions:
contents: read
packages: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# 1. 코드 체크아웃
- name: Checkout code
uses: actions/checkout@v4
# 2. Docker Buildx 설정
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 3. ghcr.io 로그인
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# 4. Docker 이미지 빌드 + push
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64
tags: |
ghcr.io/team-timo/timo-server:latest
ghcr.io/team-timo/timo-server:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
# 5. 배포 파일들을 EC2로 복사 (신규)
- name: Copy deploy files to EC2
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
source: "deploy/docker-compose.prod.yml,deploy/deploy.sh,deploy/prometheus/prometheus.yml,deploy/grafana/provisioning/datasources/datasource.yml"
target: "~/timo-deploy/"
strip_components: 1
# 6. EC2에 SSH 접속해서 Blue/Green 배포 실행
- name: Deploy to EC2 (Blue/Green)
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
echo "${{ secrets.GHCR_TOKEN }}" | sudo docker login ghcr.io -u "${{ secrets.GHCR_USERNAME }}" --password-stdin
cd ~/timo-deploy
chmod +x deploy.sh
bash deploy.sh