diff --git a/copier.yml b/copier.yml index 958fb6d..d5481fc 100644 --- a/copier.yml +++ b/copier.yml @@ -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 diff --git a/template/{% if layout == 'parts' %}.env.example{% endif %}.jinja b/template/{% if layout == 'parts' %}.env.example{% endif %}.jinja index 919d6e4..23af4f4 100644 --- a/template/{% if layout == 'parts' %}.env.example{% endif %}.jinja +++ b/template/{% if layout == 'parts' %}.env.example{% endif %}.jinja @@ -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 %} diff --git a/template/{% if layout == 'parts' %}Makefile{% endif %} b/template/{% if layout == 'parts' %}Makefile{% endif %} index 99bfc9a..80af3a9 100644 --- a/template/{% if layout == 'parts' %}Makefile{% endif %} +++ b/template/{% if layout == 'parts' %}Makefile{% 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 diff --git a/template/{% if layout == 'parts' %}README.md{% endif %}.jinja b/template/{% if layout == 'parts' %}README.md{% endif %}.jinja new file mode 100644 index 0000000..884a89b --- /dev/null +++ b/template/{% if layout == 'parts' %}README.md{% endif %}.jinja @@ -0,0 +1,14 @@ +# {{ project_name }} +{% if project_description %} +{{ 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] }} ...`.