spaceshelter / orbitar

Experimental collective social/blogging platform with self-regulation.
MIT License
62 stars 24 forks source link

Split compose & caddy files #395

Open Lexy2 opened 2 months ago

Lexy2 commented 2 months ago

Problem statement

We've got some configuration drift by virtue of having almost identical configurations in different docker-compose files and different Caddy configurations.

Solution

This PR attempts to mitigate those issues by making hierarchical structure of the Docker & Caddy configuration files used.

Compose

Development

The main configuration file is now docker-compose.yml which is paired with docker-compose.override.yml. docker compose commands automatically find and select those two files, making the development experience easier. This is equivalent to running docker compose -f docker-compose.yml -f docker-compose.override.yml

TLS local development is facilitated by running docker compose -f docker-compose.yml -f docker-compose.dev.ssl.yml

Deployment

Main deployment requires plugging in 3 docker-compose files: docker compose -f docker-compose.yml -f docker-compose.deploy.yml -f docker-compose.deploy.ssl.yml (or nonssl.yml).

The reason why it has to be so complicated is because list variables in compose files can't be overridden, they are only complemented in override files, so you can't define everything just in one file and then add just one override file, alas.

I also renamed the file parts from local to deploy which better reflects their purpose.

Caddy

Configuration

There is now one main Caddyfile that serves it all.

Its configurability is managed by environment variables and imported snippet files.

Default files (off.tls.Caddyfile, dev.frontend.Caddyfile) can be copied as is. Override files need to have their dash replaced with a dot (to on.tls.Caddyfile and deploy.frontend.Caddyfile) to provide updated behaviour. They are also mutually exclusive with the default files; only one of each should be copied.

Subdomains

We don't use or support subdomains in our prod, so I dropped its support from caddy. www.orbitar.space / local is now redirected to orbitar.space / local.

CORS

I finally configured CORS the way it should work.

Only backend requests are responded with CORS policy allowing cross-domain requests from the frontend and frontend only. Even in development. You want access to backend directly - you always have your *:5001 server running.

The backend CORS-related headers are removed by caddy - this backend feature caught me by surprise and I puzzled for a little bit (I configured it right, why is it not working?)

Environment

Most of the changes in the environment variables were for Caddy.

Other

Updated uses actions to their latest versions.