Skip to content

Commit b491e54

Browse files
authored
Merge pull request #116 from limdingwen/docker
Add Docker support
2 parents 360ef90 + 8fbc69e commit b491e54

9 files changed

Lines changed: 134 additions & 2 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,7 @@ dist
132132
.yarn/unplugged
133133
.yarn/build-state.yml
134134
.yarn/install-state.gz
135-
.pnp.*
135+
.pnp.*
136+
137+
# Docker Compose
138+
docker-compose.override.yml

README-DOCKER.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## Running with Docker
2+
3+
You can also run **mikupad** using Docker. This automatically compiles the HTML and runs the custom NodeJS server, which serves the HTML, among other functions.
4+
5+
First, copy `server/.env.example` to `server/.env`. Then, **change your username and password**; anyone who has access to your hosted **mikupad** can store and load sessions, and proxy network requests through your server!
6+
7+
To run the server:
8+
9+
```shell
10+
docker compose -f server/docker-compose.yml up --build -d
11+
```
12+
13+
Then visit http://localhost:3000/.
14+
15+
Note that by default, the server will automatically start when Docker starts (which likely also starts on login). To stop the server, and at the same time also stop it from automatically starting up:
16+
17+
```shell
18+
docker compose -f server/docker-compose.yml down
19+
```
20+
21+
### Adding HTTPS support
22+
23+
You can also add HTTPS support, for example, if you wish to use **mikupad** remotely without revealing your generations or password to the entire world.
24+
25+
First, copy and rename `server/docker-compose.override.example.yml` to `server/docker-compose.override.yml`. Then, uncomment `services:`, as well as the `ADD HTTPS SUPPORT` section. You may also wish to remove unencrypted HTTP support by uncommenting the `REMOVE HTTP SUPPORT` section.
26+
27+
You will also need to provide a SSL certificate. You can do this in any way you wish, such as obtaining one from a [certificate authority](https://letsencrypt.org/) or creating a self-signed one yourself. Regardless, place the public certificate and the private key files in the `https` folder like so:
28+
29+
```shell
30+
$ ls server/https
31+
nginx.conf private.key public.crt
32+
```
33+
34+
If you have already started the server, run this command to start up the HTTPS server as well:
35+
36+
```shell
37+
docker compose -f server/docker-compose.yml up -d
38+
```
39+
40+
Then visit https://localhost:3443/.
41+
42+
### Using AI servers running on localhost when running mikupad in Docker
43+
44+
By default, **mikupad** running in server mode will proxy requests to any endpoints. For example, if you are running Ollama (which is OpenAI compatible), you can set the endpoint to `http://localhost:11434` and it'll work.
45+
46+
However, in Docker, you need to replace `localhost` with `host.docker.internal`. For example, the correct endpoint to use for Ollama is `http://host.docker.internal:11434`.
47+
48+
If you are on Linux, you'd need to copy and rename `server/docker-compose.override.example.yml` to `server/docker-compose.override.yml`. Then, uncomment `services:`, as well as the `ADD LOCALHOST AI SERVER SUPPORT FOR LINUX USERS` section.

server/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
MIKUPAD_LOGIN="anon"
2+
MIKUPAD_PASSWORD="SET_YOUR_PASSWORD_HERE"
3+
MIKUPAD_STORAGE_PATH="/storage/web-session-storage.db"

server/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM node:20.19.3
2+
3+
COPY server /app/server
4+
COPY project /app/project
5+
COPY mikupad.html /app/mikupad.html
6+
COPY compile.sh /app/compile.sh
7+
8+
# Compile HTML
9+
WORKDIR /app
10+
RUN /bin/bash compile.sh
11+
12+
# Server expects mikupad.html
13+
RUN mv /app/mikupad_compiled.html /app/mikupad.html
14+
15+
# Compile server
16+
WORKDIR /app/server
17+
RUN npm install --no-audit
18+
ENTRYPOINT [ "node", "server.js" ]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# HOW TO USE THIS FILE
2+
#
3+
# 1. Copy into `docker-compose.override.yml`
4+
# 2. Uncomment the parts you wish to include
5+
#
6+
# UNCOMMENT THIS FIRST:
7+
8+
# services:
9+
10+
# ADD HTTPS SUPPORT:
11+
12+
# https:
13+
# image: nginx:1.29
14+
# ports:
15+
# - 3443:3443
16+
# volumes:
17+
# - ./https/nginx.conf:/etc/nginx/conf.d/default.conf
18+
# - ./https/public.crt:/public.crt
19+
# - ./https/private.key:/private.key
20+
21+
# REMOVE HTTP SUPPORT:
22+
23+
# mikupad:
24+
# ports: !reset []
25+
26+
# ADD LOCALHOST AI SERVER SUPPORT FOR LINUX USERS:
27+
# (DELETE `mikupad:` IF ALREADY DEFINED ABOVE)
28+
29+
# mikupad:
30+
# extra_hosts:
31+
# - host.docker.internal:host-gateway

server/docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
mikupad:
3+
build:
4+
context: ..
5+
dockerfile: server/Dockerfile
6+
ports:
7+
- 3000:3000
8+
env_file:
9+
- .env
10+
restart: unless-stopped
11+
volumes:
12+
- storage:/storage
13+
14+
volumes:
15+
storage:

server/https/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
private.key
2+
public.crt

server/https/nginx.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
server {
2+
listen 3443 ssl;
3+
4+
ssl_certificate /public.crt;
5+
ssl_certificate_key /private.key;
6+
7+
location / {
8+
proxy_pass http://mikupad:3000;
9+
proxy_buffering off; # Required to keep token streaming smooth
10+
}
11+
}

server/server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const host = args.host || process.env.MIKUPAD_HOST || '0.0.0.0';
1818
const noOpen = (args.open !== undefined && !args.open) || process.env.MIKUPAD_NO_OPEN;
1919
const login = args.login || process.env.MIKUPAD_LOGIN || 'anon';
2020
const password = args.password || process.env.MIKUPAD_PASSWORD || undefined;
21+
const storagePath = args.storagePath || process.env.MIKUPAD_STORAGE_PATH || './web-session-storage.db';
2122

2223
// Headers that shouldn't be forwarded in the proxy endpoint.
2324
const headersToRemove = [
@@ -149,7 +150,7 @@ const runMigrationToV3 = (db) => {
149150

150151

151152
// Open a database connection
152-
const db = new sqlite3.Database('./web-session-storage.db', (err) => {
153+
const db = new sqlite3.Database(storagePath, (err) => {
153154
if (err) {
154155
console.error(err.message);
155156
process.exit(1);

0 commit comments

Comments
 (0)