Not the way #35
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |