Repository navigation
127 lines (107 loc) · 3.19 KB
/
Copy pathci-cd.yml
File metadata and controls
127 lines (107 loc) · 3.19 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
126
127
name: CI-CD Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
name: Run tests
runs-on: ubuntu-latest
services:
redis:
image: redis:latest
ports:
- 6379:6379
options: --health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
postgres:
image: postgres:16-alpine
ports:
- 5432:5432
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: testdb
options: >-
--health-cmd "pg_isready -U test"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Generate Prisma Client
run: npx prisma generate
env:
DATABASE_URL: "postgresql://fake:fake@localhost:5432/fake"
- name: Run Prisma migrations
run: npx prisma migrate deploy
env:
DATABASE_URL: "postgresql://test:test@localhost:5432/testdb"
- name: Run tests
run: npm test
env:
NODE_ENV: test
BASE_URL: "http://localhost:3000"
DATABASE_URL: "postgresql://test:test@localhost:5432/testdb"
REDIS_URL: "redis://localhost:6379"
EMAIL_HOST: "smtp.gmail.com"
EMAIL_PORT: "587"
EMAIL_USER: ${{ secrets.EMAIL_USER }}
EMAIL_PASS: ${{ secrets.EMAIL_PASS }}
ACCESS_SECRET: ${{ secrets.ACCESS_SECRET }}
REFRESH_SECRET: ${{ secrets.REFRESH_SECRET }}
ACCESS_EXPIRES_IN: "15m"
REFRESH_EXPIRES_IN: "7d"
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
FRONTEND_URL: "http://localhost:3000"
build-and-push:
name: Build and push to Docker Hub
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/notifierapi:latest
- name: Deployed to Docker Hub
run: echo "Deployed to Docker Hub"
deploy:
name: Deploy to VPS
runs-on: ubuntu-latest
needs: build-and-push
steps:
- name: Deploy via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: 22
script: |
cd ~/notifierapi
docker compose pull
docker compose up -d
docker image prune -f