Compare commits
3
Commits
3dc3a03066
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c573c1b1e8 | ||
|
|
ea78a12a83 | ||
|
|
0a3511a44b |
No files matched your search
@@ -1,8 +1,6 @@
|
|||||||
# blank
|
# blank
|
||||||
|
|
||||||
Copier template for a part in any stack that has no template of its own, either as a `backend/` or `frontend/` part next to other parts or alone at the root of the project (`layout`). It brings nothing but the part contract, the code and the `Dockerfile` are yours.
|
Copier template for a part with no template of its own: compose, Makefile and `.env.example`, the code and the `Dockerfile` are yours. A `backend/` or `frontend/` part or the whole project (`layout`), on top of `infra`.
|
||||||
|
|
||||||
Ships `docker-compose.yml` with root-relative paths and one service under its own profile and `services`, `docker-compose.override.yml.example` (the `caddy` network alias, copied by `make env`), a `Makefile` with empty `fmt` and `check`, `build`, `pre-deploy` that rebuilds the image only when the part changed and an empty `post-deploy`, and `.env.example`. Applied on top of the `infra` template, `layout: parts` or `layout: single` respectively. The `caddy` template expects the backend to listen on 8080 and the frontend on 3000.
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
copier copy --trust -a .copier/backend.yml -d project_name="My Thing" -d part=backend <this-repo> <dest>
|
copier copy --trust -a .copier/backend.yml -d project_name="My Thing" -d part=backend <this-repo> <dest>
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
COMPOSE := {% if layout == 'part' %}cd .. && {% endif %}docker compose
|
COMPOSE := {% if layout == 'part' %}cd .. && {% endif %}docker compose
|
||||||
IMAGE := {{ project_slug }}/{{ part }}
|
|
||||||
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 deploy {% endif %}fmt check build pre-deploy post-deploy
|
.PHONY: {% if layout == 'root' %}env recreate rebuild restart logs down {% endif %}fmt check build
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
@:
|
@:
|
||||||
@@ -13,14 +10,6 @@ check:
|
|||||||
|
|
||||||
build:
|
build:
|
||||||
$(COMPOSE) build {{ service }}
|
$(COMPOSE) build {{ service }}
|
||||||
|
|
||||||
pre-deploy:
|
|
||||||
@if $(call changed,refs/deploy/{{ part }},.) || ! docker image inspect $(IMAGE) >/dev/null 2>&1; then \
|
|
||||||
$(MAKE) build && $(call stamp,refs/deploy/{{ part }}); \
|
|
||||||
fi
|
|
||||||
|
|
||||||
post-deploy:
|
|
||||||
@:
|
|
||||||
{% if layout == 'root' %}
|
{% if layout == 'root' %}
|
||||||
env:
|
env:
|
||||||
@fresh=; test -f .env || { cp .env.example .env; fresh=1; }; \
|
@fresh=; test -f .env || { cp .env.example .env; fresh=1; }; \
|
||||||
@@ -47,8 +36,4 @@ logs:
|
|||||||
|
|
||||||
down:
|
down:
|
||||||
$(COMPOSE) down
|
$(COMPOSE) down
|
||||||
|
|
||||||
deploy: pre-deploy
|
|
||||||
$(COMPOSE) up -d
|
|
||||||
$(MAKE) post-deploy
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
services:
|
services:
|
||||||
{{ service }}:
|
{{ service }}:
|
||||||
build: {{ part_dir }}
|
build: {{ part_dir }}
|
||||||
image: {{ project_slug }}/{{ part }}
|
image: {{ project_slug | replace('_', '-') }}/{{ part }}
|
||||||
profiles: [{{ service }}, services]
|
profiles: [{{ service }}, services]
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file:
|
env_file:
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
# {{ project_name }}
|
# {{ project_name }}
|
||||||
|
|
||||||
Runs in Docker, locally the same way as in production. `COMPOSE_PROFILES` in `.env` selects the services that run on this machine. `docker-compose.override.yml` holds what differs between machines: published ports and the aliases on the external `caddy` network.
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
make env
|
make env # .env and docker-compose.override.yml from the examples
|
||||||
make recreate
|
make recreate # the services in COMPOSE_PROFILES
|
||||||
```
|
```
|
||||||
|
|
||||||
`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.
|
|
||||||
Reference in new issue
Block a user