Files
decomp.me/docs/DOCKER.md
Mark Street 77bc4e6672 Add Docker Production setup (#1580)
* Add Docker Production setup

* Fixup ci

* forgot to hit save..

* try again

* More trying

* tweaks

* 🐻 hide all the dumbness

* overriding INTERNAL_API_BASE is optional

* Add pgdump dir to allow pg_restore

* rework nginx configuration for prod

* Add proxy timeouts for sanity
2025-06-07 15:51:39 +01:00

122 lines
3.2 KiB
Markdown

# Docker
## Prerequisites:
### Docker
You will need [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/). Follow the instructions for your distro.
## Production
0. Create a `docker.prod.env` and set the necessary configuration options (see .env for inspiration).
```bash
nano docker.prod.env
```
1. Bring up postgres & nginx containers
```bash
docker compose -f docker-compose.prod.yaml up -d postgres nginx
```
2. Build and bring up backend
```bash
docker compose -f docker-compose.prod.yaml build backend
docker compose -f docker-compose.prod.yaml up -d backend
```
3. Build and bring up frontend (relies on backend for SSR)
```bash
# NOTE: this can be overridden if needed, i.e. --build-arg INTERNAL_API_BASE=https://decomp.me/api
docker compose -f docker-compose.prod.yaml build frontend
docker compose -f docker-compose.prod.yaml up -d frontend
```
### SSL Certificates Bootstrap
In order to bring up nginx we need to have SSL certificates. In order to do that we need to get nginx to run only on port 80, then run certbot to fetch the certs.
1. Modify the `nginx/production.conf` to comment out the *whole* `server { listen 443 ssl http2; ... }` block.
2. Bring up nginx
```
docker compose -f docker-compose.prod.yaml up -d nginx
```
3. Run certbot:
```bash
docker compose run --rm certbot certonly \
--webroot -w /var/www/certbot \
-d decomp.me -d www.decomp.me \
--email you@your-email.com \
--agree-tos \
--no-eff-email
```
4. Uncomment the 443 block and then send a reload trigger to nginx
```
docker compose exec nginx nginx -t # sanity check configuration OK
docker compose exec nginx nginx -s reload
```
## Development
There is a `docker-compose.yaml` file to help you spin up a dev instance quickly.
**Run in foreground:**
```sh
docker compose up --build
```
The processes will run in the foreground until you CTRL+C to trigger a shutdown.
Navigate to [http://localhost:80](http://localhost:80) in your browser.
**Run daemonised:**
```sh
docker compose up -d && docker compose logs -f
```
You can CTRL+C to stop tailing logs. If you want to stop the processes then running `docker compose down` will shut everything down.
**Note:** The first time you bring up the containers can take a minute or so - Docker has to pull/build images, grab Node dependencies, apply database migrations etc. Subsequent runs will be significantly faster to spin up.
## Configuration
By default, the Docker `backend` container is configured with the Switch platform disabled (due to the size of the Clang compilers).
Platforms can be enabled by changing the `ENABLE_<PLATFORM>_SUPPORT` variables to `YES` in the `docker-compose.yaml` and re-running the `docker compose up` command.
E.g. to enable `SWITCH` platform:
```yaml
backend:
build:
context: backend
environment:
- ENABLE_SWITCH_SUPPORT=YES
```
## Connecting from a different host
If you wish to run decomp.me on one machine and connect from a *different* one (e.g. to test the site on your phone) please edit `./backend/docker.dev.env` to add your `hostname` to the `ALLOWED_HOSTS` environment variable.
E.g. if your hostname is `mylaptop`:
```sh
ALLOWED_HOSTS="backend,localhost,127.0.0.1,mylaptop"
```