-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (50 loc) · 1.99 KB
/
Copy pathdeploy.yml
File metadata and controls
60 lines (50 loc) · 1.99 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
name: Deploy Backend to EC2
on:
push:
branches:
- master
paths:
- "server/**"
- "docker-compose.yml"
- ".github/workflows/deploy.yml"
# We ignore client/ and extension/ so we don't trigger backend deployments
# when only frontend code changes.
jobs:
deploy:
name: Deploy to EC2
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Deploy via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
# Go to the project directory
cd ~/AppliTrack
# Pull the latest code
git pull origin master
# Make sure Docker is installed (just in case)
if ! command -v docker &> /dev/null; then
echo "Cleaning up any broken previous Docker APT repositories..."
sudo rm -f /etc/apt/sources.list.d/*docker*.list
sudo apt-get update -qq || true
echo "Installing Docker..."
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker ubuntu
rm get-docker.sh
fi
# Make sure Docker Compose is available
if ! command -v docker-compose &> /dev/null; then
sudo curl -L "https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
fi
# Rebuild and restart the backend and redis containers in the background
# using the local postgres database via host.docker.internal (if configured)
sudo docker-compose up -d --build
# Cleanup old unused docker images to save EC2 disk space
sudo docker image prune -f