-
Notifications
You must be signed in to change notification settings - Fork 2
66 lines (55 loc) · 2.16 KB
/
deploy.yml
File metadata and controls
66 lines (55 loc) · 2.16 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
name: Deploy to EC2 with GHCR
on:
push:
branches:
- develop
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ghcr.io/pirogramming/startlinedev/web:latest
# 빌드 시 캐시로 인한 0바이트 파일 생성을 방지하고 싶다면 아래 옵션을 추가할 수 있습니다.
# no-cache: true
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Deploy to EC2 via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
cd ~/kitup
# 서버에서도 GHCR 이미지를 받을 수 있게 로그인
echo ${{ secrets.GHCR_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
# 1. 기존의 <none> 태그 이미지(Dangling Images)를 정리하여 용량 확보 및 이미지 꼬임 방지
docker image prune -f
# 2. 최신 이미지 가져오기
docker-compose pull web
# 3. 컨테이너 재실행
docker-compose up -d web
# 4. 배포 직후 다시 한번 정리 (선택사항이지만 서버를 깨끗하게 유지해줍니다)
docker image prune -f
# 5. 후처리 작업 (DB 동기화 및 정적파일 수집)
# 컨테이너가 뜰 시간을 잠깐 주기 위해 sleep을 넣는 것도 안정적입니다.
sleep 3
docker-compose exec -T web python manage.py migrate
docker-compose exec -T web python manage.py collectstatic --noinput