From a4994ce234d9a7037ff1a4c7962934a6371b95dc Mon Sep 17 00:00:00 2001 From: h Date: Wed, 9 Sep 2026 00:37:04 +0200 Subject: [PATCH] Deploy hooks --- template/{{ part_dir }}/Makefile.jinja | 17 ++++++++++++++++- ...ayout == 'root' %}README.md{% endif %}.jinja | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/template/{{ part_dir }}/Makefile.jinja b/template/{{ part_dir }}/Makefile.jinja index d06952b..177e951 100644 --- a/template/{{ part_dir }}/Makefile.jinja +++ b/template/{{ part_dir }}/Makefile.jinja @@ -1,6 +1,9 @@ COMPOSE := docker compose{% if layout == 'part' %} --project-directory ..{% endif %} +{% if serve != 'api' %}IMAGE := {{ project_slug }}/frontend +{% endif %}changed = ! git diff --quiet $(1) -- $(2) 2>/dev/null +stamp = { git update-ref $(1) HEAD 2>/dev/null || true; } -.PHONY: {% if layout == 'root' %}env recreate rebuild restart logs down {% endif %}fmt check build dev +.PHONY: {% if layout == 'root' %}env recreate rebuild restart logs down deploy {% endif %}fmt check build pre-deploy post-deploy dev fmt: bun run fix @@ -13,6 +16,14 @@ build: {% if serve == 'api' %} $(COMPOSE) run --rm frontend-dev sh -c "bun install && bun run build" {% else %} $(COMPOSE) build frontend {% endif %} +pre-deploy: + @if $(call changed,refs/deploy/frontend,.) || {% if serve == 'api' %}! test -d build{% else %}! docker image inspect $(IMAGE) >/dev/null 2>&1{% endif %}; then \ + $(MAKE) build && $(call stamp,refs/deploy/frontend); \ + fi + +post-deploy: + @: + dev: bun run dev {% if layout == 'root' %} @@ -34,4 +45,8 @@ logs: down: $(COMPOSE) down + +deploy: pre-deploy + $(COMPOSE) up -d + $(MAKE) post-deploy {% endif %} \ No newline at end of file diff --git a/template/{{ part_dir }}/{% if layout == 'root' %}README.md{% endif %}.jinja b/template/{{ part_dir }}/{% if layout == 'root' %}README.md{% endif %}.jinja index 01c5dd5..ba8d1a5 100644 --- a/template/{{ part_dir }}/{% if layout == 'root' %}README.md{% endif %}.jinja +++ b/template/{{ part_dir }}/{% if layout == 'root' %}README.md{% endif %}.jinja @@ -9,4 +9,6 @@ make recreate `make env` creates `.env` and `docker-compose.override.yml` from their examples. `make recreate` starts the selected profiles, `make rebuild` builds the image first, `make logs`, `make restart` and `make down` do what they say. +To deploy, `git pull && make deploy`. It runs `make pre-deploy`, which rebuilds the image only when something in the repository changed, then `docker compose up -d`. A deploy system with its own `up` step calls `make pre-deploy` before it and `make post-deploy` after. What was built is remembered as `refs/deploy/*` in the clone. + `make dev` runs the Vite dev server on the host, `make fmt` formats, `make check` runs svelte-check and the linter.