11 Commits
10 changed files with 72 additions and 27 deletions

No files matched your search

+1 -10
View File
@@ -1,15 +1,6 @@
# infra
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, and an `.env.example` whose `COMPOSE_FILE` adds each part's `docker-compose.local.yml`. 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:
- `docker-compose.yml` with root-relative paths, plus `docker-compose.local.yml` and `docker-compose.prod.yml` picked through `COMPOSE_FILE` in the root `.env`
- `Makefile` with `fmt`, `check` and `build` targets
- `.env.example` appended to the root `.env` by `make env`
- `CLAUDE.md` with the part's checking commands
Application services carry the `services` profile, databases and other infrastructure carry `external`.
Copier template for the root of a project: compose that includes every part, a Makefile that delegates to parts, `.gitignore`, `CLAUDE.md`, pre-commit hooks and `renovate.jsonc`. A part is a directory with `docker-compose.yml` (profiles per service: `services` for the app, `external` for databases), `docker-compose.override.yml.example`, a Makefile with `fmt`, `check`, `build` and `.env.example`.
```sh
copier copy --trust -d layout=parts -d 'parts=["backend","frontend"]' <this-repo> <dest>
+19
View File
@@ -4,6 +4,16 @@ _answers_file: .copier/infra.yml
_envops:
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
@@ -22,6 +32,15 @@ parts:
frontend: frontend
default: []
mcp_servers:
type: str
multiselect: true
help: MCP servers in .mcp.json
choices:
Context7 (library docs): context7
Svelte docs: svelte
default: []
init_git:
type: bool
help: git init and install pre-commit hooks
+2
View File
@@ -14,3 +14,5 @@ node_modules/
.svelte-kit/
/build/
{% endif %}
# Local playground
/t/
+1 -1
View File
@@ -23,4 +23,4 @@ repos:
language: system
files: ^{{ part }}/
pass_filenames: false
{% endfor %}
{% endfor %}
+4
View File
@@ -0,0 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["local>templates/renovate"]
}
@@ -1,2 +1,3 @@
{% if parts %}COMPOSE_FILE=docker-compose.yml{% for part in parts %}:{{ part }}/docker-compose.local.yml{% endfor %}
{% endif %}
{% 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 %}
@@ -1,28 +1,34 @@
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
.PHONY: env recreate rebuild restart logs down fmt check build
env:
@test -f .env || cat .env.example $(addsuffix /.env.example,$(PARTS)) > .env
@fresh=; test -f .env || { awk 'FNR == 1 && NR > 1 { print "" } 1' .env.example $(addsuffix /.env.example,$(PARTS)) > .env; fresh=1; }; \
for part in $(PARTS); do \
override=$$part/docker-compose.override.yml; \
test -f $$override && continue; \
cp $$override.example $$override; \
for port in $$(sed -n 's/.*127\.0\.0\.1:\([0-9]*\):.*/\1/p' $$override | sort -u); do \
random=$$((20000 + $$(od -An -N2 -tu2 /dev/urandom) % 40000)); \
sed "s/127\.0\.0\.1:$$port:/127.0.0.1:$$random:/" $$override > $$override.tmp && mv $$override.tmp $$override; \
test -z "$$fresh" || { sed "s|localhost:$$port/|localhost:$$random/|" .env > .env.tmp && mv .env.tmp .env; }; \
done; \
done
external:
$(EXTERNAL) up -d
recreate:
docker compose up -d --force-recreate
recreate: external
$(SERVICES) up -d --force-recreate
rebuild: build recreate
rebuild: build
docker compose up -d
restart:
$(SERVICES) restart
docker compose restart
logs:
$(SERVICES) logs -f --tail=100
docker compose logs -f --tail=100
down:
$(EXTERNAL) --profile services down
docker compose down
fmt check build:
@for part in $(PARTS); do $(MAKE) -C $$part $@ || exit 1; done
@@ -0,0 +1,11 @@
# {{ project_name }}
{% if project_description and project_description != project_name %}
{{ project_description }}
{% endif %}
```sh
make env # .env and docker-compose.override.yml from the examples
make recreate # the services in COMPOSE_PROFILES
make check
```
Parts: `{{ parts | join('/`, `') }}/`, each with its own Makefile.
@@ -2,4 +2,4 @@
{% for part in parts %} - path: {{ part }}/docker-compose.yml
project_directory: .
{% endfor %}{% else %}services: {}
{% endif %}
{% endif %}
@@ -0,0 +1,11 @@
{%- set urls = {'context7': 'https://mcp.context7.com/mcp', 'svelte': 'https://mcp.svelte.dev/mcp'} -%}
{
"mcpServers": {
{%- for server in mcp_servers %}
"{{ server }}": {
"type": "http",
"url": "{{ urls[server] }}"
}{{ "," if not loop.last }}
{%- endfor %}
}
}