Skip to content

Commit 406ad69

Browse files
authored
Docker compose dependencies (stack-auth#20)
1 parent bcce00f commit 406ad69

File tree

16 files changed

+159
-175
lines changed

16 files changed

+159
-175
lines changed

.github/workflows/e2e-api-tests.yaml

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,13 @@ name: Runs E2E API Tests
22

33
on:
44
push:
5-
branches: [main, dev]
6-
pull_request:
7-
branches: [main, dev]
5+
branches:
6+
- '*'
87

98
jobs:
109
build:
1110
runs-on: ubuntu-latest
1211

13-
env:
14-
SERVER_BASE_URL: http://localhost:8101
15-
PROJECT_CLIENT_ID: ${{ secrets.PROJECT_CLIENT_ID }}
16-
PROJECT_CLIENT_KEY: ${{ secrets.PROJECT_CLIENT_KEY }}
17-
18-
NEXT_PUBLIC_STACK_URL: http://localhost:8101
19-
NEXT_PUBLIC_STACK_PROJECT_ID: ${{ secrets.PROJECT_CLIENT_ID }}
20-
NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY: ${{ secrets.PROJECT_CLIENT_KEY }}
21-
STACK_SECRET_SERVER_KEY: test
22-
SERVER_SECRET: 23-wuNpik0gIW4mruTz25rbIvhuuvZFrLOLtL7J4tyo
23-
24-
EMAIL_HOST: 0.0.0.0
25-
EMAIL_PORT: 2500
26-
EMAIL_SECURE: false
27-
EMAIL_USERNAME: test
28-
EMAIL_PASSWORD: none
29-
EMAIL_SENDER: noreply@test.com
30-
31-
DATABASE_CONNECTION_STRING: ${{ secrets.DATABASE_CONNECTION_STRING }}
32-
DIRECT_DATABASE_CONNECTION_STRING: ${{ secrets.DATABASE_CONNECTION_STRING }}
33-
3412
strategy:
3513
matrix:
3614
node-version: [20.x]
@@ -45,9 +23,47 @@ jobs:
4523
uses: pnpm/action-setup@v3
4624
with:
4725
version: 8
26+
27+
- name: Create .env.local file for stack-server
28+
run: |
29+
cat > packages/stack-server/.env.local <<EOF
30+
NEXT_PUBLIC_STACK_URL=http://localhost:8101
31+
NEXT_PUBLIC_STACK_PROJECT_ID=internal
32+
NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=internal-project-client-api-key
33+
STACK_SECRET_SERVER_KEY=internal-project-server-api-key
34+
SERVER_SECRET=23-wuNpik0gIW4mruTz25rbIvhuuvZFrLOLtL7J4tyo
35+
36+
EMAIL_HOST=0.0.0.0
37+
EMAIL_PORT=2500
38+
EMAIL_SECURE=false
39+
EMAIL_USERNAME=some-username
40+
EMAIL_PASSWORD=some-password
41+
EMAIL_SENDER=noreply@example.com
42+
43+
DATABASE_CONNECTION_STRING=postgres://postgres:password@localhost:5432/stackframe
44+
DIRECT_DATABASE_CONNECTION_STRING=postgres://postgres:password@localhost:5432/stackframe
45+
EOF
46+
4847
- name: Install dependencies
4948
run: pnpm install
50-
- name: Build
49+
50+
- name: Start Docker Compose
51+
run: docker-compose -f dependencies.compose.yaml up -d
52+
- name: Initialize database
53+
run: pnpm run prisma:server -- migrate reset --force
54+
55+
- name: Build stack-server
5156
run: pnpm build:server
52-
- name: Start server & run tests
53-
run: pnpm -C packages/stack-server start & npx wait-on@7.2.0 http://localhost:8101 && pnpm -C apps/e2e test:ci
57+
58+
59+
- name: Start stack-server in background
60+
run: pnpm -C packages/stack-server start &
61+
- name: Wait for stack-server to start
62+
run: npx wait-on@7.2.0 http://localhost:8101
63+
64+
- name: Run tests
65+
run: pnpm -C apps/e2e test:ci
66+
env:
67+
SERVER_BASE_URL: http://localhost:8101
68+
INTERNAL_PROJECT_ID: internal
69+
INTERNAL_PROJECT_CLIENT_KEY: internal-project-client-api-key

apps/e2e/.env

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
PROJECT_CLIENT_ID=internal
2-
PROJECT_CLIENT_KEY=client_key
3-
SERVER_BASE_URL=http://localhost:8101
1+
INTERNAL_PROJECT_ID=
2+
INTERNAL_PROJECT_CLIENT_KEY=
3+
SERVER_BASE_URL=http://localhost:8101

apps/e2e/tests/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ function getEnvVar(name: string): string {
77
}
88

99
export const BASE_URL = getEnvVar("SERVER_BASE_URL")
10-
export const PROJECT_ID = getEnvVar("PROJECT_CLIENT_ID")
11-
export const PROJECT_CLIENT_KEY = getEnvVar("PROJECT_CLIENT_KEY")
10+
export const INTERNAL_PROJECT_ID = getEnvVar("INTERNAL_PROJECT_ID")
11+
export const INTERNAL_PROJECT_CLIENT_KEY = getEnvVar("INTERNAL_PROJECT_CLIENT_KEY")

apps/e2e/tests/basic.test.ts renamed to apps/e2e/tests/stack-server/internal-project.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { describe, expect, test } from "vitest";
22
import request from "supertest";
3-
import { BASE_URL, PROJECT_CLIENT_KEY, PROJECT_ID } from "./helpers";
3+
import { BASE_URL, INTERNAL_PROJECT_CLIENT_KEY, INTERNAL_PROJECT_ID } from "../helpers";
44

55
const AUTH_HEADER = {
6-
"x-stack-project-id": PROJECT_ID,
7-
"x-stack-publishable-client-key": PROJECT_CLIENT_KEY,
6+
"x-stack-project-id": INTERNAL_PROJECT_ID,
7+
"x-stack-publishable-client-key": INTERNAL_PROJECT_CLIENT_KEY,
88
};
99

1010
const JSON_HEADER = {
@@ -36,7 +36,7 @@ async function signInWithEmailPassword(email: string, password: string) {
3636
return { email, password, response };
3737
}
3838

39-
describe("Basic", () => {
39+
describe("Various internal project tests", () => {
4040
test("Main Page", async () => {
4141
const response = await request(BASE_URL).get("/");
4242
expect(response.status).toBe(307);
@@ -71,4 +71,4 @@ describe("Basic", () => {
7171
expect(response2.status).toBe(200);
7272
expect(response2.body.primaryEmail).toBe(email)
7373
});
74-
});
74+
});

dependencies.compose.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
services:
2+
db:
3+
image: postgres:latest
4+
environment:
5+
POSTGRES_USER: postgres
6+
POSTGRES_PASSWORD: password
7+
POSTGRES_DB: stackframe
8+
ports:
9+
- 5432:5432
10+
volumes:
11+
- postgres-data:/var/lib/postgresql/data
12+
inbucket:
13+
image: inbucket/inbucket:latest
14+
ports:
15+
- 2500:2500
16+
- 9000:9000
17+
- 1100:1100
18+
volumes:
19+
- inbucket-data:/data
20+
21+
volumes:
22+
postgres-data:
23+
inbucket-data:
24+

packages/stack-server/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"todo-sh-error-blocker": "( echo && echo ========================================= && echo There are TODO\\ ASAPs in your code, please && echo review them with '`npm run todo`'. && echo && echo Press ENTER or wait 10s to continue. && echo ========================================= && echo && bash -c 'read -t 10'; exit 1 ) 1>&2"
2626
},
2727
"prisma": {
28-
"seed": "npm run with-env -- ts-node prisma/seed.ts"
28+
"seed": "npm run with-env -- tsx prisma/seed.ts"
2929
},
3030
"dependencies": {
3131
"@emotion/react": "^11.11.3",
@@ -77,6 +77,6 @@
7777
"@types/react": "^18.2.66",
7878
"@types/react-dom": "^18",
7979
"prisma": "^5.9.1",
80-
"ts-node": "^10.9.2"
80+
"tsx": "^4.7.2"
8181
}
8282
}

packages/stack-server/prisma/seed.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { PrismaClient } = require('@prisma/client'); // must use require due to ts-node shenanigans
1+
import { PrismaClient } from '@prisma/client';
22
const prisma = new PrismaClient();
33

44

@@ -37,11 +37,11 @@ async function seed() {
3737
create: {
3838
allowLocalhost: true,
3939
oauthProviderConfigs: {
40-
create: ['github', 'facebook', 'google', 'microsoft'].map((id) => ({
40+
create: (['github', 'facebook', 'google', 'microsoft'] as const).map((id) => ({
4141
id,
4242
proxiedOAuthConfig: {
4343
create: {
44-
type: id.toUpperCase(),
44+
type: id.toUpperCase() as any,
4545
}
4646
},
4747
projectUserOAuthAccounts: {

packages/stack-server/sentry.client.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Sentry.init({
1111
tracesSampleRate: 1,
1212

1313
// Setting this option to true will print useful information to the console while you're setting up Sentry.
14-
debug: process.env.NODE_ENV === "development",
14+
debug: false,
1515

16-
enabled: process.env.NODE_ENV !== "development" && process.env.NODE_ENV !== "test",
16+
enabled: process.env.NODE_ENV !== "development" && !process.env.CI,
1717

1818
replaysOnErrorSampleRate: 1.0,
1919

packages/stack-server/sentry.edge.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Sentry.init({
1212
tracesSampleRate: 1,
1313

1414
// Setting this option to true will print useful information to the console while you're setting up Sentry.
15-
debug: process.env.NODE_ENV === "development",
15+
debug: false,
1616

17-
enabled: process.env.NODE_ENV !== "development" && process.env.NODE_ENV !== "test",
17+
enabled: process.env.NODE_ENV !== "development" && !process.env.CI,
1818
});

packages/stack-server/sentry.server.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Sentry.init({
1111
tracesSampleRate: 1,
1212

1313
// Setting this option to true will print useful information to the console while you're setting up Sentry.
14-
debug: process.env.NODE_ENV === "development",
14+
debug: false,
1515

16-
enabled: process.env.NODE_ENV !== "development" && process.env.NODE_ENV !== "test",
16+
enabled: process.env.NODE_ENV !== "development" && !process.env.CI,
1717
});

0 commit comments

Comments
 (0)