Skip to content

Commit 147496e

Browse files
committed
feat: try add support deploy to vercel
1 parent 181de5d commit 147496e

File tree

20 files changed

+526
-155
lines changed

20 files changed

+526
-155
lines changed

.github/workflows/kubernetes.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ env:
1010
NX_DAEMON: false
1111
NX_PARALLEL: 1
1212
NX_SKIP_NX_CACHE: true
13-
DISABLE_SERVE_STATIC: true
1413
jobs:
1514
release:
1615
runs-on: ubuntu-latest

.github/workflows/vercel.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Deploy to Vercel
2+
3+
on:
4+
push:
5+
branches: ['master', 'vercel']
6+
7+
jobs:
8+
build-and-deploy:
9+
environment: vercel
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
if: ${{ !contains(github.event.head_commit.message, '[skip deploy]') }}
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Node.js
18+
if: ${{ !contains(github.event.head_commit.message, '[skip deploy]') }}
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '22.11.0'
22+
23+
- name: Install dependencies
24+
if: ${{ !contains(github.event.head_commit.message, '[skip deploy]') }}
25+
uses: borales/actions-yarn@v4
26+
with:
27+
cmd: install
28+
29+
- name: Install Vercel CLI
30+
if: ${{ !contains(github.event.head_commit.message, '[skip deploy]') }}
31+
run: npm install --global vercel@latest
32+
33+
- name: Pull Vercel Environment Information
34+
if: ${{ !contains(github.event.head_commit.message, '[skip deploy]') }}
35+
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
36+
37+
- name: Build project
38+
if: ${{ !contains(github.event.head_commit.message, '[skip deploy]') }}
39+
run: |
40+
cp -r .vercel/.env.production.local .env
41+
npx --yes tsx update-files-for-vercel.ts
42+
npm run manual-supabase-build
43+
44+
- name: Remove devDependencies
45+
if: ${{ !contains(github.event.head_commit.message, '[skip deploy]') }}
46+
run: echo $(cat package.json | jq 'del(.devDependencies)') > package.json
47+
48+
- name: Remove yarn lock file
49+
if: ${{ !contains(github.event.head_commit.message, '[skip deploy]') }}
50+
run: rm -rf yarn.lock
51+
52+
- name: Copy the settings
53+
if: ${{ !contains(github.event.head_commit.message, '[skip deploy]') }}
54+
run: cp -r .docker/nx.json nx.json
55+
56+
- name: Install only prod dependencies
57+
if: ${{ !contains(github.event.head_commit.message, '[skip deploy]') }}
58+
uses: borales/actions-yarn@v4
59+
with:
60+
cmd: install --prod
61+
62+
- name: Installing utilities to generate additional files
63+
if: ${{ !contains(github.event.head_commit.message, '[skip deploy]') }}
64+
run: yarn add [email protected] [email protected] @brakebein/[email protected] tslib -D
65+
66+
- name: Generate prisma clients
67+
if: ${{ !contains(github.event.head_commit.message, '[skip deploy]') }}
68+
run: npm run prisma:generate
69+
70+
- name: Build Project Artifacts
71+
if: ${{ !contains(github.event.head_commit.message, '[skip deploy]') }}
72+
run: vercel build --token=${{ secrets.VERCEL_TOKEN }} --prod
73+
74+
- name: Deploy Project Artifacts to Vercel
75+
if: ${{ !contains(github.event.head_commit.message, '[skip deploy]') }}
76+
run: vercel deploy --yes --prebuilt --prod --archive=tgz --token=${{ secrets.VERCEL_TOKEN }}
77+
78+
e2e-tests:
79+
environment: vercel
80+
runs-on: ubuntu-latest
81+
needs: [build-and-deploy]
82+
83+
steps:
84+
- name: Checkout code
85+
if: ${{ !contains(github.event.head_commit.message, '[skip e2e]') }}
86+
uses: actions/checkout@v4
87+
88+
- name: Set up Node.js
89+
if: ${{ !contains(github.event.head_commit.message, '[skip e2e]') }}
90+
uses: actions/setup-node@v4
91+
with:
92+
node-version: '22.11.0'
93+
94+
- name: Install dependencies
95+
if: ${{ !contains(github.event.head_commit.message, '[skip e2e]') }}
96+
uses: borales/actions-yarn@v4
97+
with:
98+
cmd: install
99+
100+
- name: Install Vercel CLI
101+
if: ${{ !contains(github.event.head_commit.message, '[skip e2e]') }}
102+
run: npm install --global vercel@latest
103+
104+
- name: Pull Vercel Environment Information
105+
if: ${{ !contains(github.event.head_commit.message, '[skip e2e]') }}
106+
run: |
107+
vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
108+
cp -r .vercel/.env.production.local .env
109+
npx --yes tsx update-files-for-vercel.ts
110+
111+
- name: Generate prisma clients
112+
if: ${{ !contains(github.event.head_commit.message, '[skip e2e]') }}
113+
run: npm run prisma:generate
114+
115+
- name: Run e2e-tests
116+
if: ${{ !contains(github.event.head_commit.message, '[skip e2e]') }}
117+
run: |
118+
export BASE_URL=https://nestjs-mod-fullstack.vercel.app
119+
export CLIENT_URL=https://nestjs-mod-fullstack.vercel.app
120+
export SERVER_URL=https://nestjs-mod-fullstack.vercel.app/api
121+
cp -r .vercel/.env.production.local .env
122+
npx --yes tsx update-files-for-vercel.ts
123+
npx playwright install chromium --with-deps
124+
npm run test:e2e
125+
- uses: actions/upload-artifact@v4
126+
if: ${{ !contains(github.event.head_commit.message, '[skip e2e]') }}
127+
with:
128+
name: e2e-tests-videos
129+
path: apps/client-e2e/src/video/

