Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Deploy

on:
workflow_run:
workflows: ["Run Tests"]
types: [completed]
workflow_dispatch:

jobs:
deploy:
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success' &&
(github.event.workflow_run.head_branch == 'main' || github.event.workflow_run.head_branch == 'github-actions'))
name: "Deploy to VPS"
runs-on: ubuntu-latest
steps:
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy-key.pem
chmod 600 ~/.ssh/deploy-key.pem
cat >> ~/.ssh/config <<END
Host my-vps
HostName $SSH_IP
User $SSH_USER
IdentityFile ~/.ssh/deploy-key.pem
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_IP: ${{ secrets.SSH_IP }}

- name: Redeploy Site
run: |
ssh my-vps '~/redeploy-site.sh' \
ssh my-vps 'yes | cp ~/PE-portfolio/scripts/redeploy-site.sh ~/redeploy-site.sh'
13 changes: 0 additions & 13 deletions scripts/count_data_points_before_cleaning copy.sh

This file was deleted.

62 changes: 62 additions & 0 deletions scripts/redeploy-site.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
# Set up a virtual environment "python3-virtualenv" before executing this script

set -eo pipefail

PROJECT_DIR="$HOME/graph-uf/"
URL="https://www.aleguy02.dev"
MAX_RETRIES=5


echo "=== pulling in latest changes ==="

cd $PROJECT_DIR
git fetch && git reset origin/main --hard > /dev/null


echo "=== spinning down containers ==="

docker compose -f compose.yaml down > /dev/null


echo "=== rebuilding containers ==="

docker compose -f compose.yaml up -d --build > /dev/null


echo "=== validating service ==="

required_containers=("graphuf")

for container in "${required_containers[@]}"; do
if ! docker ps --format '{{.Names}}' | grep -q "^${container}$"; then
echo "!! Required container '$container' is not running. !!"
exit 1
fi
done

# Health check with retries
retry_count=0
while [ $retry_count -lt $MAX_RETRIES ]; do
if [ "$(curl --head $URL/health | awk '/^HTTP/{print $2}')" = "200" ]; then
echo "Health check passed"
break
fi

retry_count=$((retry_count + 1))
echo "Health check attempt $retry_count/$MAX_RETRIES failed"

if [ $retry_count -lt $MAX_RETRIES ]; then
echo "Retrying in 7 seconds..."
sleep 7
fi
done
if [ $retry_count -eq $MAX_RETRIES ]; then
echo "!! Could not reach the site at $URL/health or received a non-200 HTTP response. !!"
exit 1
fi


echo "=== redeployment complete ==="

echo "View the site at $URL"