Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a18630e11 | ||
|
|
5fec257ab7 | ||
|
|
3b516022bd | ||
|
|
7ee077ada0 |
@@ -1,10 +1,10 @@
|
|||||||
# infra
|
# 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:
|
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
|
- `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
|
||||||
|
|||||||
+10
@@ -4,6 +4,16 @@ _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:
|
layout:
|
||||||
type: str
|
type: str
|
||||||
help: Where the code lives
|
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 %}
|
{% endif %}
|
||||||
@@ -1,28 +1,29 @@
|
|||||||
PARTS := $(patsubst %/Makefile,%,$(wildcard */Makefile))
|
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 deploy fmt check build pre-deploy post-deploy
|
||||||
|
|
||||||
env:
|
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:
|
recreate:
|
||||||
$(EXTERNAL) up -d
|
docker compose up -d --force-recreate
|
||||||
|
|
||||||
recreate: external
|
rebuild: build
|
||||||
$(SERVICES) up -d --force-recreate
|
docker compose up -d
|
||||||
|
|
||||||
rebuild: build recreate
|
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
$(SERVICES) restart
|
docker compose restart
|
||||||
|
|
||||||
logs:
|
logs:
|
||||||
$(SERVICES) logs -f --tail=100
|
docker compose logs -f --tail=100
|
||||||
|
|
||||||
down:
|
down:
|
||||||
$(EXTERNAL) --profile services down
|
docker compose down
|
||||||
|
|
||||||
fmt check build:
|
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
|
@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] }} ...`.
|
||||||
Reference in New Issue
Block a user