|
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: |
35 | 9 | ```sh
|
36 | 10 | cp .env.development .env
|
37 | 11 | ```
|
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: |
95 | 18 | ```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 |
101 | 20 | ```
|
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: |
142 | 61 | ```sh
|
143 | 62 | docker compose up -d
|
144 | 63 | ```
|
| 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. |
145 | 79 |
|
146 |
| -### Questions! |
| 80 | +--- |
147 | 81 |
|
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. |
149 | 88 |
|
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 | +--- |
155 | 90 |
|
| 91 | +## **Development** |
156 | 92 |
|
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 |
159 | 95 | ```
|
0 commit comments