-
Notifications
You must be signed in to change notification settings - Fork 1
91 lines (74 loc) · 2.21 KB
/
Copy pathdeploy.yml
File metadata and controls
91 lines (74 loc) · 2.21 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
89
90
91
name: Deploy to EC2
on:
push:
branches:
- main
paths-ignore:
- '**.md'
jobs:
test-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r backend/requirements.txt
- name: Run Backend Tests
run: |
cd backend
pytest
test-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install dependencies
run: |
cd frontend
npm install
- name: Run Component Tests
run: |
cd frontend
npm run test:component
deploy:
needs: [test-backend, test-frontend]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Deploy to EC2
uses: appleboy/ssh-action@master
env:
ENV_FILE: ${{ secrets.ENV_FILE }}
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
envs: ENV_FILE
script: |
# Stop script on first error
set -e
# Add /usr/local/bin to PATH for this session
export PATH=$PATH:/usr/local/bin
# Navigate to the project directory
cd ~/task_master
# Pull the latest changes
git pull origin main
# Create .env file from secret
echo "$ENV_FILE" > backend/.env
# Rebuild and restart containers
# Use sudo to ensure we have permissions
# Disable BuildKit to avoid compatibility issues on Amazon Linux 2
sudo DOCKER_BUILDKIT=0 /usr/local/bin/docker-compose up -d --build
# Prune unused images to save space
sudo docker image prune -f