Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fec257ab7 | ||
|
|
3b516022bd | ||
|
|
7ee077ada0 |
@@ -1,10 +1,10 @@
|
||||
# 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.
|
||||
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:
|
||||
|
||||
- `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`
|
||||
- `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
|
||||
- `.env.example` appended to the root `.env` by `make env`
|
||||
- `CLAUDE.md` with the part's checking commands
|
||||
|
||||
+10
@@ -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
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
{% if parts %}COMPOSE_FILE=docker-compose.yml{% for part in parts %}:{{ part }}/docker-compose.local.yml{% endfor %}
|
||||
{% 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,25 @@
|
||||
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
|
||||
@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
|
||||
|
||||
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,14 @@
|
||||
# {{ 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.
|
||||
|
||||
`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] }} ...`.
|
||||
Reference in New Issue
Block a user