6 Commits
Author SHA1 Message Date
hh 8a18630e11 Deploy hooks 2026-09-09 00:37:04 +02:00
hh 5fec257ab7 README wording 2026-09-09 00:21:23 +02:00
hh 3b516022bd Single trailing newline 2026-09-09 00:19:34 +02:00
hh 7ee077ada0 Override-based compose, profiles in .env, README 2026-09-09 00:18:15 +02:00
hh 1c628625e9 Single part at the root, COMPOSE_FILE in .env 2026-09-08 20:38:27 +02:00
hh a950161b00 Answers file under .copier 2026-09-08 20:11:39 +02:00
12 changed files with 106 additions and 50 deletions
+4 -4
View File
@@ -1,10 +1,10 @@
# infra # infra
Copier template for the root of a project: `docker-compose.yml` that includes every part, a `Makefile` that drives compose and delegates `fmt`, `check` and `build` to parts, `.env.example`, `.gitignore`, `CLAUDE.md` and pre-commit hooks. Copier template for the root of a project. With `layout: parts` it ships a `docker-compose.yml` that includes every part, a `Makefile` that drives compose and delegates `fmt`, `check` and `build` to parts, a `README.md` and an `.env.example` whose `COMPOSE_FILE` adds each part's `docker-compose.override.yml` and whose `COMPOSE_PROFILES` selects what runs on the machine. With `layout: single` a part template renders straight into the root and infra ships only `.gitignore`, `CLAUDE.md` and pre-commit hooks.
A part is a directory with: A part is a directory with:
- `docker-compose.yml` with root-relative paths, plus `docker-compose.local.yml` and `docker-compose.prod.yml` selected by `COMPOSE_ENV` - `docker-compose.yml` with root-relative paths and a profile per service, plus `docker-compose.override.yml.example` for what differs between machines
- `Makefile` with `fmt`, `check` and `build` targets - `Makefile` with `fmt`, `check` and `build` targets
- `.env.example` appended to the root `.env` by `make env` - `.env.example` appended to the root `.env` by `make env`
- `CLAUDE.md` with the part's checking commands - `CLAUDE.md` with the part's checking commands
@@ -12,6 +12,6 @@ A part is a directory with:
Application services carry the `services` profile, databases and other infrastructure carry `external`. Application services carry the `services` profile, databases and other infrastructure carry `external`.
```sh ```sh
copier copy --trust -d 'parts=["backend","frontend"]' <this-repo> <dest> copier copy --trust -d layout=parts -d 'parts=["backend","frontend"]' <this-repo> <dest>
copier update -a .copier-answers.infra.yml copier update -a .copier/infra.yml
``` ```
+20 -1
View File
@@ -1,12 +1,31 @@
_subdirectory: template _subdirectory: template
_templates_suffix: .jinja _templates_suffix: .jinja
_answers_file: .copier-answers.infra.yml _answers_file: .copier/infra.yml
_envops: _envops:
keep_trailing_newline: true keep_trailing_newline: true
project_name:
type: str
help: Project name
default: Project
project_description:
type: str
help: Short description
default: ""
layout:
type: str
help: Where the code lives
choices:
Parts in their own directories: parts
A single part at the root: single
default: parts
parts: parts:
type: str type: str
multiselect: true multiselect: true
when: "{{ layout == 'parts' }}"
help: Parts that live in their own directory with a docker-compose.yml and a Makefile help: Parts that live in their own directory with a docker-compose.yml and a Makefile
choices: choices:
backend: backend backend: backend
-1
View File
@@ -1 +0,0 @@
COMPOSE_ENV=local
-6
View File
@@ -1,6 +0,0 @@
.env
.env.*
!.env.example
docker-compose.override.yml
.DS_Store
.idea
+16
View File
@@ -0,0 +1,16 @@
.env
.env.*
!.env.example
docker-compose.override.yml
.DS_Store
.idea
{% if layout == 'single' %}.venv/
__pycache__/
*.pyc
.ruff_cache/
.pytest_cache/
sessions/*.session*
node_modules/
.svelte-kit/
/build/
{% endif %}
+12 -2
View File
@@ -1,7 +1,17 @@
repos: repos:
- repo: local - repo: local
hooks:{% if not parts %} []{% endif %} hooks:{% if layout == 'parts' and not parts %} []{% endif %}
{% for part in parts %} - id: {{ part }}-fmt {% if layout == 'single' %} - id: fmt
name: fmt
entry: make fmt
language: system
pass_filenames: false
- id: check
name: check
entry: make check
language: system
pass_filenames: false
{% endif %}{% for part in parts %} - id: {{ part }}-fmt
name: {{ part }} fmt name: {{ part }} fmt
entry: make -C {{ part }} fmt entry: make -C {{ part }} fmt
language: system language: system
-28
View File
@@ -1,28 +0,0 @@
PARTS := $(patsubst %/Makefile,%,$(wildcard */Makefile))
SERVICES := docker compose --profile services
EXTERNAL := docker compose --profile external
.PHONY: env external recreate rebuild restart logs down fmt check build
env:
@test -f .env || cat .env.example $(addsuffix /.env.example,$(PARTS)) > .env
external:
$(EXTERNAL) up -d
recreate: external
$(SERVICES) up -d --force-recreate
rebuild: build recreate
restart:
$(SERVICES) restart
logs:
$(SERVICES) logs -f --tail=100
down:
$(EXTERNAL) --profile services down
fmt check build:
@for part in $(PARTS); do $(MAKE) -C $$part $@ || exit 1; done
-7
View File
@@ -1,7 +0,0 @@
{% if parts %}include:
{% for part in parts %} - path:
- {{ part }}/docker-compose.yml
- {{ part }}/docker-compose.${COMPOSE_ENV:-local}.yml
project_directory: .
{% endfor %}{% else %}services: {}
{% endif %}
@@ -0,0 +1,3 @@
{% if parts %}COMPOSE_FILE=docker-compose.yml{% for part in parts %}:{{ part }}/docker-compose.override.yml{% endfor %}
COMPOSE_PROFILES={% if 'backend' in parts %}external,{% endif %}services
{% endif %}
@@ -0,0 +1,29 @@
PARTS := $(patsubst %/Makefile,%,$(wildcard */Makefile))
.PHONY: env recreate rebuild restart logs down deploy fmt check build pre-deploy post-deploy
env:
@test -f .env || awk 'FNR == 1 && NR > 1 { print "" } 1' .env.example $(addsuffix /.env.example,$(PARTS)) > .env
@for part in $(PARTS); do test -f $$part/docker-compose.override.yml || cp $$part/docker-compose.override.yml.example $$part/docker-compose.override.yml; done
recreate:
docker compose up -d --force-recreate
rebuild: build
docker compose up -d
restart:
docker compose restart
logs:
docker compose logs -f --tail=100
down:
docker compose down
deploy: pre-deploy
docker compose up -d
$(MAKE) post-deploy
fmt check build pre-deploy post-deploy:
@for part in $(PARTS); do $(MAKE) -C $$part $@ || exit 1; done
@@ -0,0 +1,16 @@
# {{ project_name }}
{% if project_description and project_description != project_name %}
{{ project_description }}
{% endif %}
Runs in Docker, locally the same way as in production. Each part in `{{ parts | join('/`, `') }}/` brings its own `docker-compose.yml`, included from the root one. `COMPOSE_PROFILES` in `.env` selects the services that run on this machine. `docker-compose.override.yml` in each part holds what differs between machines: published ports and the aliases on the external `caddy` network.
```sh
make env
make recreate
```
`make env` creates `.env` from the examples of every part and copies each `docker-compose.override.yml.example`. `make recreate` starts the selected profiles, `make rebuild` builds the images first, `make logs`, `make restart` and `make down` do what they say.
To deploy, `git pull && make deploy`. It runs `make pre-deploy` in every part, which builds images only when their inputs changed and applies migrations, then `docker compose up -d`, then `make post-deploy`, which restarts the services whose mounted code changed. A deploy system with its own `up` step calls the two hooks around it. What was built and started is remembered as `refs/deploy/*` in the clone.
`make fmt`, `make check` and `make build` run in every part. Part-specific targets live in the part's own Makefile: `make -C {{ parts[0] }} ...`.
@@ -0,0 +1,5 @@
{% if parts %}include:
{% for part in parts %} - path: {{ part }}/docker-compose.yml
project_directory: .
{% endfor %}{% else %}services: {}
{% endif %}