.kubernetes/set-env.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export COMPOSE_INTERACTIVE_NO_CLI=1
1313
export NX_DAEMON=false
1414
export NX_PARALLEL=1
1515
export NX_SKIP_NX_CACHE=true
16-
export DISABLE_SERVE_STATIC=true
1716

1817

1918
if [ -z "${ROOT_VERSION}" ]; then

.kubernetes/templates/server/1.configmap.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,5 @@ data:
2424
SERVER_SSO_SERVER_URL: 'https://%SERVER_DOMAIN%'
2525
SERVER_SSO_GOOGLE_OAUTH_CLIENT_ID: '%SERVER_SSO_GOOGLE_OAUTH_CLIENT_ID%'
2626
SERVER_SSO_GOOGLE_OAUTH_CLIENT_SECRET_KEY: '%SERVER_SSO_GOOGLE_OAUTH_CLIENT_SECRET_KEY%'
27-
SERVER_SSO_JWT_ACCESS_TOKEN_EXPIRES_IN: '30m'
28-
SERVER_SSO_JWT_REFRESH_TOKEN_EXPIRES_IN: '24h'
2927
SERVER_SSO_DEFAULT_PUBLIC_PROJECTS: 'Beijing:ru=Пекин,Jq6GQ6Rzz6x8HNOD4x2Hc2eM0cfiCVUzGfsi,X6nk0OZXQJboSEfugnH35e9oSeg5RFlV0DQprtYyYDQjNli9mA;Moscow:ru=Москва,OceX08HGZ89PTkPpg9KDk5ErY1uMfDcfFKkw,VJztpDIwvqG6IkTVEIDEw1Ed2Wu5oHu6zfBe7CCJFrCtyWO2Yv;New York:ru=Нью-Йорк,4OGD25Rmn3W3MP0kMd7c90rGP1WwK8u4wL1w,qm8nc9MgKyvd6Hgl3jY5BjgDFSBqNvxcu6o52kDjIC168OsM1R;'
3028
SERVER_SSO_DEFAULT_PROJECT: 'default:ru=по умолчанию,KzMRNEZTetzatIgQPVSDYfeGyaZrbLzkcxNc,qaHkVpAtUVIpDdLXMlAOzsBfMRJblWoHpXguYQRBuSEBpGKbWt'

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,67 @@ npm run docker-compose-full:prod:test:e2e
115115
npm run docker-compose-full:prod:stop
116116
```
117117

118+
## Supabase Dev/Watch mode
119+
120+
Infrastructure is running on [Supabase](https://supabase.com/), applications are launched in watch pm2 mode.
121+
122+
### Init
123+
124+
```sh
125+
git clone [email protected]:nestjs-mod/nestjs-mod-sso.git
126+
cd nestjs-mod-sso
127+
npm i
128+
cp ./example-supabase.env ./.env
129+
```
130+
131+
### Prepare
132+
133+
1. Create organization and project on [Supabase](https://supabase.com/)
134+
2. Create bucket "images" in storage (example link: https://supabase.com/dashboard/project/XXX/storage/buckets)
135+
3. Create new "S3 Access Keys" with "Access key ID" and "Secret access key" (example link: https://supabase.com/dashboard/project/gustcjgbrmmipkizqzso/settings/storage)
136+
4. Open `.env` and fill empty_value's
137+
138+
```sh
139+
# https://supabase.com/dashboard/project/XXX/settings/api - API Settings - Project URL - URL
140+
SUPABASE_URL=empty_value
141+
# https://supabase.com/dashboard/project/XXX/settings/database?showConnect=true - Connection String - Direct connection
142+
POSTGRES_URL=empty_value
143+
# https://supabase.com/dashboard/project/XXX/settings/api - API Settings - Project API Keys - anon public
144+
SUPABASE_ANON_KEY=empty_value
145+
# https://supabase.com/dashboard/project/gustcjgbrmmipkizqzso/settings/storage - S3 Access Keys - New access key - Access key ID
146+
SERVER_MINIO_ACCESS_KEY=empty_value
147+
# https://supabase.com/dashboard/project/gustcjgbrmmipkizqzso/settings/storage - S3 Access Keys - New access key - Secret access key
148+
SERVER_MINIO_SECRET_KEY=empty_value
149+
```
150+
151+
5. Create and fill all need new env keys
152+
153+
```sh
154+
npx --yes tsx update-files-for-vercel.ts
155+
```
156+
157+
### Start
158+
159+
```sh
160+
npm run pm2-supabase-full:dev:start
161+
```
162+
163+
### Open in browser
164+
165+
http://localhost:4200
166+
167+
### Testing
168+
169+
```sh
170+
npm run pm2-supabase-full:dev:test:e2e
171+
```
172+
173+
### Stop
174+
175+
```sh
176+
npm run pm2-supabase-full:dev:stop
177+
```
178+
118179
## Links
119180

120181
- https://sso.nestjs-mod.com - live demo on Kubernetes

apps/client/project.json

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
"targets": {
99
"build": {
1010
"executor": "@angular-devkit/build-angular:browser",
11-
"outputs": [
12-
"{options.outputPath}"
13-
],
11+
"outputs": ["{options.outputPath}"],
1412
"options": {
1513
"allowedCommonJsDependencies": [
1614
"@jsverse/transloco-messageformat",
@@ -22,9 +20,7 @@
2220
"outputPath": "dist/apps/client/browser",
2321
"index": "apps/client/src/index.html",
2422
"main": "apps/client/src/main.ts",
25-
"polyfills": [
26-
"zone.js"
27-
],
23+
"polyfills": ["zone.js"],
2824
"tsConfig": "apps/client/tsconfig.app.json",
2925
"inlineStyleLanguage": "scss",
3026
"assets": [
@@ -44,9 +40,7 @@
4440
"output": "./"
4541
}
4642
],
47-
"styles": [
48-
"apps/client/src/styles.scss"
49-
],
43+
"styles": ["apps/client/src/styles.scss"],
5044
"scripts": []
5145
},
5246
"configurations": {
@@ -71,6 +65,48 @@
7165
}
7266
]
7367
},
68+
"supabase-prod": {
69+
"budgets": [
70+
{
71+
"type": "initial",
72+
"maximumWarning": "600kb",
73+
"maximumError": "5mb"
74+
},
75+
{
76+
"type": "anyComponentStyle",
77+
"maximumWarning": "2kb",
78+
"maximumError": "4kb"
79+
}
80+
],
81+
"outputHashing": "all",
82+
"fileReplacements": [
83+
{
84+
"replace": "apps/client/src/environments/environment.ts",
85+
"with": "apps/client/src/environments/environment.supabase-prod.ts"
86+
}
87+
]
88+
},
89+
"supabase": {
90+
"budgets": [
91+
{
92+
"type": "initial",
93+
"maximumWarning": "600kb",
94+
"maximumError": "5mb"
95+
},
96+
{
97+
"type": "anyComponentStyle",
98+
"maximumWarning": "2kb",
99+
"maximumError": "4kb"
100+
}
101+
],
102+
"outputHashing": "all",
103+
"fileReplacements": [
104+
{
105+
"replace": "apps/client/src/environments/environment.ts",
106+
"with": "apps/client/src/environments/environment.supabase.ts"
107+
}
108+
]
109+
},
74110
"development": {
75111
"buildOptimizer": false,
76112
"optimization": false,
@@ -90,6 +126,12 @@
90126
},
91127
"development": {
92128
"buildTarget": "client:build:development"
129+
},
130+
"supabase-prod": {
131+
"buildTarget": "client:build:supabase-prod"
132+
},
133+
"supabase": {
134+
"buildTarget": "client:build:supabase"
93135
}
94136
},
95137
"defaultConfiguration": "development"
@@ -105,17 +147,13 @@
105147
},
106148
"test": {
107149
"executor": "@nx/jest:jest",
108-
"outputs": [
109-
"{workspaceRoot}/coverage/{projectRoot}"
110-
],
150+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
111151
"options": {
112152
"jestConfig": "apps/client/jest.config.ts"
113153
}
114154
},
115155
"server": {
116-
"dependsOn": [
117-
"build"
118-
],
156+
"dependsOn": ["build"],
119157
"executor": "@angular-devkit/build-angular:server",
120158
"options": {
121159
"outputPath": "dist/apps/client/server",
@@ -154,9 +192,7 @@
154192
"prerender": {
155193
"executor": "@angular-devkit/build-angular:prerender",
156194
"options": {
157-
"routes": [
158-
"/"
159-
]
195+
"routes": ["/"]
160196
},
161197
"configurations": {
162198
"development": {
@@ -191,4 +227,4 @@
191227
}
192228
}
193229
}
194-
}
230+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const serverUrl = '';
2+
export const minioURL =
3+
'https://jfbdymapjznbbtldxdqn.supabase.co/storage/v1/s3';
4+
export const supabaseURL = 'https://jfbdymapjznbbtldxdqn.supabase.co';
5+
export const supabaseKey =
6+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImpmYmR5bWFwanpuYmJ0bGR4ZHFuIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDU5ODQzNzcsImV4cCI6MjA2MTU2MDM3N30.F6gLS-LZoz2z5EjaepgoAG57xp0V0Mdm8m8SJHMQJNw';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const serverUrl = 'http://localhost:3000';
2+
export const minioURL =
3+
'https://jfbdymapjznbbtldxdqn.supabase.co/storage/v1/s3';
4+
export const supabaseURL = 'https://jfbdymapjznbbtldxdqn.supabase.co';
5+
export const supabaseKey =
6+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImpmYmR5bWFwanpuYmJ0bGR4ZHFuIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDU5ODQzNzcsImV4cCI6MjA2MTU2MDM3N30.F6gLS-LZoz2z5EjaepgoAG57xp0V0Mdm8m8SJHMQJNw';

0 commit comments

Comments
 (0)