Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74abd9c592 | ||
|
|
940a599515 | ||
|
|
e38ca1bf26 | ||
|
|
0538038deb | ||
|
|
65622715b5 | ||
|
|
6ee1f706e0 | ||
|
|
279fffb2ce | ||
|
|
8a18630e11 | ||
|
|
5fec257ab7 | ||
|
|
3b516022bd | ||
|
|
7ee077ada0 | ||
|
|
1c628625e9 | ||
|
|
a950161b00 |
No files matched your search
@@ -1,17 +1,8 @@
|
|||||||
# infra
|
# infra
|
||||||
|
|
||||||
Copier template for the root of a project: `docker-compose.yml` that includes every part, a `Makefile` that drives compose and delegates `fmt`, `check` and `build` to parts, `.env.example`, `.gitignore`, `CLAUDE.md` and pre-commit hooks.
|
Copier template for the root of a project: compose that includes every part, a Makefile that delegates to parts, `.gitignore`, `CLAUDE.md`, pre-commit hooks and `renovate.jsonc`. A part is a directory with `docker-compose.yml` (profiles per service: `services` for the app, `external` for databases), `docker-compose.override.yml.example`, a Makefile with `fmt`, `check`, `build` and `.env.example`.
|
||||||
|
|
||||||
A part is a directory with:
|
|
||||||
|
|
||||||
- `docker-compose.yml` with root-relative paths, plus `docker-compose.local.yml` and `docker-compose.prod.yml` selected by `COMPOSE_ENV`
|
|
||||||
- `Makefile` with `fmt`, `check` and `build` targets
|
|
||||||
- `.env.example` appended to the root `.env` by `make env`
|
|
||||||
- `CLAUDE.md` with the part's checking commands
|
|
||||||
|
|
||||||
Application services carry the `services` profile, databases and other infrastructure carry `external`.
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
copier copy --trust -d 'parts=["backend","frontend"]' <this-repo> <dest>
|
copier copy --trust -d layout=parts -d 'parts=["backend","frontend"]' <this-repo> <dest>
|
||||||
copier update -a .copier-answers.infra.yml
|
copier update -a .copier/infra.yml
|
||||||
```
|
```
|
||||||
+29
-1
@@ -1,18 +1,46 @@
|
|||||||
_subdirectory: template
|
_subdirectory: template
|
||||||
_templates_suffix: .jinja
|
_templates_suffix: .jinja
|
||||||
_answers_file: .copier-answers.infra.yml
|
_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:
|
||||||
|
type: str
|
||||||
|
help: Where the code lives
|
||||||
|
choices:
|
||||||
|
Parts in their own directories: parts
|
||||||
|
A single part at the root: single
|
||||||
|
default: parts
|
||||||
|
|
||||||
parts:
|
parts:
|
||||||
type: str
|
type: str
|
||||||
multiselect: true
|
multiselect: true
|
||||||
|
when: "{{ layout == 'parts' }}"
|
||||||
help: Parts that live in their own directory with a docker-compose.yml and a Makefile
|
help: Parts that live in their own directory with a docker-compose.yml and a Makefile
|
||||||
choices:
|
choices:
|
||||||
backend: backend
|
backend: backend
|
||||||
frontend: frontend
|
frontend: frontend
|
||||||
default: []
|
default: []
|
||||||
|
|
||||||
|
mcp_servers:
|
||||||
|
type: str
|
||||||
|
multiselect: true
|
||||||
|
help: MCP servers in .mcp.json
|
||||||
|
choices:
|
||||||
|
Context7 (library docs): context7
|
||||||
|
Svelte docs: svelte
|
||||||
|
default: []
|
||||||
|
|
||||||
init_git:
|
init_git:
|
||||||
type: bool
|
type: bool
|
||||||
help: git init and install pre-commit hooks
|
help: git init and install pre-commit hooks
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
COMPOSE_ENV=local
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
.env
|
|
||||||
.env.*
|
|
||||||
!.env.example
|
|
||||||
docker-compose.override.yml
|
|
||||||
.DS_Store
|
|
||||||
.idea
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
docker-compose.override.yml
|
||||||
|
.DS_Store
|
||||||
|
.idea
|
||||||
|
{% if layout == 'single' %}.venv/
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
.ruff_cache/
|
||||||
|
.pytest_cache/
|
||||||
|
sessions/*.session*
|
||||||
|
node_modules/
|
||||||
|
.svelte-kit/
|
||||||
|
/build/
|
||||||
|
{% endif %}
|
||||||
|
# Local playground
|
||||||
|
/t/
|
||||||
@@ -1,7 +1,17 @@
|
|||||||
repos:
|
repos:
|
||||||
- repo: local
|
- repo: local
|
||||||
hooks:{% if not parts %} []{% endif %}
|
hooks:{% if layout == 'parts' and not parts %} []{% endif %}
|
||||||
{% for part in parts %} - id: {{ part }}-fmt
|
{% if layout == 'single' %} - id: fmt
|
||||||
|
name: fmt
|
||||||
|
entry: make fmt
|
||||||
|
language: system
|
||||||
|
pass_filenames: false
|
||||||
|
- id: check
|
||||||
|
name: check
|
||||||
|
entry: make check
|
||||||
|
language: system
|
||||||
|
pass_filenames: false
|
||||||
|
{% endif %}{% for part in parts %} - id: {{ part }}-fmt
|
||||||
name: {{ part }} fmt
|
name: {{ part }} fmt
|
||||||
entry: make -C {{ part }} fmt
|
entry: make -C {{ part }} fmt
|
||||||
language: system
|
language: system
|
||||||
@@ -13,4 +23,4 @@ repos:
|
|||||||
language: system
|
language: system
|
||||||
files: ^{{ part }}/
|
files: ^{{ part }}/
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
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
|
|
||||||
|
|
||||||
env:
|
|
||||||
@test -f .env || cat .env.example $(addsuffix /.env.example,$(PARTS)) > .env
|
|
||||||
|
|
||||||
external:
|
|
||||||
$(EXTERNAL) up -d
|
|
||||||
|
|
||||||
recreate: external
|
|
||||||
$(SERVICES) up -d --force-recreate
|
|
||||||
|
|
||||||
rebuild: build recreate
|
|
||||||
|
|
||||||
restart:
|
|
||||||
$(SERVICES) restart
|
|
||||||
|
|
||||||
logs:
|
|
||||||
$(SERVICES) logs -f --tail=100
|
|
||||||
|
|
||||||
down:
|
|
||||||
$(EXTERNAL) --profile services down
|
|
||||||
|
|
||||||
fmt check build:
|
|
||||||
@for part in $(PARTS); do $(MAKE) -C $$part $@ || exit 1; done
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{% if parts %}include:
|
|
||||||
{% for part in parts %} - path:
|
|
||||||
- {{ part }}/docker-compose.yml
|
|
||||||
- {{ part }}/docker-compose.${COMPOSE_ENV:-local}.yml
|
|
||||||
project_directory: .
|
|
||||||
{% endfor %}{% else %}services: {}
|
|
||||||
{% endif %}
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": ["local>templates/renovate"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{% 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 %}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
PARTS := $(patsubst %/Makefile,%,$(wildcard */Makefile))
|
||||||
|
|
||||||
|
.PHONY: env recreate rebuild restart logs down fmt check build
|
||||||
|
|
||||||
|
env:
|
||||||
|
@fresh=; test -f .env || { awk 'FNR == 1 && NR > 1 { print "" } 1' .env.example $(addsuffix /.env.example,$(PARTS)) > .env; fresh=1; }; \
|
||||||
|
for part in $(PARTS); do \
|
||||||
|
override=$$part/docker-compose.override.yml; \
|
||||||
|
test -f $$override && continue; \
|
||||||
|
cp $$override.example $$override; \
|
||||||
|
for port in $$(sed -n 's/.*127\.0\.0\.1:\([0-9]*\):.*/\1/p' $$override | sort -u); do \
|
||||||
|
random=$$((20000 + $$(od -An -N2 -tu2 /dev/urandom) % 40000)); \
|
||||||
|
sed "s/127\.0\.0\.1:$$port:/127.0.0.1:$$random:/" $$override > $$override.tmp && mv $$override.tmp $$override; \
|
||||||
|
test -z "$$fresh" || { sed "s|localhost:$$port/|localhost:$$random/|" .env > .env.tmp && mv .env.tmp .env; }; \
|
||||||
|
done; \
|
||||||
|
done
|
||||||
|
|
||||||
|
recreate:
|
||||||
|
docker compose up -d --force-recreate
|
||||||
|
|
||||||
|
rebuild: build
|
||||||
|
docker compose up -d
|
||||||
|
|
||||||
|
restart:
|
||||||
|
docker compose restart
|
||||||
|
|
||||||
|
logs:
|
||||||
|
docker compose logs -f --tail=100
|
||||||
|
|
||||||
|
down:
|
||||||
|
docker compose down
|
||||||
|
|
||||||
|
fmt check build:
|
||||||
|
@for part in $(PARTS); do $(MAKE) -C $$part $@ || exit 1; done
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# {{ project_name }}
|
||||||
|
{% if project_description and project_description != project_name %}
|
||||||
|
{{ project_description }}
|
||||||
|
{% endif %}
|
||||||
|
```sh
|
||||||
|
make env # .env and docker-compose.override.yml from the examples
|
||||||
|
make recreate # the services in COMPOSE_PROFILES
|
||||||
|
make check
|
||||||
|
```
|
||||||
|
|
||||||
|
Parts: `{{ parts | join('/`, `') }}/`, each with its own Makefile.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{% if parts %}include:
|
||||||
|
{% for part in parts %} - path: {{ part }}/docker-compose.yml
|
||||||
|
project_directory: .
|
||||||
|
{% endfor %}{% else %}services: {}
|
||||||
|
{% endif %}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{%- set urls = {'context7': 'https://mcp.context7.com/mcp', 'svelte': 'https://mcp.svelte.dev/mcp'} -%}
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
{%- for server in mcp_servers %}
|
||||||
|
"{{ server }}": {
|
||||||
|
"type": "http",
|
||||||
|
"url": "{{ urls[server] }}"
|
||||||
|
}{{ "," if not loop.last }}
|
||||||
|
{%- endfor %}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user