-
Notifications
You must be signed in to change notification settings - Fork 11
68 lines (61 loc) · 2.24 KB
/
deploy.yml
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
name: Deploy to DigitalOcean
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Create VPS if it doesn't exist
run: |
if ! doctl compute droplet list | grep -q 'mautic-vps'; then
doctl compute droplet create mautic-vps --image docker-20-04 --size s-1vcpu-1gb --region nyc1 --ssh-keys ${{ secrets.DIGITALOCEAN_SSH_FINGERPRINT }} --wait --user-data-file setup.sh --enable-monitoring
echo "droplet_created=true" >> $GITHUB_ENV
else
echo "Droplet 'mautic-vps' already exists."
echo "droplet_created=true" >> $GITHUB_ENV
fi
- name: Get VPS IP
run: |
while : ; do
echo "Waiting for droplet to be ready..."
sleep 5
STATUS=$(doctl compute droplet get mautic-vps --format Status --no-header)
if [ "$STATUS" = "active" ]; then
IP=$(doctl compute droplet get mautic-vps --format PublicIPv4 --no-header)
if [ -n "$IP" ]; then
break
fi
fi
done
echo "ip=$IP" >> $GITHUB_ENV
- name: Deploy to Server
uses: easingthemes/ssh-deploy@main
with:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
ARGS: "-rlgoDzvc --delete"
SOURCE: "."
REMOTE_HOST: ${{ env.ip }}
REMOTE_USER: root
TARGET: /var/www/${{ github.repository }}
EXCLUDE: ".git"
SCRIPT_BEFORE: |
mkdir -p /var/www/${{ github.repository }}
SCRIPT_AFTER: |
echo $RSYNC_STDOUT
cd /var/www/${{ github.repository }}
pwd
ls -la
docker compose up -d
mv nginx-virtual-host ./${{ env.DOMAIN_NAME }}
sed -i '' 's/DOMAIN_NAME/${{ env.DOMAIN_NAME }}/g; s/PORT/${{ env.MAUTIC_PORT || '8001' }}/g' ${{ env.DOMAIN_NAME }}
sudo ln -s ${{ env.DOMAIN_NAME }} /etc/nginx/sites-enabled/
nginx -t && nginx -s reload
sudo certbot --nginx -d {{ env.DOMAIN_NAME }} --non-interactive --agree-tos --email ${{ env.EMAIL }}