|
1 |
| -### Docker - Build at Building Server |
2 |
| - |
| 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 && unzip -j repo.zip "stack-dev/docker/stack-auth-services/*" -d stack-auth-services && rm repo.zip |
| 18 | + ``` |
| 19 | + |
| 20 | +### Setup |
| 21 | + |
| 22 | +Go to folder `docker/stack-auth-setup` |
| 23 | + |
| 24 | +0. **Pre-install** |
| 25 | + ```sh |
| 26 | + cd docker/stack-auth-setup |
| 27 | + pnpm i --ignore-workspace |
| 28 | + ``` |
3 | 29 | 1. **Update Environment Variables**
|
4 | 30 | - Navigate to `docker/setup` and update the `.env` file:
|
5 | 31 | ```sh
|
6 |
| - cd docker/setup |
7 | 32 | cp .env.development .env
|
8 |
| - cd ../.. |
9 | 33 | ```
|
10 |
| - |
11 | 34 | 2. **Create Tokens**
|
12 |
| - - Install dependencies and run the key generation script: |
| 35 | + - Run the key generation script: |
13 | 36 | ```sh
|
14 |
| - cd docker/setup |
15 |
| - pnpm i --ignore-workspace |
16 | 37 | pnpm tsx scripts/generateKeys.ts
|
17 |
| - cd ../.. |
18 | 38 | ```
|
19 |
| - |
| 39 | + - Copy them to `.env` under the `generated by generateKeys.ts` section. |
20 | 40 | 3. **Configure Hosts**
|
21 |
| - - Set the following environment variables: |
22 |
| - ```env |
23 |
| - NEXT_PUBLIC_STACK_URL=https://api.stack-auth.internal |
24 |
| - NEXT_PUBLIC_STACK_SVIX_SERVER_URL=https://svix-api.stack-auth.internal |
25 |
| - NEXT_PUBLIC_STACK_HEAD_TAGS=[{ "tagName": "script", "attributes": {}, "innerHTML": "// insert head tags here" }] |
26 |
| - ``` |
27 |
| - |
28 |
| -4. **Sentry Integration** |
29 | 41 | - Set up Sentry variables according to [Sentry's documentation](https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup):
|
30 | 42 | ```env
|
31 | 43 | NEXT_PUBLIC_SENTRY_DSN=
|
32 | 44 | NEXT_PUBLIC_SENTRY_ORG=
|
33 | 45 | NEXT_PUBLIC_SENTRY_PROJECT=
|
34 | 46 | SENTRY_AUTH_TOKEN=
|
35 | 47 | ```
|
| 48 | + - The following environment variables are not necessary to update: |
| 49 | + ```env |
| 50 | + NEXT_PUBLIC_STACK_URL=https://api.stack-auth.internal |
| 51 | + NEXT_PUBLIC_STACK_SVIX_SERVER_URL=https://svix-api.stack-auth.internal |
| 52 | + NEXT_PUBLIC_STACK_HEAD_TAGS=[{ "tagName": "script", "attributes": {}, "innerHTML": "// insert head tags here" }] |
36 | 53 |
|
37 |
| -5. **Generate Builder Environment** |
| 54 | + # db connection |
| 55 | + STACK_DATABASE_CONNECTION_STRING=postgres://postgres:${POSTGRES_STACKFRAME_PASSWORD}@127.0.0.1:5432/stackframe |
| 56 | + STACK_DIRECT_DATABASE_CONNECTION_STRING=postgres://postgres:${POSTGRES_STACKFRAME_PASSWORD}@127.0.0.1:5432/stackframe |
| 57 | + ``` |
| 58 | + - Setup db connection (Optional if you use our docker server setup) |
| 59 | + - It will be used to deploy prisma data. |
| 60 | +4. **Generate Builder Environment file** |
38 | 61 | - Run the builder environment generation script:
|
39 | 62 | ```sh
|
40 |
| - cd docker/setup |
41 | 63 | pnpm dotenv -c -- tsx scripts/generateBuilderEnv.ts
|
42 |
| - cd ../.. |
43 |
| - ``` |
44 |
| -
|
45 |
| -6. **Build Docker Images** |
46 |
| - - Navigate to `docker/builder` and build: |
47 |
| - ```sh |
48 |
| - cd docker/builder |
49 |
| - docker compose build |
50 |
| - cd .. |
51 |
| - ``` |
52 |
| -
|
53 |
| ---- |
54 |
| -
|
55 |
| -### Services at Deployment Server |
56 |
| -
|
57 |
| -1. **Prepare Environment Files** |
58 |
| - - Copy the `.env.dashboard` configuration: |
59 |
| - ```sh |
60 |
| - cd docker/setup |
61 |
| - pnpm dotenv -c -- tsx scripts/generateDashboardEnv.ts |
62 |
| - cd ../.. |
63 | 64 | ```
|
| 65 | + - Copy this to the builder server. |
64 | 66 |
|
65 |
| -2. **Configure `.env` File** |
| 67 | +5. **Prepare Services Environment Files** |
66 | 68 | - Populate `.env` in `docker/services` with required values from `setup/.env`:
|
67 | 69 | - `POSTGRES_STACKFRAME_PASSWORD`
|
68 | 70 | - `POSTGRES_SVIX_PASSWORD`
|
69 | 71 | - `SVIX_JWT_SECRET`
|
70 |
| -
|
71 |
| -3. **Configure `.env.backend` File** |
72 |
| - - Include necessary secrets like `STACK_SERVER_SECRET` and `STACK_SVIX_API_KEY`. |
73 |
| - - Generate the `STACK_SVIX_API_KEY`: |
74 |
| - ```sh |
75 |
| - docker compose up svix-server -d |
76 |
| - docker exec -it <container_id> sh |
77 |
| - svix-server jwt generate |
78 |
| - ``` |
79 |
| -
|
80 |
| -4. **Configure Sentry Variables** |
81 |
| - - Copy Sentry-related variables into `.env.sentry` from `setup/.env`. |
82 |
| -
|
83 |
| -5. **SSL Certificates** |
84 |
| - - Place SSL files in the `certs` directory. |
85 |
| -
|
86 |
| -6. **Start Docker Services** |
87 |
| - - Start services in detached mode: |
| 72 | + - Copy the `.env.dashboard` configuration: |
88 | 73 | ```sh
|
89 |
| - cd docker/services |
90 |
| - docker compose up -d |
| 74 | + pnpm dotenv -c -- tsx scripts/generateDashboardEnv.ts |
91 | 75 | ```
|
92 |
| -
|
93 |
| -7. **Initialize Data** |
| 76 | + - Uncomment `DEPTH_ZERO_SELF_SIGNED_CERT` if self-trust SSL is needed. |
| 77 | + - Copy the `.env.backend` configuration: |
| 78 | + - Include necessary secrets like `STACK_SERVER_SECRET` and `STACK_SVIX_API_KEY`. |
| 79 | + - Generate the `STACK_SVIX_API_KEY`: |
| 80 | + ```sh |
| 81 | + docker compose up svix-server -d |
| 82 | + docker exec -it <container_id> sh |
| 83 | + svix-server jwt generate |
| 84 | + ``` |
| 85 | + - **Configure Sentry Variables** |
| 86 | + Copy Sentry-related variables into `.env.sentry` from `setup/.env`. |
| 87 | +6. **Initialize Data** |
| 88 | + - After starting services: |
| 89 | + - Update db IP for your services server. |
94 | 90 | - If deploying and building on the same server, run initialization:
|
95 | 91 | ```sh
|
96 |
| - cd docker/setup |
| 92 | + cd docker/stack-auth-setup |
97 | 93 | cp -r ../../apps/backend/prisma/ .
|
98 | 94 | pnpm prisma generate
|
99 | 95 | pnpm prisma migrate deploy
|
100 | 96 | pnpm dotenv -c -- tsx scripts/seed.ts
|
101 | 97 | ```
|
102 |
| - - Use `pnpm prisma studio` to update ProjectUser, adding `"internal"` to `managedProjectIds`. |
| 98 | + - Use `pnpm prisma studio` to update `ProjectUser`, adding `"internal"` to `managedProjectIds`. |
| 99 | +
|
| 100 | +7. **Network** |
| 101 | + - Add `https://stack-auth.internal`, `svix-api.stack-auth.internal`, `api.stack-auth.internal` to your DNS hosts. |
| 102 | + - Expose ports: |
| 103 | + - 443 |
103 | 104 |
|
104 | 105 | 8. **User Signup**
|
105 | 106 | - Access `https://stack-auth.internal` and complete the signup process.
|
|
109 | 110 | - In the Admin project:
|
110 | 111 | - Disable localhost.
|
111 | 112 | - Add `https://stack-auth.internal` to domains.
|
112 |
| - - Set user to "verified" for otp. |
| 113 | + - Set user to "verified" for OTP. |
| 114 | +
|
| 115 | +### Build |
| 116 | +Go to the builder server. |
| 117 | +
|
| 118 | +**Build Docker Images** |
| 119 | +- Navigate to `docker/builder` and build: |
| 120 | + ```sh |
| 121 | + docker compose build |
| 122 | + ``` |
| 123 | +
|
| 124 | +### Start Services |
| 125 | +
|
| 126 | +0. **SSL Certificates** |
| 127 | + - Place SSL files in the `certs` directory. |
| 128 | + ```sh |
| 129 | + openssl genrsa -out stack-auth.key 2048 |
| 130 | + openssl req -new -key stack-auth.key -out stack-auth.csr |
| 131 | + openssl x509 -req -days 365 -in stack-auth.csr -signkey stack-auth.key -out stack-auth.crt |
| 132 | + ``` |
| 133 | +
|
| 134 | +1. **Start Docker Services** |
| 135 | + - Pull `stack-auth/dashboard` and `stack-auth/backend`. |
| 136 | + - Start services in detached mode: |
| 137 | + ```sh |
| 138 | + docker compose up -d |
| 139 | + ``` |
| 140 | +
|
| 141 | +### Questions! |
| 142 | +
|
| 143 | +1. Self-host and self-signed cert |
| 144 | +
|
| 145 | +- Dashboard `DEPTH_ZERO_SELF_SIGNED_CERT` |
| 146 | +- Browser visit: |
| 147 | + - `https://stack-auth.internal` |
| 148 | + - `svix-api.stack-auth.internal` |
| 149 | + - `api.stack-auth.internal` |
0 commit comments