-
Notifications
You must be signed in to change notification settings - Fork 1
91 lines (83 loc) · 2.92 KB
/
main.yaml
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
89
90
91
name: ci
on:
push:
branches:
- "main"
pull_request:
branches:
- "main"
jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name : Cache pip modules
id : cache-pip
uses : actions/cache@v3
with :
path : ~/.cache/pip
key : ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
-
name: Install dependencies
if: steps.cache-pip.outputs.cache-hit != 'true'
run: pip install -r requirements.txt
- name: Check Cache Directory
run: |
mkdir -p /tmp/.buildx-cache
ls -la /tmp
-
name : Cache Docker layers
id : cache
uses : actions/cache@v3
with :
path : /tmp/.buildx-cache
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile', '**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-docker-
-
# Build and push to dockerhub
name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}:latest
cache-from : type=gha
cache-to : type=gha,mode=max
# EC2 인스턴스 접속 및 애플리케이션 실행
-
name: Application Run
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}
# 기존 컨테이너 중지, 이미지 삭제
# 새로운 이미지 받아오기
# 새로운 이미지 기반으로 컨테이너 실행
script: |
sudo docker ps -a --filter "name=${{ secrets.PROJECT_NAME }}" --format "{{.ID}}" | xargs -r sudo docker stop
sudo docker ps -a --filter "name=${{ secrets.PROJECT_NAME }}" --format "{{.ID}}" | xargs -r sudo docker rm -f
sudo docker rmi ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}
sudo docker run -p ${{ secrets.PORT }}:${{ secrets.PORT }} \
--env-file ${{ secrets.ENV }} \
--name ${{ secrets.PROJECT_NAME }} \
-v /home/ubuntu/resume_ai_chat.db:/app/resume_ai_chat.db \
-d ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}