Skip to content

Commit bdbb45f

Browse files
authored
Merge pull request #121 from AtoroDesu/master
Add Docker Compose setup documentation for server deployment
2 parents b9a25dd + 1aef829 commit bdbb45f

File tree

2 files changed

+168
-0
lines changed

2 files changed

+168
-0
lines changed
File renamed without changes.
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Docker Compose
2+
3+
## Compose file
4+
5+
```yml
6+
services:
7+
spacebar-gateway:
8+
image: ghcr.io/{{ repositories.server }}-gateway:latest
9+
env_file: .env
10+
networks:
11+
- spacebar-network
12+
volumes:
13+
- ./data:/data
14+
ports:
15+
- "3001:3001"
16+
restart: unless-stopped
17+
18+
spacebar-api:
19+
image: ghcr.io/{{ repositories.server }}-api:latest
20+
env_file: .env
21+
networks:
22+
- spacebar-network
23+
volumes:
24+
- ./data:/data
25+
ports:
26+
- "3002:3001"
27+
restart: unless-stopped
28+
29+
spacebar-cdn:
30+
image: ghcr.io/{{ repositories.server }}-cdn:latest
31+
env_file: .env
32+
networks:
33+
- spacebar-network
34+
volumes:
35+
- ./data:/data
36+
ports:
37+
- "3003:3001"
38+
restart: unless-stopped
39+
40+
spacebar-db:
41+
image: postgres:18-alpine
42+
networks:
43+
- spacebar-network
44+
volumes:
45+
- spacebar-db:/var/lib/postgresql
46+
environment:
47+
- POSTGRES_PASSWORD=postgres
48+
restart: unless-stopped
49+
50+
networks:
51+
spacebar-network:
52+
53+
volumes:
54+
spacebar-db:
55+
```
56+
57+
## Volumes
58+
59+
| Mount | Type | Container(s) | Purpose |
60+
|---------------------|-------|--------------|------------------------------|
61+
| /data | Bind | spacebar-* | All Spacebar persistent data |
62+
| /var/lib/postgresql | Named | postgres | Persistent database |
63+
64+
## Setup
65+
66+
There's some prep to get things running the first time.
67+
68+
1. First steps:
69+
70+
Before anything, make sure you have a domain to use, and are familiar with creating subdomains and setting up
71+
a reverse proxy (like NGINX or Caddy) to point to the containers. Due to the very, _very_ many ways this can be
72+
done, we won't cover specifics here, but you'll need to point `your.domain` (placeholder) to the following
73+
subdomains and ports:
74+
75+
`spacebar.your.domain` -> `localhost:3001`
76+
`api.your.domain` -> `localhost:3002`
77+
`cdn.your.domain` -> `localhost:3003`
78+
79+
Create the .env file with the following variables:
80+
```shell
81+
DATABASE=postgres://postgres:postgres@spacebar-db/postgres
82+
CONFIG_PATH=config.json
83+
```
84+
85+
Run the compose setup for a minute to generate the other required files:
86+
```shell
87+
docker compose up
88+
```
89+
Wait until the logs stop moving and it looks like it's finished setting up, then `ctrl+c` to exit.
90+
91+
This will place a few files into the `./data` bind, including `jwt.key` and `jwt.key.pub`, along with a fresh
92+
`config.json` file.
93+
94+
2. Edit the `config.json` file with your server information
95+
This covers only what's different for a Docker Compose setup compared to a baremetal install.
96+
For the full list of config file options, check out the [configuration settings](../configuration/index.md)
97+
98+
| Key | Description | Example |
99+
|---------------------------|---------------------------------------------------|---------------------------------|
100+
| `gateway.endpointPrivate` | Internal (e.g. api-to-cdn) gateway communication | ws://spacebar-gateway:3001 |
101+
| `gateway.endpointPublic` | External (e.g. from a user) gateway communication | wss://spacebar.your.domain |
102+
| `cdn.endpointPrivate` | Internal CDN communication | http://spacebar-cdn:3001 |
103+
| `cdn.gatewayPublic` | External CDN communication | https://cdn.your.domain |
104+
| `api.endpointPrivate` | Internal API communication | http://spacebar-api:3001/api/v9 |
105+
| `api.endpointPublic` | External API communication | https://api.your.domain/api/v9 |
106+
107+
3. Bring up the containers
108+
Everything should be good to go. Run the following command to start the containers running in the background.
109+
```shell
110+
docker compose up -d
111+
```
112+
113+
## Fermi
114+
115+
4. If you want to host Fermi, the web client for Spacebar, as well
116+
Spacebar needs a client to connect to it for it to be used. Spacebar doesn't come with one by default, so you'll need
117+
one like Fermi. It can be added to this compose setup pretty easily.
118+
119+
### Build Fermi
120+
Fermi doesn't have a native Docker image just yet, so we have to build it ourselves.
121+
122+
Clone the git repository:
123+
```shell
124+
git clone https://github.com/MathMan05/Fermi.git
125+
```
126+
127+
Create a new `fermi` directory in the same place as the docker-compose.yml and create an empty `uptime.json` file:
128+
```shell
129+
mkdir fermi
130+
touch fermi/uptime.json
131+
```
132+
133+
Edit the `instances.json` file in the repository to include your new server. Read the details on how to do
134+
that [in the Fermi GitHub](https://github.com/MathMan05/Fermi/blob/main/InstanceInfo.md).
135+
We recommend copying this file somewhere safe, as updating the git repo will likely overwrite these changes.
136+
137+
Build the Docker image:
138+
```shell
139+
docker build -t fermi:latest .
140+
```
141+
142+
### Compose file
143+
144+
Add the following service to the existing compose file:
145+
146+
```shell
147+
fermi:
148+
image: fermi:latest
149+
env_file: .env
150+
networks:
151+
- spacebar-network
152+
volumes:
153+
- ./fermi/uptime.json:/exec/uptime.json
154+
ports:
155+
- 8080:8080
156+
restart: unless-stopped
157+
```
158+
159+
### Reverse Proxy
160+
161+
Add another route to your reverse proxy pointing your domain or subdomain to the new Fermi port, `8080`.
162+
Most people use the `app.your.domain` subdomain for Fermi, but you can also use the plain domain itself if you won't
163+
be using it for something else.
164+
165+
### Finished
166+
167+
After restarting the compose, or starting it for the first time if you read ahead, you should be able to open up
168+
the Fermi app and connect to your Spacebar instance.

0 commit comments

Comments
 (0)