-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (116 loc) · 4.18 KB
/
Copy pathci.yml
File metadata and controls
125 lines (116 loc) · 4.18 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun run lint
type-check:
name: Type Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun run type-check
test:
name: Test
runs-on: ubuntu-latest
continue-on-error: true
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: financetracker_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/financetracker_test
BETTER_AUTH_SECRET: test-secret-for-ci-only-not-for-production
BETTER_AUTH_URL: http://localhost:4006
NODE_ENV: test
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- name: Setup database
run: bun run db:push
- name: Run tests
run: bun run test
deploy-production:
name: Deploy to VPS
runs-on: ubuntu-latest
needs: [lint, type-check]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
environment: production
steps:
- uses: actions/checkout@v4
- name: Clean old source on VPS
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.VPS_HOST_CONTABO }}
username: ${{ secrets.VPS_USERNAME_CONTABO }}
key: ${{ secrets.VPS_SSHKEY_CONTABO }}
port: ${{ secrets.VPS_PORT_CONTABO || '22' }}
script: |
cd ${{ secrets.VPS_TARGET_DIR }}
# Remove stale source directories so SCP writes a clean copy
rm -rf server/ db/
- name: Copy fresh source to VPS
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.VPS_HOST_CONTABO }}
username: ${{ secrets.VPS_USERNAME_CONTABO }}
key: ${{ secrets.VPS_SSHKEY_CONTABO }}
port: ${{ secrets.VPS_PORT_CONTABO || '22' }}
source: "server/,db/,package.json,bun.lock,docker-compose.yml,Dockerfile,tsconfig.json,.dockerignore,deploy.sh"
target: ${{ secrets.VPS_TARGET_DIR }}/
overwrite: true
- name: Deploy on VPS
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.VPS_HOST_CONTABO }}
username: ${{ secrets.VPS_USERNAME_CONTABO }}
key: ${{ secrets.VPS_SSHKEY_CONTABO }}
port: ${{ secrets.VPS_PORT_CONTABO || '22' }}
script: |
cd ${{ secrets.VPS_TARGET_DIR }}
chown deploy:deploy .env 2>/dev/null || true
# Ensure the DB container is running before deploying app
docker compose --env-file .env up -d db
# Wait for Postgres to be ready (up to 30s)
timeout 30 sh -c 'until docker compose --env-file .env exec -T db pg_isready -U ${DB_USER:-postgres}; do sleep 2; done' || true
# Rebuild and restart only the app container
docker compose --env-file .env stop app
# FORCE clean build without cache
docker compose --env-file .env build --no-cache app
docker compose --env-file .env up -d --force-recreate --no-deps app
# Run migrations after app starts
sleep 5
docker compose --env-file .env exec -T app npm run db:push || true
docker image prune -f
# Verify new routes are reachable
sleep 3
echo "=== POST-DEPLOY VERIFICATION ==="
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:4015/docs)
echo "/docs status: $HTTP_CODE"
if [ "$HTTP_CODE" = "404" ]; then
echo "ERROR: /docs still returns 404 — deploy may have failed!"
exit 1
fi
echo "Deploy verified successfully."