Skip to content

Commit d2f5504

Browse files
update README.md
1 parent 8338921 commit d2f5504

File tree

3 files changed

+168
-149
lines changed

3 files changed

+168
-149
lines changed

docker/.env.development

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
############
2+
# Secret
3+
############
4+
5+
# stack
6+
STACK_SERVER_SECRET=u8WXA6g18tS2pGy8LKECYel5wlZAqgIo9Gxq67W1PF4
7+
NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=this-publishable-client-key-is-for-local-development-only
8+
STACK_SECRET_SERVER_KEY=this-secret-server-key-is-for-local-development-only
9+
STACK_SUPER_SECRET_ADMIN_KEY=this-secret-admin-key-is-for-local-development-only
10+
11+
# db
12+
POSTGRES_STACKFRAME_PASSWORD=this-db-password-is-for-local-development-only
13+
14+
# svix
15+
POSTGRES_SVIX_PASSWORD=this-svix-password-is-for-local-development-only
16+
SVIX_JWT_SECRET=x6HeHo0IZGmTigbwq4AiCWb--wtTb9PxLiE8Kuj8RxU
17+
STACK_SVIX_API_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2NTUxNDA2MzksImV4cCI6MTk3MDUwMDYzOSwibmJmIjoxNjU1MTQwNjM5LCJpc3MiOiJzdml4LXNlcnZlciIsInN1YiI6Im9yZ18yM3JiOFlkR3FNVDBxSXpwZ0d3ZFhmSGlyTXUifQ.VCP8uc2wqIQfMZfalNykRd1xNVyKKKEZFGnatwvwO7M
18+
19+
############
20+
# Config
21+
############
22+
23+
POSTGRES_DELAY_MS=0
24+
# This is needed for local development to allow self-signed certificates
25+
NODE_TLS_REJECT_UNAUTHORIZED=0
26+
27+
############
28+
# Stack Dashboard
29+
############
30+
31+
NEXT_PUBLIC_STACK_URL=https://api.stack-auth.internal
32+
NEXT_PUBLIC_STACK_PROJECT_ID=internal
33+
NEXT_PUBLIC_STACK_SVIX_SERVER_URL=https://svix-api.stack-auth.internal
34+
STACK_ACCESS_TOKEN_EXPIRATION_TIME=
35+
NEXT_PUBLIC_STACK_HEAD_TAGS=[{ "tagName": "script", "attributes": {}, "innerHTML": "// insert head tags here" }]
36+
37+
############
38+
# Sentry
39+
############
40+
41+
NEXT_PUBLIC_SENTRY_DSN=
42+
NEXT_PUBLIC_SENTRY_ORG=
43+
NEXT_PUBLIC_SENTRY_PROJECT=
44+
SENTRY_AUTH_TOKEN=
45+
46+
############
47+
# Auth
48+
############
49+
50+
# OAuth mock provider settings
51+
STACK_OAUTH_MOCK_URL=
52+
53+
# OAuth shared keys
54+
# Can be set to MOCK to use mock OAuth providers
55+
STACK_GITHUB_CLIENT_ID=
56+
STACK_GITHUB_CLIENT_SECRET=
57+
STACK_GOOGLE_CLIENT_ID=
58+
STACK_GOOGLE_CLIENT_SECRET=
59+
STACK_MICROSOFT_CLIENT_ID=
60+
STACK_MICROSOFT_CLIENT_SECRET=
61+
STACK_SPOTIFY_CLIENT_ID=
62+
STACK_SPOTIFY_CLIENT_SECRET=
63+
64+
# Email
65+
# For local development, you can spin up a local SMTP server like inbucket
66+
STACK_EMAIL_HOST=
67+
STACK_EMAIL_PORT=
68+
STACK_EMAIL_SECURE=
69+
STACK_EMAIL_USERNAME=
70+
STACK_EMAIL_PASSWORD=
71+
STACK_EMAIL_SENDER=
72+
73+
# Misc, optional
74+
STACK_ACCESS_TOKEN_EXPIRATION_TIME=
75+
STACK_SETUP_ADMIN_GITHUB_ID=
76+
OTEL_EXPORTER_OTLP_ENDPOINT=
77+
78+
############
79+
# Database - You can change these to any PostgreSQL database that has logical replication enabled.
80+
############
81+
82+
STACK_DATABASE_CONNECTION_STRING=postgres://postgres:${POSTGRES_STACKFRAME_PASSWORD}@127.0.0.1:8111/stackframe
83+
STACK_DIRECT_DATABASE_CONNECTION_STRING=postgres://postgres:${POSTGRES_STACKFRAME_PASSWORD}@127.0.0.1:8111/stackframe

