You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: adminforth/documentation/docs/tutorial/04-deploy.md
+24-81Lines changed: 24 additions & 81 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,77 +5,15 @@ with `ts-node` command in any node environment.
5
5
6
6
It will start the server on configured HTTP port and you can use any proxy like Traefik/Nginx to expose it to the internet and add SSL Layer.
7
7
8
-
## Building SPA in Docker build time
8
+
## Dockerfile
9
9
10
-
In current index.ts file you might use call to `bundleNow` method which starts building internal SPA bundle when `index.ts` started
11
-
executing. SPA building generally takes from 10 seconds to minute depending on the external modules you will add into AdminForth and extended functionality you will create.
10
+
If you created your AdminForth application with `adminforth create-app` command you already have a `Dockerfile` in your project.
12
11
13
-
To fully exclude this bundle time we recommend doing bundling in build time.
12
+
You can use it to build your AdminForth application in Docker container.
14
13
15
-
Create file `bundleNow.ts` in the root directory of your project:
14
+
> ⚠️ Please note that `Dockerfile` has `npx adminforth bundle` command which pre-bundles your AdminForth SPA
15
+
> at build time. If you will remove it, your AdminForth application will still work, but will cause some downtime during app restart/redeploy because bundling will happen at runtime after you start the `index.ts` file. When `npx adminforth bundle` command is executed at build time, the call do `bundleNow()` inside of `index.ts` file will actually do nothing.
16
16
17
-
and put the following code:
18
-
19
-
```ts title='./bundleNow.ts'
20
-
import { admin } from'./index.js';
21
-
22
-
awaitadmin.bundleNow({ hotReload: false});
23
-
console.log('Bundling AdminForth done.');
24
-
```
25
-
26
-
Now completely Remove bundleNow call from `index.ts` file:
27
-
28
-
```ts title='./index.ts'
29
-
//diff-remove
30
-
// needed to compile SPA. Call it here or from a build script e.g. in Docker build time to reduce downtime
> `-v $(pwd)/db:/code/db` is needed only if you are using SQLite database.
36
+
100
37
Now open your browser and go to `http://localhost:3500` to see your AdminForth application running in Docker container.
101
38
102
39
## Adding SSL (https) to AdminForth
@@ -106,14 +43,7 @@ change 3500 port to 80 and Cloudflare will automatically add SSL layer and faste
106
43
107
44
However as a bonus here we will give you independent way to add free LetsEncrypt SSL layer to your AdminForth application.
108
45
109
-
First move all contents of your root folder (which contains index.ts and other files) to `app` folder:
110
-
111
-
```bash
112
-
mkdir app
113
-
mv {.,}* app
114
-
```
115
-
116
-
In root directory create file `compose.yml`:
46
+
In a folder which contains folder of your AdminForth application (e.g. `adminforth-app`) create a file `compose.yml`:
117
47
118
48
```yaml title='./compose.yml'
119
49
version: '3.8'
@@ -144,12 +74,10 @@ services:
144
74
- "traefik.http.routers.http-catchall.tls=false"
145
75
146
76
adminforth:
147
-
build: ./app
77
+
build: ./adminforth-app
148
78
environment:
149
79
- NODE_ENV=production
150
80
- ADMINFORTH_SECRET=!CHANGEME! # ☝️ replace with your secret
151
-
- DATABASE_FILE=/code/db/db.sqlite
152
-
- DATABASE_FILE_URL=file:/code/db/db.sqlite
153
81
labels:
154
82
- "traefik.enable=true"
155
83
- "traefik.http.routers.adminforth.tls=true"
@@ -241,3 +169,18 @@ server {
241
169
}
242
170
}
243
171
```
172
+
173
+
# Environment variables best practices
174
+
175
+
Use `.env` file for sensitive variables like `OPENAI_API_KEY` locally.
176
+
177
+
Use `.env.prod` and `.env.local` for non-sensitive variables which are different for production and local environemnts (like NODE_ENV, SOME_EXTERNAL_API_BASE, etc).
178
+
179
+
Sensitive variables like `OPENAI_API_KEY` in production should be passed directly to docker container or use secrets from your vault.
180
+
181
+
182
+
# If you are not using Docker
183
+
184
+
You can actually ship your AdminForth application without Docker as well.
185
+
186
+
Most important thing is remember in such case is to use `npx adminforth bundle` command after you installed node modules and before you do actual restart of your application to avoid downtimes.
0 commit comments