Compare commits

3 Commits
3 changed files with 13 additions and 4 deletions

No files matched your search

+10 -3
View File
@@ -1,5 +1,5 @@
COMPOSE := {% if layout == 'part' %}cd .. && {% endif %}docker compose
IMAGE := {{ project_slug }}/{{ part }}
IMAGE := {{ project_slug | replace('_', '-') }}/{{ part }}
changed = ! git diff --quiet $(1) -- $(2) 2>/dev/null
stamp = { git update-ref $(1) HEAD 2>/dev/null || true; }
@@ -23,8 +23,15 @@ post-deploy:
@:
{% if layout == 'root' %}
env:
@test -f .env || cp .env.example .env
@test -f docker-compose.override.yml || cp docker-compose.override.yml.example docker-compose.override.yml
@fresh=; test -f .env || { cp .env.example .env; fresh=1; }; \
if ! test -f docker-compose.override.yml; then \
cp docker-compose.override.yml.example docker-compose.override.yml; \
for port in $$(sed -n 's/.*127\.0\.0\.1:\([0-9]*\):.*/\1/p' docker-compose.override.yml | sort -u); do \
random=$$((20000 + $$(od -An -N2 -tu2 /dev/urandom) % 40000)); \
sed "s/127\.0\.0\.1:$$port:/127.0.0.1:$$random:/" docker-compose.override.yml > docker-compose.override.yml.tmp && mv docker-compose.override.yml.tmp docker-compose.override.yml; \
test -z "$$fresh" || { sed "s|localhost:$$port/|localhost:$$random/|" .env > .env.tmp && mv .env.tmp .env; }; \
done; \
fi
recreate:
$(COMPOSE) up -d --force-recreate
@@ -1,7 +1,7 @@
services:
{{ service }}:
build: {{ part_dir }}
image: {{ project_slug }}/{{ part }}
image: {{ project_slug | replace('_', '-') }}/{{ part }}
profiles: [{{ service }}, services]
restart: unless-stopped
env_file:
@@ -10,3 +10,5 @@ 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.
In the fleet, production is deployed from `infra/komodo` instead (git mode of Komodo, see `docs/architecture.md` there): Komodo clones this repo, and a layer plus `deploy.sh` in the stack's directory tag images by the hash of what they bake in and write `.env` from sops. The repo only has to stay a plain recipe: images built from `build:` in compose, `caddy/site.caddy`. `make deploy` and `refs/deploy/*` are for a checkout deployed by hand.