docker/README.md

Lines changed: 81 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,95 @@
1-
You need three folders:
2-
3-
0. server for setup - generate your token and seed the data
4-
- `docker/stack-auth-setup`
5-
```sh
6-
git clone https://github.com/ShaunDyson-leetcode/stack.git
7-
```
8-
9-
1. server for builder - build your own token
10-
- `docker/stack-auth-builder`
11-
```sh
12-
git clone https://github.com/ShaunDyson-leetcode/stack.git
13-
```
14-
2. server for services - run your docker
15-
- `docker/stack-auth-services`
16-
```sh
17-
wget https://github.com/ShaunDyson-leetcode/stack/archive/refs/heads/dev.zip -O repo.zip
18-
unzip repo.zip "stack-dev/docker/stack-auth-services/*" -d stack-auth-services
19-
mv stack-auth-services/stack-dev/docker/stack-auth-services/* stack-auth-services
20-
rm -rvf stack-auth-services/stack-dev
21-
rm repo.zip
22-
```
23-
24-
### Setup
25-
26-
Go to folder `docker/stack-auth-setup`
27-
28-
0. **Pre-install**
29-
```sh
30-
cd docker/stack-auth-setup
31-
pnpm i --ignore-workspace
32-
```
33-
1. **Update Environment Variables**
34-
- Navigate to `docker/setup` and update the `.env` file:
1+
### Stack Auth Setup Guide
2+
3+
This guide provides step-by-step instructions to set up the `stack-auth` environment using Docker. Follow each step carefully to ensure proper configuration and smooth execution.
4+
5+
---
6+
7+
### 1. **Create `.env` File**
8+
- Copy the development environment file:
359
```sh
3610
cp .env.development .env
3711
```
38-
2. **Create Tokens**
39-
- Run the key generation script:
40-
```sh
41-
pnpm tsx scripts/generateKeys.ts
42-
```
43-
- Copy them to `.env` under the `generated by generateKeys.ts` section.
44-
3. **Configure Hosts**
45-
- Set up Sentry variables according to [Sentry's documentation](https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup):
46-
```env
47-
NEXT_PUBLIC_SENTRY_DSN=
48-
NEXT_PUBLIC_SENTRY_ORG=
49-
NEXT_PUBLIC_SENTRY_PROJECT=
50-
SENTRY_AUTH_TOKEN=
51-
```
52-
- The following environment variables are not necessary to update:
53-
```env
54-
NEXT_PUBLIC_STACK_URL=https://api.stack-auth.internal
55-
NEXT_PUBLIC_STACK_SVIX_SERVER_URL=https://svix-api.stack-auth.internal
56-
NEXT_PUBLIC_STACK_HEAD_TAGS=[{ "tagName": "script", "attributes": {}, "innerHTML": "// insert head tags here" }]
57-
58-
# db connection
59-
STACK_DATABASE_CONNECTION_STRING=postgres://postgres:${POSTGRES_STACKFRAME_PASSWORD}@127.0.0.1:5432/stackframe
60-
STACK_DIRECT_DATABASE_CONNECTION_STRING=postgres://postgres:${POSTGRES_STACKFRAME_PASSWORD}@127.0.0.1:5432/stackframe
61-
```
62-
- Setup db connection (Optional if you use our docker server setup)
63-
- It will be used to deploy prisma data.
64-
4. **Generate Builder Environment file**
65-
- Run the builder environment generation script:
66-
```sh
67-
pnpm dotenv -c -- tsx scripts/generateBuilderEnv.ts
68-
```
69-
- Copy this to the builder server.
70-
71-
5. **Prepare Services Environment Files**
72-
- Populate `.env` in `docker/services` with required values from `setup/.env`:
73-
- `POSTGRES_STACKFRAME_PASSWORD`
74-
- `POSTGRES_SVIX_PASSWORD`
75-
- `SVIX_JWT_SECRET`
76-
- Copy the `.env.dashboard` configuration:
77-
```sh
78-
pnpm dotenv -c -- tsx scripts/generateDashboardEnv.ts
79-
```
80-
- Uncomment `DEPTH_ZERO_SELF_SIGNED_CERT` if self-trust SSL is needed.
81-
- Copy the `.env.backend` configuration:
82-
- Include necessary secrets like `STACK_SERVER_SECRET` and `STACK_SVIX_API_KEY`.
83-
- Generate the `STACK_SVIX_API_KEY`:
84-
```sh
85-
docker compose up svix-server -d
86-
docker exec -it <container_id> sh
87-
svix-server jwt generate
88-
```
89-
- **Configure Sentry Variables**
90-
Copy Sentry-related variables into `.env.sentry` from `setup/.env`.
91-
6. **Initialize Data**
92-
- After starting services:
93-
- Update db IP for your services server.
94-
- If deploying and building on the same server, run initialization:
12+
- **Note**: After copying, open the new `.env` file and adjust environment variables as needed.
13+
14+
---
15+
16+
### 2. **Build Docker Images**
17+
- Build Docker images. If you change any `NEXT_JS_*` environment variables in `.env`, rebuild the images for those changes to take effect:
9518
```sh
96-
cd docker/stack-auth-setup
97-
cp -r ../../apps/backend/prisma/ .
98-
pnpm prisma generate
99-
pnpm prisma migrate deploy
100-
pnpm dotenv -c -- tsx scripts/seed.ts
19+
docker compose -f docker-compose.builder.yaml build
10120
```
102-
- Use `pnpm prisma studio` to update `ProjectUser`, adding `"internal"` to `managedProjectIds`.
103-
104-
7. **Network**
105-
- Add `https://stack-auth.internal`, `svix-api.stack-auth.internal`, `api.stack-auth.internal` to your DNS hosts.
106-
- Expose ports:
107-
- 443
108-
- 8111 (Optional: database)
109-
110-
8. **User Signup**
111-
- Access `https://stack-auth.internal` and complete the signup process.
112-
- Ignore whitelist warnings on first-time signup and proceed to sign in.
113-
114-
9. **Set Domains and Handlers**
115-
- In the Admin project:
116-
- Disable localhost.
117-
- Add `https://stack-auth.internal` to domains.
118-
- Set user to "verified" for OTP.
119-
120-
### Build
121-
Go to the builder server.
122-
123-
**Build Docker Images**
124-
- Navigate to `docker/builder` and build:
125-
```sh
126-
docker compose build
127-
```
128-
129-
### Start Services
130-
131-
0. **SSL Certificates**
132-
- Place SSL files in the `certs` directory.
133-
```sh
134-
openssl genrsa -out stack-auth.key 2048
135-
openssl req -new -key stack-auth.key -out stack-auth.csr
136-
openssl x509 -req -days 365 -in stack-auth.csr -signkey stack-auth.key -out stack-auth.crt
137-
```
138-
139-
1. **Start Docker Services**
140-
- Pull `stack-auth/dashboard` and `stack-auth/backend`.
141-
- Start services in detached mode:
21+
22+
---
23+
24+
### 3. **Setup Service**
25+
- **Download Config Files**:
26+
- Fetch the latest config files and organize them into the required directories:
27+
```sh
28+
wget https://github.com/ShaunDyson-leetcode/stack/archive/refs/heads/dev.zip -O repo.zip
29+
unzip repo.zip "stack-dev/docker/*" -d stack-auth
30+
mv stack-auth/stack-dev/docker stack-auth/
31+
rm -rf stack-auth/stack-dev repo.zip
32+
```
33+
34+
---
35+
36+
### 4. **Network and DNS Setup**
37+
- **DNS Entries**:
38+
- Add the following entries to your system’s `/etc/hosts` file (or DNS management system):
39+
- `stack-auth.internal`
40+
- `svix-api.stack-auth.internal`
41+
- `api.stack-auth.internal`
42+
- **Port Exposure**:
43+
- Ensure the following ports are accessible:
44+
- **443**: Main service
45+
- **8111**: Optional (database)
46+
- **Firewall**: If you are on a network with firewall restrictions, ensure these ports are open.
47+
- **Self-Signed SSL Certificates**:
48+
- Place SSL files in the `volumes/nginx/certs` directory.
49+
- If you need to create self-signed certificates, use:
50+
```sh
51+
openssl genrsa -out stack-auth.key 2048
52+
openssl req -new -key stack-auth.key -out stack-auth.csr
53+
openssl x509 -req -days 365 -in stack-auth.csr -signkey stack-auth.key -out stack-auth.crt
54+
```
55+
- **Note**: This is optional for development but recommended for production. Uncomment `DEPTH_ZERO_SELF_SIGNED_CERT` in `.env` if using self-signed certificates.
56+
57+
---
58+
59+
### 5. **Start Services**
60+
- Start Docker services in detached mode:
14261
```sh
14362
docker compose up -d
14463
```
64+
- **Verification**: Run `docker ps` to confirm that all services started successfully.
65+
- **Troubleshooting**: Common errors at this step may include port conflicts or permission issues. Check Docker logs if services fail to start.
66+
67+
- **Access Services**:
68+
- Open the following URLs in your browser:
69+
- `https://svix-api.stack-auth.internal`
70+
- `https://api.stack-auth.internal`
71+
- `https://stack-auth.internal`
72+
- **Browser Compatibility**: Certain browsers may show a warning for self-signed certificates; proceed past these warnings to access the sites.
73+
74+
---
75+
76+
### 6. **User Signup**
77+
- Access `https://stack-auth.internal` to complete the signup process.
78+
- **Note**: Ignore any whitelist warnings on your first login; these warnings will not affect your signup process.
14579

146-
### Questions!
80+
---
14781

148-
1. Self-host and self-signed cert
82+
### 7. **Set Domains and Handlers**
83+
- Access the Admin project (refer to the project documentation if unsure how to access this).
84+
- Update settings as follows:
85+
- **Disable**: `localhost` domain for security.
86+
- **Add**: `https://stack-auth.internal` to the allowed domains.
87+
- **Set User Verification**: Set the user to "verified" for OTP.
14988

150-
- Dashboard `DEPTH_ZERO_SELF_SIGNED_CERT`
151-
- Browser visit:
152-
- `https://stack-auth.internal`
153-
- `svix-api.stack-auth.internal`
154-
- `api.stack-auth.internal`
89+
---
15590

91+
## **Development**
15692

157-
``` sh
158-
pnpm prisma migrate diff --from-empty --to-schema-datamodel ../../apps/backend/prisma/schema.prisma --script > ../stack-auth-services/volumes/db/stack-auth-init.sql
93+
```sh
94+
pnpm prisma migrate diff --from-empty --to-schema-datamodel ../../apps/backend/prisma/schema.prisma --script > ../stack-auth-services/volumes/db/stack-auth-init.sql
15995
```

docker/docker-compose.builder.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ services:
33
stack-auth-dashboard:
44
image: stack-auth/dashboard
55
build:
6-
context: ../..
6+
context: ../
77
target: dashboard
8-
dockerfile: ./docker/stack-auth-builder/Dockerfile
8+
dockerfile: ./docker/Dockerfile
99
args: # Pass all necessary variables for build
1010
NEXT_PUBLIC_STACK_URL: ${NEXT_PUBLIC_STACK_URL}
1111
NEXT_PUBLIC_STACK_PROJECT_ID: ${NEXT_PUBLIC_STACK_PROJECT_ID}
@@ -20,9 +20,9 @@ services:
2020
stack-auth-backend:
2121
image: stack-auth/backend
2222
build:
23-
context: ../..
23+
context: ../
2424
target: backend
25-
dockerfile: ./docker/stack-auth-builder/Dockerfile
25+
dockerfile: ./docker/Dockerfile
2626
args: # Pass all necessary variables for build
2727
NEXT_PUBLIC_SENTRY_DSN: ${NEXT_PUBLIC_SENTRY_DSN}
2828
NEXT_PUBLIC_SENTRY_ORG: ${NEXT_PUBLIC_SENTRY_ORG}

0 commit comments

Comments
 (0)