refactor(skills): extract containerize-project from build-* scaffolds
- refactor(scaffold): move Docker/compose templates and three-stage doc into new containerize-project skill; build-* skills delegate their Docker step - fix(scaffold): drop source mount from the production compose service - fix(scaffold): add .dockerignore templates so COPY . . excludes .git/.env/data - feat(scaffold): run production stages as non-root app user; pin uv install via COPY --from=ghcr.io/astral-sh/uv:0.7 - docs(README): list containerize-project and add-docker-secrets; remove the now-empty _concepts section Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
79141458d3
commit
2517b1fb43
31
README.md
31
README.md
@ -9,8 +9,7 @@ Modeled on [mattpocock/skills](https://github.com/mattpocock/skills).
|
|||||||
|
|
||||||
Claude Code discovers skills at `~/.claude/skills/<name>/SKILL.md` (flat,
|
Claude Code discovers skills at `~/.claude/skills/<name>/SKILL.md` (flat,
|
||||||
one level deep — category subfolders are not scanned). Symlink each skill
|
one level deep — category subfolders are not scanned). Symlink each skill
|
||||||
individually; the `_concepts/` doc folder lives inside `skills/` and is
|
individually:
|
||||||
not symlinked separately (skills reach it via relative paths):
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
mkdir -p ~/.claude/skills
|
mkdir -p ~/.claude/skills
|
||||||
@ -49,19 +48,21 @@ skill list.
|
|||||||
`justfile`.
|
`justfile`.
|
||||||
|
|
||||||
### scaffold
|
### scaffold
|
||||||
- **build-py-project** — uv + Docker (3-stage) + justfile + pyproject.
|
- **build-py-project** — uv + justfile + pyproject; Docker via
|
||||||
- **build-r-package** — renv + rocker/r-ver + DESCRIPTION + testthat.
|
`containerize-project`.
|
||||||
- **build-r-analysis** — renv + rocker/verse + `_targets.R` + Quarto.
|
- **build-r-package** — renv + DESCRIPTION + testthat; Docker via
|
||||||
|
`containerize-project`.
|
||||||
### _concepts
|
- **build-r-analysis** — renv + `_targets.R` + Quarto; Docker via
|
||||||
Shared reference docs under `skills/_concepts/` — not skills (no
|
`containerize-project`.
|
||||||
`SKILL.md`), loaded on demand by skills that link them. The leading
|
- **containerize-project** — three-stage Docker (base/production/
|
||||||
underscore is the "not a skill" marker; the install loop above skips it
|
development) for uv and renv projects: Dockerfile, compose,
|
||||||
because it sits one level shallower than `skills/<category>/<name>/`.
|
`.dockerignore`, justfile recipes. Hardened defaults (non-root
|
||||||
|
production user, pinned uv, no source mount in prod). The `build-*`
|
||||||
- [`skills/_concepts/three-stage-dockerfile.md`](skills/_concepts/three-stage-dockerfile.md)
|
skills delegate their Docker step here; also works standalone on an
|
||||||
— base / production / development Docker pattern used by every
|
existing repo.
|
||||||
`scaffold/build-*` skill.
|
- **add-docker-secrets** — build-time (BuildKit secret mounts) and
|
||||||
|
runtime (`env_file` / compose secrets) credentials without leaking
|
||||||
|
into image layers.
|
||||||
|
|
||||||
## Adding a skill
|
## Adding a skill
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: build-py-project
|
name: build-py-project
|
||||||
description: Scaffold a new Python project with uv for dependency management, a three-stage Docker setup (base/production/development), docker-compose, justfile task runner, and pyproject.toml configured with ruff, ty, and pytest. Materialises files into a target directory and stops on `jj diff` for review before any commit. Use when the user says "new python project", "scaffold python", "create python project", "set up python repo", "bootstrap python", "/build-py-project".
|
description: Scaffold a new Python project with uv for dependency management, a justfile task runner, and pyproject.toml configured with ruff, ty, and pytest, then delegate the three-stage Docker setup (Dockerfile, docker-compose, .dockerignore) to containerize-project. Materialises files into a target directory and stops on `jj diff` for review before any commit. Use when the user says "new python project", "scaffold python", "create python project", "set up python repo", "bootstrap python", "/build-py-project".
|
||||||
---
|
---
|
||||||
|
|
||||||
# build-py-project
|
# build-py-project
|
||||||
@ -26,17 +26,19 @@ description: Scaffold a new Python project with uv for dependency management, a
|
|||||||
<project>/
|
<project>/
|
||||||
├── src/<package>/__init__.py
|
├── src/<package>/__init__.py
|
||||||
├── tests/fixtures/.gitkeep
|
├── tests/fixtures/.gitkeep
|
||||||
├── Dockerfile ← Dockerfile.tpl
|
|
||||||
├── docker-compose.yml ← docker-compose.yml.tpl
|
|
||||||
├── justfile ← justfile.tpl
|
├── justfile ← justfile.tpl
|
||||||
├── pyproject.toml ← pyproject.toml.tpl
|
├── pyproject.toml ← pyproject.toml.tpl
|
||||||
└── .gitignore ← gitignore.tpl
|
└── .gitignore ← gitignore.tpl
|
||||||
```
|
```
|
||||||
3. **Stop. Do not run `jj describe`.** Tell the user:
|
3. **Delegate Docker** to
|
||||||
|
[`/containerize-project`](../containerize-project/SKILL.md) (python
|
||||||
|
variant): it writes `Dockerfile`, `docker-compose.yml`,
|
||||||
|
`.dockerignore`, and appends the Docker recipes to the justfile.
|
||||||
|
4. **Stop. Do not run `jj describe`.** Tell the user:
|
||||||
> "Review with `jj diff` (or `git status` + `git diff`). Then run
|
> "Review with `jj diff` (or `git status` + `git diff`). Then run
|
||||||
> `just build-dev` to verify the toolchain. Describe the change with
|
> `just build-dev` to verify the toolchain. Describe the change with
|
||||||
> [`/jj-atomic`](../../productivity/jj-atomic/SKILL.md) when satisfied."
|
> [`/jj-atomic`](../../productivity/jj-atomic/SKILL.md) when satisfied."
|
||||||
4. **Suggest** running [`/write-readme-py`](../../engineering/write-readme-py/SKILL.md)
|
5. **Suggest** running [`/write-readme-py`](../../engineering/write-readme-py/SKILL.md)
|
||||||
after the first successful build to generate the README.
|
after the first successful build to generate the README.
|
||||||
|
|
||||||
## Placeholders used by templates
|
## Placeholders used by templates
|
||||||
@ -56,8 +58,8 @@ description: Scaffold a new Python project with uv for dependency management, a
|
|||||||
the scaffold lean and let the user grow it.
|
the scaffold lean and let the user grow it.
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
- [`../../_concepts/three-stage-dockerfile.md`](../../_concepts/three-stage-dockerfile.md)
|
- [`../containerize-project/SKILL.md`](../containerize-project/SKILL.md)
|
||||||
— rationale for the base/production/development pattern in `Dockerfile.tpl`.
|
— owns the Docker templates and the three-stage pattern rationale.
|
||||||
- [`../../engineering/dev-python/SKILL.md`](../../engineering/dev-python/SKILL.md)
|
- [`../../engineering/dev-python/SKILL.md`](../../engineering/dev-python/SKILL.md)
|
||||||
— workflow that this scaffold sets up.
|
— workflow that this scaffold sets up.
|
||||||
- [`../../engineering/write-readme-py/SKILL.md`](../../engineering/write-readme-py/SKILL.md)
|
- [`../../engineering/write-readme-py/SKILL.md`](../../engineering/write-readme-py/SKILL.md)
|
||||||
|
|||||||
@ -6,24 +6,8 @@ set dotenv-load := false
|
|||||||
default:
|
default:
|
||||||
@just --list
|
@just --list
|
||||||
|
|
||||||
# ── Docker ──────────────────────────────────────────────────────────────
|
# Docker recipes (build-dev, up, down, …) are appended by
|
||||||
build-dev:
|
# /containerize-project from its justfile-docker.tpl.
|
||||||
docker compose build dev
|
|
||||||
|
|
||||||
build-prod:
|
|
||||||
docker compose build production
|
|
||||||
|
|
||||||
up:
|
|
||||||
docker compose run --rm dev bash
|
|
||||||
|
|
||||||
up-prod:
|
|
||||||
docker compose run --rm production
|
|
||||||
|
|
||||||
down:
|
|
||||||
docker compose down
|
|
||||||
|
|
||||||
rebuild:
|
|
||||||
docker compose build --no-cache dev
|
|
||||||
|
|
||||||
# ── Linting & Formatting ────────────────────────────────────────────────
|
# ── Linting & Formatting ────────────────────────────────────────────────
|
||||||
lint:
|
lint:
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: build-r-analysis
|
name: build-r-analysis
|
||||||
description: Scaffold a new R analysis project with renv for dependency management, three-stage Docker on rocker/verse (base/production/development), docker-compose, justfile, a `_targets.R` workflow skeleton, and Quarto reports under `reports/`. Configured with lintr, styler, testthat, and box. Materialises files and stops on `jj diff` for review before any commit. Use when the user says "new R analysis", "scaffold R project", "create R analysis", "set up R data science project", "new quarto project", "/build-r-analysis".
|
description: Scaffold a new R analysis project with renv for dependency management, a justfile, a `_targets.R` workflow skeleton, and Quarto reports under `reports/`, then delegate the three-stage Docker setup on rocker/verse (Dockerfile, docker-compose, .dockerignore) to containerize-project. Configured with lintr, styler, testthat, and box. Materialises files and stops on `jj diff` for review before any commit. Use when the user says "new R analysis", "scaffold R project", "create R analysis", "set up R data science project", "new quarto project", "/build-r-analysis".
|
||||||
---
|
---
|
||||||
|
|
||||||
# build-r-analysis
|
# build-r-analysis
|
||||||
@ -26,12 +26,14 @@ description: Scaffold a new R analysis project with renv for dependency manageme
|
|||||||
├── reports/index.qmd ← reports-index.qmd.tpl
|
├── reports/index.qmd ← reports-index.qmd.tpl
|
||||||
├── tests/testthat/test-functions.R ← tests-test-functions.R.tpl
|
├── tests/testthat/test-functions.R ← tests-test-functions.R.tpl
|
||||||
├── _targets.R ← _targets.R.tpl
|
├── _targets.R ← _targets.R.tpl
|
||||||
├── Dockerfile ← Dockerfile.tpl
|
|
||||||
├── docker-compose.yml ← docker-compose.yml.tpl
|
|
||||||
├── justfile ← justfile.tpl
|
├── justfile ← justfile.tpl
|
||||||
└── .gitignore ← gitignore.tpl
|
└── .gitignore ← gitignore.tpl
|
||||||
```
|
```
|
||||||
3. **Stop. Do not run `jj describe`.** Tell the user:
|
3. **Delegate Docker** to
|
||||||
|
[`/containerize-project`](../containerize-project/SKILL.md)
|
||||||
|
(r-analysis variant): it writes `Dockerfile`, `docker-compose.yml`,
|
||||||
|
`.dockerignore`, and appends the Docker recipes to the justfile.
|
||||||
|
4. **Stop. Do not run `jj describe`.** Tell the user:
|
||||||
> "Review with `jj diff`. Then `just build-dev` → `just up` → `R -e
|
> "Review with `jj diff`. Then `just build-dev` → `just up` → `R -e
|
||||||
> 'renv::init()'` to lock dependencies. Then `just run` to execute
|
> 'renv::init()'` to lock dependencies. Then `just run` to execute
|
||||||
> the pipeline. Describe with
|
> the pipeline. Describe with
|
||||||
@ -52,8 +54,8 @@ description: Scaffold a new R analysis project with renv for dependency manageme
|
|||||||
showing the box-imported pipeline pattern. Replace, don't extend.
|
showing the box-imported pipeline pattern. Replace, don't extend.
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
- [`../../_concepts/three-stage-dockerfile.md`](../../_concepts/three-stage-dockerfile.md)
|
- [`../containerize-project/SKILL.md`](../containerize-project/SKILL.md)
|
||||||
— rationale for `Dockerfile.tpl`.
|
— owns the Docker templates and the three-stage pattern rationale.
|
||||||
- [`../../engineering/dev-r/SKILL.md`](../../engineering/dev-r/SKILL.md)
|
- [`../../engineering/dev-r/SKILL.md`](../../engineering/dev-r/SKILL.md)
|
||||||
— workflow auto-detects `_targets.R` → R-analysis loop.
|
— workflow auto-detects `_targets.R` → R-analysis loop.
|
||||||
- [`../../engineering/r-style/SKILL.md`](../../engineering/r-style/SKILL.md)
|
- [`../../engineering/r-style/SKILL.md`](../../engineering/r-style/SKILL.md)
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
services:
|
|
||||||
dev:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
target: development
|
|
||||||
container_name: <project-name>-dev
|
|
||||||
volumes:
|
|
||||||
- .:/usr/<project-name>
|
|
||||||
- renv-cache:/root/.cache/R/renv
|
|
||||||
|
|
||||||
production:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
target: production
|
|
||||||
container_name: <project-name>-prod
|
|
||||||
volumes:
|
|
||||||
- .:/usr/<project-name>
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
renv-cache:
|
|
||||||
@ -6,21 +6,8 @@ set dotenv-load := false
|
|||||||
default:
|
default:
|
||||||
@just --list
|
@just --list
|
||||||
|
|
||||||
# ── Docker ──────────────────────────────────────────────────────────────
|
# Docker recipes (build-dev, up, down, …) are appended by
|
||||||
build-dev:
|
# /containerize-project from its justfile-docker.tpl.
|
||||||
docker compose build dev
|
|
||||||
|
|
||||||
build-prod:
|
|
||||||
docker compose build production
|
|
||||||
|
|
||||||
up:
|
|
||||||
docker compose run --rm dev bash
|
|
||||||
|
|
||||||
down:
|
|
||||||
docker compose down
|
|
||||||
|
|
||||||
rebuild:
|
|
||||||
docker compose build --no-cache dev
|
|
||||||
|
|
||||||
# ── Pipeline ────────────────────────────────────────────────────────────
|
# ── Pipeline ────────────────────────────────────────────────────────────
|
||||||
run:
|
run:
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: build-r-package
|
name: build-r-package
|
||||||
description: Scaffold a new R package with renv for dependency management, a three-stage Docker setup (base/production/development) on rocker/r-ver, docker-compose, justfile task runner, DESCRIPTION, NAMESPACE generation via roxygen2, and testthat ed. 3. Materialises files into a target directory and stops on `jj diff` for review before any commit. Use when the user says "new R package", "scaffold R package", "create R package", "set up R package", "bootstrap R package", "/build-r-package".
|
description: Scaffold a new R package with renv for dependency management, a justfile task runner, DESCRIPTION, NAMESPACE generation via roxygen2, and testthat ed. 3, then delegate the three-stage Docker setup on rocker/r-ver (Dockerfile, docker-compose, .dockerignore) to containerize-project. Materialises files into a target directory and stops on `jj diff` for review before any commit. Use when the user says "new R package", "scaffold R package", "create R package", "set up R package", "bootstrap R package", "/build-r-package".
|
||||||
---
|
---
|
||||||
|
|
||||||
# build-r-package
|
# build-r-package
|
||||||
@ -25,18 +25,20 @@ description: Scaffold a new R package with renv for dependency management, a thr
|
|||||||
<package>/
|
<package>/
|
||||||
├── R/<package>-package.R
|
├── R/<package>-package.R
|
||||||
├── tests/testthat/test-<package>.R
|
├── tests/testthat/test-<package>.R
|
||||||
├── Dockerfile ← Dockerfile.tpl
|
|
||||||
├── docker-compose.yml ← docker-compose.yml.tpl
|
|
||||||
├── justfile ← justfile.tpl
|
├── justfile ← justfile.tpl
|
||||||
├── DESCRIPTION ← DESCRIPTION.tpl
|
├── DESCRIPTION ← DESCRIPTION.tpl
|
||||||
└── .gitignore ← gitignore.tpl
|
└── .gitignore ← gitignore.tpl
|
||||||
```
|
```
|
||||||
3. **Stop. Do not run `jj describe`.** Tell the user:
|
3. **Delegate Docker** to
|
||||||
|
[`/containerize-project`](../containerize-project/SKILL.md)
|
||||||
|
(r-package variant): it writes `Dockerfile`, `docker-compose.yml`,
|
||||||
|
`.dockerignore`, and appends the Docker recipes to the justfile.
|
||||||
|
4. **Stop. Do not run `jj describe`.** Tell the user:
|
||||||
> "Review with `jj diff`. Then run `just build-dev` → `just up` → `R
|
> "Review with `jj diff`. Then run `just build-dev` → `just up` → `R
|
||||||
> -e 'renv::init()'` to lock dependencies; then `just document` and
|
> -e 'renv::init()'` to lock dependencies; then `just document` and
|
||||||
> `just check`. Describe the change with
|
> `just check`. Describe the change with
|
||||||
> [`/jj-atomic`](../../productivity/jj-atomic/SKILL.md) when satisfied."
|
> [`/jj-atomic`](../../productivity/jj-atomic/SKILL.md) when satisfied."
|
||||||
4. **Suggest** `/write-readme-py`'s R counterpart once it exists (not
|
5. **Suggest** `/write-readme-py`'s R counterpart once it exists (not
|
||||||
yet — see octobot/README.md *Out of scope*).
|
yet — see octobot/README.md *Out of scope*).
|
||||||
|
|
||||||
## Placeholders used by templates
|
## Placeholders used by templates
|
||||||
@ -57,8 +59,8 @@ description: Scaffold a new R package with renv for dependency management, a thr
|
|||||||
invent stub functions.
|
invent stub functions.
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
- [`../../_concepts/three-stage-dockerfile.md`](../../_concepts/three-stage-dockerfile.md)
|
- [`../containerize-project/SKILL.md`](../containerize-project/SKILL.md)
|
||||||
— rationale for `Dockerfile.tpl`.
|
— owns the Docker templates and the three-stage pattern rationale.
|
||||||
- [`../../engineering/dev-r/SKILL.md`](../../engineering/dev-r/SKILL.md)
|
- [`../../engineering/dev-r/SKILL.md`](../../engineering/dev-r/SKILL.md)
|
||||||
— workflow auto-detects DESCRIPTION → R-package loop.
|
— workflow auto-detects DESCRIPTION → R-package loop.
|
||||||
- [`../../engineering/r-style/SKILL.md`](../../engineering/r-style/SKILL.md)
|
- [`../../engineering/r-style/SKILL.md`](../../engineering/r-style/SKILL.md)
|
||||||
|
|||||||
@ -6,21 +6,8 @@ set dotenv-load := false
|
|||||||
default:
|
default:
|
||||||
@just --list
|
@just --list
|
||||||
|
|
||||||
# ── Docker ──────────────────────────────────────────────────────────────
|
# Docker recipes (build-dev, up, down, …) are appended by
|
||||||
build-dev:
|
# /containerize-project from its justfile-docker.tpl.
|
||||||
docker compose build dev
|
|
||||||
|
|
||||||
build-prod:
|
|
||||||
docker compose build production
|
|
||||||
|
|
||||||
up:
|
|
||||||
docker compose run --rm dev bash
|
|
||||||
|
|
||||||
down:
|
|
||||||
docker compose down
|
|
||||||
|
|
||||||
rebuild:
|
|
||||||
docker compose build --no-cache dev
|
|
||||||
|
|
||||||
# ── Documentation ───────────────────────────────────────────────────────
|
# ── Documentation ───────────────────────────────────────────────────────
|
||||||
document:
|
document:
|
||||||
|
|||||||
@ -1,16 +1,15 @@
|
|||||||
FROM python:3.11-slim AS base
|
FROM python:3.11-slim AS base
|
||||||
|
|
||||||
|
# Pinned uv binary — bump the tag deliberately, never use :latest.
|
||||||
|
COPY --from=ghcr.io/astral-sh/uv:0.7 /uv /uvx /usr/local/bin/
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
build-essential \
|
build-essential \
|
||||||
git \
|
git \
|
||||||
curl \
|
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
&& rm -rf /var/lib/apt/lists/* \
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
&& mkdir /usr/<package_name>
|
&& mkdir /usr/<package_name>
|
||||||
|
|
||||||
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
||||||
ENV PATH="/root/.local/bin:$PATH"
|
|
||||||
|
|
||||||
WORKDIR /usr/<package_name>
|
WORKDIR /usr/<package_name>
|
||||||
|
|
||||||
ENV UV_LINK_MODE=copy \
|
ENV UV_LINK_MODE=copy \
|
||||||
@ -30,10 +29,16 @@ COPY . .
|
|||||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||||
uv sync --frozen --no-dev 2>/dev/null || uv sync --no-dev
|
uv sync --frozen --no-dev 2>/dev/null || uv sync --no-dev
|
||||||
|
|
||||||
|
RUN useradd --create-home --shell /usr/sbin/nologin app \
|
||||||
|
&& chown -R app:app /usr/<package_name>
|
||||||
|
USER app
|
||||||
|
|
||||||
ENV PATH="/opt/venv/bin:$PATH"
|
ENV PATH="/opt/venv/bin:$PATH"
|
||||||
CMD ["python", "-c", "import <package_name>; print('<package_name> ready')"]
|
CMD ["python", "-c", "import <package_name>; print('<package_name> ready')"]
|
||||||
|
|
||||||
# ── development ────────────────────────────────────────────────────────
|
# ── development ────────────────────────────────────────────────────────
|
||||||
|
# Runs as root deliberately: the dev service bind-mounts the source tree
|
||||||
|
# and installs packages interactively; a non-root user fights both.
|
||||||
FROM base AS development
|
FROM base AS development
|
||||||
|
|
||||||
COPY pyproject.toml uv.lock* ./
|
COPY pyproject.toml uv.lock* ./
|
||||||
@ -22,9 +22,16 @@ RUN R -e "renv::restore()"
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
# tar_make() writes _targets/, so the workdir must be writable by app.
|
||||||
|
RUN useradd --create-home --shell /usr/sbin/nologin app \
|
||||||
|
&& chown -R app:app /usr/<project-name>
|
||||||
|
USER app
|
||||||
|
|
||||||
CMD ["R", "--vanilla", "-e", "targets::tar_make()"]
|
CMD ["R", "--vanilla", "-e", "targets::tar_make()"]
|
||||||
|
|
||||||
# ── development ────────────────────────────────────────────────────────
|
# ── development ────────────────────────────────────────────────────────
|
||||||
|
# Runs as root deliberately: the dev service bind-mounts the source tree
|
||||||
|
# and installs packages interactively; a non-root user fights both.
|
||||||
FROM base AS development
|
FROM base AS development
|
||||||
|
|
||||||
COPY renv.lock renv.lock
|
COPY renv.lock renv.lock
|
||||||
@ -25,10 +25,16 @@ RUN R -e "renv::restore()"
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
RUN useradd --create-home --shell /usr/sbin/nologin app \
|
||||||
|
&& chown -R app:app /usr/<package-name>
|
||||||
|
USER app
|
||||||
|
|
||||||
CMD ["R", "--vanilla", "-e", \
|
CMD ["R", "--vanilla", "-e", \
|
||||||
"pkgload::load_all(); cat('<package-name> ready\\n')"]
|
"pkgload::load_all(); cat('<package-name> ready\\n')"]
|
||||||
|
|
||||||
# ── development ────────────────────────────────────────────────────────
|
# ── development ────────────────────────────────────────────────────────
|
||||||
|
# Runs as root deliberately: the dev service bind-mounts the source tree
|
||||||
|
# and installs packages interactively; a non-root user fights both.
|
||||||
FROM base AS development
|
FROM base AS development
|
||||||
|
|
||||||
COPY renv.lock renv.lock
|
COPY renv.lock renv.lock
|
||||||
60
skills/scaffold/containerize-project/SKILL.md
Normal file
60
skills/scaffold/containerize-project/SKILL.md
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
---
|
||||||
|
name: containerize-project
|
||||||
|
description: Add a three-stage Docker setup (base/production/development) to a project — Dockerfile, docker-compose.yml, .dockerignore, and Docker recipes in the justfile. Detects the ecosystem from marker files (pyproject.toml → uv on python-slim; DESCRIPTION → renv on rocker/r-ver; _targets.R → renv on rocker/verse). Hardened defaults: non-root production user, pinned package-manager install, no source mount in the production service. Materialises files and stops on `jj diff` for review before any commit. Use when the user says "containerize", "dockerize", "add docker", "/containerize-project", or a scaffold skill (build-py-project, build-r-package, build-r-analysis) delegates Docker setup here.
|
||||||
|
---
|
||||||
|
|
||||||
|
# containerize-project
|
||||||
|
|
||||||
|
## When to use
|
||||||
|
- User says "containerize", "dockerize", "add docker", "/containerize-project".
|
||||||
|
- A `build-*` scaffold skill reaches its Docker step and delegates here.
|
||||||
|
- An existing uv or renv project needs the standard three-stage setup.
|
||||||
|
|
||||||
|
## Process
|
||||||
|
|
||||||
|
1. **Detect ecosystem** (in this order; ask if none or several match):
|
||||||
|
| Marker | Variant | Templates |
|
||||||
|
|---|---|---|
|
||||||
|
| `pyproject.toml` | python | `Dockerfile.python.tpl`, `docker-compose.python.yml.tpl`, `dockerignore.python.tpl` |
|
||||||
|
| `DESCRIPTION` | r-package | `Dockerfile.r-package.tpl`, `docker-compose.r.yml.tpl`, `dockerignore.r.tpl` |
|
||||||
|
| `_targets.R` | r-analysis | `Dockerfile.r-analysis.tpl`, `docker-compose.r.yml.tpl`, `dockerignore.r.tpl` |
|
||||||
|
2. **Materialise** with placeholder substitution:
|
||||||
|
- `Dockerfile` ← variant Dockerfile template
|
||||||
|
- `docker-compose.yml` ← variant compose template
|
||||||
|
- `.dockerignore` ← variant dockerignore template
|
||||||
|
3. **Justfile recipes** from `justfile-docker.tpl`:
|
||||||
|
- No `justfile` → create one with the standard header
|
||||||
|
(`set dotenv-load := false`, `default: @just --list`) plus the
|
||||||
|
Docker section.
|
||||||
|
- `justfile` exists without a `build-dev` recipe → append the
|
||||||
|
Docker section.
|
||||||
|
- `build-dev` already present → leave the justfile alone.
|
||||||
|
4. **Stop. Do not run `jj describe`.** Tell the user:
|
||||||
|
> "Review with `jj diff`. Then `just build-dev` to verify the
|
||||||
|
> toolchain. Describe with `/jj-atomic` when satisfied."
|
||||||
|
|
||||||
|
## Placeholders
|
||||||
|
- python: `<project-name>` (kebab-case), `<package_name>` (snake_case).
|
||||||
|
- r-package: `<package-name>`.
|
||||||
|
- r-analysis: `<project-name>` (snake_case).
|
||||||
|
|
||||||
|
## Guardrails
|
||||||
|
- **Never** overwrite an existing `Dockerfile`, `docker-compose.yml`, or
|
||||||
|
`.dockerignore` without explicit confirmation — show a diff first.
|
||||||
|
- **Never** put credentials in `ENV`, `ARG`, or `COPY`-ed files — that's
|
||||||
|
[`add-docker-secrets`](../add-docker-secrets/SKILL.md) territory.
|
||||||
|
- **Never** add a source mount to the production service — it overrides
|
||||||
|
the baked image and defeats immutability.
|
||||||
|
- The development stage runs as root deliberately (bind mounts +
|
||||||
|
interactive installs); production runs as `app`. Don't "fix" either.
|
||||||
|
- Keep the pinned uv image tag; never switch to `:latest`.
|
||||||
|
|
||||||
|
## See also
|
||||||
|
- [three-stage-dockerfile.md](three-stage-dockerfile.md) — rationale for
|
||||||
|
the base/production/development pattern, caveats, anti-patterns.
|
||||||
|
- [`../add-docker-secrets/SKILL.md`](../add-docker-secrets/SKILL.md) —
|
||||||
|
build-time and runtime secrets once the project needs credentials.
|
||||||
|
- [`../build-py-project/SKILL.md`](../build-py-project/SKILL.md),
|
||||||
|
[`../build-r-package/SKILL.md`](../build-r-package/SKILL.md),
|
||||||
|
[`../build-r-analysis/SKILL.md`](../build-r-analysis/SKILL.md) —
|
||||||
|
scaffolds that delegate their Docker step here.
|
||||||
@ -8,11 +8,10 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- .:/usr/<package_name>
|
- .:/usr/<package_name>
|
||||||
|
|
||||||
|
# No source mount: production runs the baked image as built.
|
||||||
production:
|
production:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
target: production
|
target: production
|
||||||
container_name: <project-name>-prod
|
container_name: <project-name>-prod
|
||||||
volumes:
|
|
||||||
- .:/usr/<package_name>
|
|
||||||
@ -9,14 +9,13 @@ services:
|
|||||||
- .:/usr/<package-name>
|
- .:/usr/<package-name>
|
||||||
- renv-cache:/root/.cache/R/renv
|
- renv-cache:/root/.cache/R/renv
|
||||||
|
|
||||||
|
# No source mount: production runs the baked image as built.
|
||||||
production:
|
production:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
target: production
|
target: production
|
||||||
container_name: <package-name>-prod
|
container_name: <package-name>-prod
|
||||||
volumes:
|
|
||||||
- .:/usr/<package-name>
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
renv-cache:
|
renv-cache:
|
||||||
17
skills/scaffold/containerize-project/dockerignore.python.tpl
Normal file
17
skills/scaffold/containerize-project/dockerignore.python.tpl
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Keep the build context lean and secrets out of COPY . .
|
||||||
|
.git
|
||||||
|
.jj
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
.venv/
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
.coverage
|
||||||
|
htmlcov/
|
||||||
|
.mypy_cache/
|
||||||
|
.ruff_cache/
|
||||||
|
.pytest_cache/
|
||||||
|
dist/
|
||||||
|
*.egg-info/
|
||||||
|
Dockerfile
|
||||||
|
docker-compose.yml
|
||||||
16
skills/scaffold/containerize-project/dockerignore.r.tpl
Normal file
16
skills/scaffold/containerize-project/dockerignore.r.tpl
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Keep the build context lean and secrets out of COPY . .
|
||||||
|
# Data enters containers via the compose source mount, never the image.
|
||||||
|
.git
|
||||||
|
.jj
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
.Rproj.user
|
||||||
|
.Rhistory
|
||||||
|
.RData
|
||||||
|
renv/library/
|
||||||
|
renv/staging/
|
||||||
|
_targets/
|
||||||
|
data/raw/
|
||||||
|
data/processed/
|
||||||
|
Dockerfile
|
||||||
|
docker-compose.yml
|
||||||
18
skills/scaffold/containerize-project/justfile-docker.tpl
Normal file
18
skills/scaffold/containerize-project/justfile-docker.tpl
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# ── Docker ──────────────────────────────────────────────────────────────
|
||||||
|
build-dev:
|
||||||
|
docker compose build dev
|
||||||
|
|
||||||
|
build-prod:
|
||||||
|
docker compose build production
|
||||||
|
|
||||||
|
up:
|
||||||
|
docker compose run --rm dev bash
|
||||||
|
|
||||||
|
up-prod:
|
||||||
|
docker compose run --rm production
|
||||||
|
|
||||||
|
down:
|
||||||
|
docker compose down
|
||||||
|
|
||||||
|
rebuild:
|
||||||
|
docker compose build --no-cache dev
|
||||||
@ -23,6 +23,9 @@ COPY <lock file(s)> ./
|
|||||||
RUN <pkg-mgr> sync --no-dev --frozen
|
RUN <pkg-mgr> sync --no-dev --frozen
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN <pkg-mgr> sync --no-dev --frozen # final install
|
RUN <pkg-mgr> sync --no-dev --frozen # final install
|
||||||
|
RUN useradd --create-home --shell /usr/sbin/nologin app \
|
||||||
|
&& chown -R app:app /usr/<project>
|
||||||
|
USER app
|
||||||
CMD ["<runtime>", "<entrypoint>"]
|
CMD ["<runtime>", "<entrypoint>"]
|
||||||
|
|
||||||
# ── development ────────────────────────────────────────────────────────
|
# ── development ────────────────────────────────────────────────────────
|
||||||
@ -48,6 +51,27 @@ the package manager install happen **once**, not twice.
|
|||||||
manager. `docker compose build --target production` and `--target
|
manager. `docker compose build --target production` and `--target
|
||||||
development` produce two distinct images from one file.
|
development` produce two distinct images from one file.
|
||||||
|
|
||||||
|
## Hardening defaults
|
||||||
|
|
||||||
|
- **Non-root production user.** Production creates `app` after the final
|
||||||
|
`COPY` and switches to it; a container escape then lands in an
|
||||||
|
unprivileged process. Development stays root deliberately — the dev
|
||||||
|
service bind-mounts the source tree and installs packages
|
||||||
|
interactively, and a non-root user fights both (UID mismatches on the
|
||||||
|
mount, no write access to the library path).
|
||||||
|
- **`.dockerignore` is mandatory.** Without it, `COPY . .` drags `.git`,
|
||||||
|
`.env`, data directories, and local caches into the image — a secret
|
||||||
|
leak and a cache-bust in one. Ship it with the Dockerfile, always.
|
||||||
|
- **Pin the package-manager install.** `curl | sh` fetches whatever is
|
||||||
|
latest that day; builds stop being reproducible. Copy a pinned binary
|
||||||
|
instead (`COPY --from=ghcr.io/astral-sh/uv:<tag> …`) or install a
|
||||||
|
pinned version.
|
||||||
|
- **No source mount on the production service.** A `.:/usr/<project>`
|
||||||
|
volume on `production` silently overrides the baked image with the
|
||||||
|
working tree — you are no longer running what you built.
|
||||||
|
- **Secrets never enter the Dockerfile.** No `ARG`, no `ENV`, no
|
||||||
|
`COPY`-ed credential files; see `add-docker-secrets`.
|
||||||
|
|
||||||
## docker-compose.yml pairing
|
## docker-compose.yml pairing
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@ -89,6 +113,8 @@ source.
|
|||||||
|
|
||||||
## Used by
|
## Used by
|
||||||
|
|
||||||
- `scaffold/build-py-project` (uv-based)
|
- `scaffold/containerize-project` — owns the templates implementing this
|
||||||
- `scaffold/build-r-analysis` (renv on rocker/verse)
|
pattern (python/uv, r-package/rocker-r-ver, r-analysis/rocker-verse).
|
||||||
- `scaffold/build-r-package` (renv on rocker/r-ver)
|
- `scaffold/build-py-project`, `scaffold/build-r-package`,
|
||||||
|
`scaffold/build-r-analysis` — delegate their Docker step to
|
||||||
|
`containerize-project`.
|
||||||
Loading…
x
Reference in New Issue
Block a user