mirror of
https://github.com/blackboxprogramming/alexa-amundson-resume.git
synced 2026-03-18 02:03:58 -05:00
feat: add real Stripe integration, e2e tests, and Pi deployment
Replace documentation-only repo with working code: - Stripe integration: webhook handler (8 event types), billing API (customers, checkout, payments, subscriptions, invoices) - Express API server with health endpoint, structured logging - E2E tests (Playwright): health, webhook signature verification, billing API validation - Unit tests: webhook event handler coverage for all event types - Pi deployment: deploy.sh (rsync + systemd), NGINX load balancer across Pi cluster, Docker support - CI/CD: test workflow, Pi deploy workflow, updated auto-deploy and self-healing to run real tests before deploying - Move resume docs to docs/ to separate code from documentation https://claude.ai/code/session_01Mf5Pg82fV6BTRS9GnpV7nr
This commit is contained in:
78
.github/workflows/auto-deploy.yml
vendored
78
.github/workflows/auto-deploy.yml
vendored
@@ -1,25 +1,41 @@
|
||||
name: 🚀 Auto Deploy
|
||||
name: Auto Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main, master]
|
||||
paths:
|
||||
- 'src/**'
|
||||
- 'package.json'
|
||||
- 'Dockerfile'
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
NODE_VERSION: '20'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Run Tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: 'npm'
|
||||
- run: npm ci
|
||||
- run: npm test
|
||||
|
||||
detect-service:
|
||||
name: Detect Service Type
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
outputs:
|
||||
service_type: ${{ steps.detect.outputs.service_type }}
|
||||
deploy_target: ${{ steps.detect.outputs.deploy_target }}
|
||||
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Detect Service Type
|
||||
id: detect
|
||||
run: |
|
||||
@@ -45,27 +61,21 @@ jobs:
|
||||
needs: detect-service
|
||||
if: needs.detect-service.outputs.deploy_target == 'cloudflare'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v4
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- run: npm ci
|
||||
- run: npm run build
|
||||
env:
|
||||
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: ${{ secrets.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY }}
|
||||
|
||||
- name: Deploy to Cloudflare Pages
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
|
||||
- uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
@@ -76,14 +86,13 @@ jobs:
|
||||
needs: detect-service
|
||||
if: needs.detect-service.outputs.deploy_target == 'railway'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Railway CLI
|
||||
run: npm i -g @railway/cli
|
||||
|
||||
|
||||
- name: Deploy to Railway
|
||||
run: railway up --service ${{ github.event.repository.name }}
|
||||
env:
|
||||
@@ -94,22 +103,15 @@ jobs:
|
||||
needs: [deploy-cloudflare, deploy-railway]
|
||||
if: always() && (needs.deploy-cloudflare.result == 'success' || needs.deploy-railway.result == 'success')
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
||||
steps:
|
||||
- name: Wait for Deployment
|
||||
run: sleep 30
|
||||
|
||||
|
||||
- name: Check Health Endpoint
|
||||
run: |
|
||||
URL="${{ secrets.DEPLOY_URL }}/api/health"
|
||||
curl -f $URL || exit 1
|
||||
|
||||
- name: Notify Success
|
||||
if: success()
|
||||
run: echo "✅ Deployment successful and healthy!"
|
||||
|
||||
- name: Notify Failure
|
||||
if: failure()
|
||||
run: |
|
||||
echo "❌ Deployment health check failed!"
|
||||
exit 1
|
||||
echo "Checking $URL..."
|
||||
RESPONSE=$(curl -sf "$URL" 2>&1) || { echo "Health check failed"; exit 1; }
|
||||
echo "$RESPONSE"
|
||||
echo "$RESPONSE" | grep -q '"status":"ok"' || { echo "Unexpected health response"; exit 1; }
|
||||
|
||||
57
.github/workflows/deploy-pi.yml
vendored
Normal file
57
.github/workflows/deploy-pi.yml
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
name: Deploy to Pi
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [main, master]
|
||||
paths:
|
||||
- 'src/**'
|
||||
- 'package.json'
|
||||
- 'Dockerfile'
|
||||
- 'deploy/**'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Run Tests First
|
||||
uses: ./.github/workflows/test.yml
|
||||
|
||||
deploy:
|
||||
name: Deploy to Raspberry Pi Nodes
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup SSH key
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.PI_SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
ssh-keyscan -H ${{ secrets.PI_HOST_1 }} >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||
ssh-keyscan -H ${{ secrets.PI_HOST_2 }} >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||
ssh-keyscan -H ${{ secrets.PI_HOST_3 }} >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||
|
||||
- name: Create .env for deployment
|
||||
run: |
|
||||
cat > .env <<EOF
|
||||
STRIPE_SECRET_KEY=${{ secrets.STRIPE_SECRET_KEY }}
|
||||
STRIPE_PUBLISHABLE_KEY=${{ secrets.STRIPE_PUBLISHABLE_KEY }}
|
||||
STRIPE_WEBHOOK_SECRET=${{ secrets.STRIPE_WEBHOOK_SECRET }}
|
||||
PORT=3000
|
||||
NODE_ENV=production
|
||||
PI_HOST_1=${{ secrets.PI_HOST_1 }}
|
||||
PI_HOST_2=${{ secrets.PI_HOST_2 }}
|
||||
PI_HOST_3=${{ secrets.PI_HOST_3 }}
|
||||
PI_USER=${{ secrets.PI_USER }}
|
||||
PI_DEPLOY_PATH=/opt/blackroad
|
||||
PI_SSH_KEY=~/.ssh/id_ed25519
|
||||
EOF
|
||||
|
||||
- name: Deploy to Pis
|
||||
run: bash deploy/pi/deploy.sh
|
||||
|
||||
- name: Cleanup
|
||||
if: always()
|
||||
run: rm -f .env ~/.ssh/id_ed25519
|
||||
67
.github/workflows/self-healing.yml
vendored
67
.github/workflows/self-healing.yml
vendored
@@ -1,78 +1,73 @@
|
||||
name: 🔧 Self-Healing
|
||||
name: Self-Healing
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '*/30 * * * *' # Every 30 minutes
|
||||
- cron: '*/30 * * * *'
|
||||
workflow_dispatch:
|
||||
workflow_run:
|
||||
workflows: ["🚀 Auto Deploy"]
|
||||
workflows: ["Auto Deploy"]
|
||||
types: [completed]
|
||||
|
||||
jobs:
|
||||
monitor:
|
||||
name: Monitor Deployments
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Check Health
|
||||
id: health
|
||||
run: |
|
||||
if [ ! -z "${{ secrets.DEPLOY_URL }}" ]; then
|
||||
STATUS=$(curl -s -o /dev/null -w "%{http_code}" ${{ secrets.DEPLOY_URL }}/api/health || echo "000")
|
||||
if [ -n "${{ secrets.DEPLOY_URL }}" ]; then
|
||||
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${{ secrets.DEPLOY_URL }}/api/health" || echo "000")
|
||||
echo "status=$STATUS" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "status=skip" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
|
||||
- name: Auto-Rollback
|
||||
if: steps.health.outputs.status != '200' && steps.health.outputs.status != 'skip'
|
||||
run: |
|
||||
echo "🚨 Health check failed (Status: ${{ steps.health.outputs.status }})"
|
||||
echo "Health check failed (Status: ${{ steps.health.outputs.status }})"
|
||||
echo "Triggering rollback..."
|
||||
gh workflow run auto-deploy.yml --ref $(git rev-parse HEAD~1)
|
||||
gh workflow run auto-deploy.yml --ref $(git rev-parse HEAD~1) || true
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
|
||||
- name: Attempt Auto-Fix
|
||||
if: steps.health.outputs.status != '200' && steps.health.outputs.status != 'skip'
|
||||
run: |
|
||||
echo "🔧 Attempting automatic fixes..."
|
||||
# Check for common issues
|
||||
if [ -f "package.json" ]; then
|
||||
npm ci || true
|
||||
npm run build || true
|
||||
fi
|
||||
|
||||
|
||||
- name: Create Issue on Failure
|
||||
if: failure()
|
||||
if: steps.health.outputs.status != '200' && steps.health.outputs.status != 'skip'
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
github.rest.issues.create({
|
||||
const issues = await github.rest.issues.listForRepo({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
title: '🚨 Self-Healing: Deployment Health Check Failed',
|
||||
body: `Deployment health check failed.\n\nStatus: ${{ steps.health.outputs.status }}\nWorkflow: ${context.workflow}\nRun: ${context.runId}`,
|
||||
labels: ['bug', 'deployment', 'auto-generated']
|
||||
})
|
||||
labels: 'deployment,auto-generated',
|
||||
state: 'open',
|
||||
});
|
||||
if (issues.data.length < 3) {
|
||||
github.rest.issues.create({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
title: 'Self-Healing: Health Check Failed (Status: ${{ steps.health.outputs.status }})',
|
||||
body: `Health check failed.\n\nStatus: ${{ steps.health.outputs.status }}\nWorkflow: ${context.workflow}\nRun: ${context.runId}\nTimestamp: ${new Date().toISOString()}`,
|
||||
labels: ['bug', 'deployment', 'auto-generated']
|
||||
});
|
||||
}
|
||||
|
||||
dependency-updates:
|
||||
name: Auto Update Dependencies
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
if: hashFiles('package.json') != ''
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
|
||||
|
||||
- name: Update npm dependencies
|
||||
if: hashFiles('package.json') != ''
|
||||
run: |
|
||||
|
||||
51
.github/workflows/test.yml
vendored
Normal file
51
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
name: Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main, master, 'claude/**']
|
||||
pull_request:
|
||||
branches: [main, master]
|
||||
|
||||
env:
|
||||
NODE_VERSION: '20'
|
||||
|
||||
jobs:
|
||||
unit-tests:
|
||||
name: Unit Tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: 'npm'
|
||||
|
||||
- run: npm ci
|
||||
|
||||
- name: Run unit tests
|
||||
run: npm test
|
||||
|
||||
e2e-tests:
|
||||
name: E2E Tests
|
||||
runs-on: ubuntu-latest
|
||||
needs: unit-tests
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: 'npm'
|
||||
|
||||
- run: npm ci
|
||||
|
||||
- name: Install Playwright
|
||||
run: npx playwright install --with-deps chromium
|
||||
|
||||
- name: Run E2E tests
|
||||
run: npm run test:e2e
|
||||
env:
|
||||
STRIPE_SECRET_KEY: sk_test_placeholder
|
||||
STRIPE_WEBHOOK_SECRET: whsec_test_secret
|
||||
NODE_ENV: test
|
||||
Reference in New Issue
Block a user