Skip to content

Commit 0648c6f

Browse files
committed
Best practices
1 parent eb08e9b commit 0648c6f

File tree

6 files changed

+186
-18
lines changed

6 files changed

+186
-18
lines changed

docs/.vitepress/config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default {
5252
{ text: 'Networks', link: '/manifest/networks' },
5353
{ text: 'Filesets', link: '/manifest/filesets' },
5454
{ text: 'Applications', link: '/manifest/applications' },
55-
{ text: 'Good Practices', link: '/manifest/good_practices' }
55+
{ text: 'Best Practices', link: '/manifest/best_practices' }
5656
]
5757
},
5858
...cliSidebar

docs/introduction/getting_started.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Before you begin, make sure you have the following installed:
2020

2121
On macOS or Linux, you can install Dockform using [Homebrew](https://brew.sh/):
2222

23-
```sh
24-
brew tap gcstr/dockform
25-
brew install dockform
23+
```sh [terminal ~vscode-icons:file-type-shell~]
24+
$ brew tap gcstr/dockform
25+
$ brew install dockform
2626
```
2727

2828
### Precompiled binaries
@@ -36,7 +36,7 @@ Download the binary for your platform, extract it, and place it somewhere in you
3636

3737
Dockform includes a convenience command to scaffold a new project:
3838

39-
```sh
39+
```sh [terminal ~vscode-icons:file-type-shell~]
4040
dockform init
4141
```
4242

docs/manifest/applications.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ applications:
5050
- `profiles` (optional): Compose profiles to enable.
5151
- `env-file` (optional): additional env files for Compose (relative to `root`).
5252
- `environment` (optional): per-app env definitions, with `files` and `inline`.
53-
- `secrets.sops` (optional): per-app SOPS-encrypted `.env` files for inline injection at runtime.
53+
- `secrets.sops` (optional): per-app SOPS-encrypted `.env` files for inline injection at runtime. *(See [Secrets](secrets))*
5454
- `project.name` (optional): Compose project name override.
5555

5656
## Environment merging and precedence

docs/manifest/best_practices.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: Best Practices
3+
---
4+
5+
# Best Practices
6+
7+
This guide collects practical recommendations for using Dockform safely and effectively across development, staging, and production.
8+
9+
## Core principles
10+
11+
- Treat the manifest file as *the* source of truth; avoid imperative Docker commands.
12+
- Scope everything with a clear `docker.identifier` (e.g., `server-name`).
13+
- Prefer small, focused changes and review with `dockform plan` before `apply`.
14+
15+
## Volumes
16+
17+
- Declare named volumes in the manifest under `volumes:` and reference them as `external` in Compose. ***Avoid defining named volumes directly in Compose***.
18+
- Back up volumes regularly. Dockform’s `destroy` (and `prune`) can remove labeled volumes. Consider a backup solution like [docker-volume-backup](https://offen.github.io/docker-volume-backup/).
19+
- If a fileset targets a volume, you may omit it from `volumes:` (it will be created), but listing it explicitly improves readability.
20+
21+
## Networks
22+
23+
- Declare networks in the manifest and reference them as `external` in Compose. Avoid creating ad-hoc networks via Compose.
24+
- Use environment-specific names if you need strict isolation per environment.
25+
26+
## Filesets
27+
28+
- Use filesets for configs and static assets (not for very large, frequently-changing data).
29+
- Keep `target_path` specific (never `/`), and use `exclude` to avoid syncing build artifacts, VCS metadata, and OS files.
30+
- Set `restart_services` only for services that actually need a restart.
31+
32+
Example excludes:
33+
34+
```yaml [dockform.yaml]
35+
filesets:
36+
app-config:
37+
source: ./config
38+
target_volume: app-config
39+
target_path: /etc/app
40+
exclude:
41+
- ".git/"
42+
- "**/*.tmp"
43+
- "**/.DS_Store"
44+
```
45+
46+
## Applications and Compose
47+
48+
- Set a stable `project.name` for predictable container and network names. See https://docs.docker.com/compose/how-tos/project-name/
49+
- Keep Compose files close to each app’s `root` folder; avoid cross-tree paths.
50+
- Use Compose profiles for environment-specific toggles (e.g., `prod` vs `dev`).
51+
- Let Dockform inject its identifier label; do not hardcode `io.dockform.identifier` in Compose.
52+
53+
## Environment and secrets
54+
55+
- Use root `environment.files` for shared files and app-level `environment.files` for overrides; Dockform rebases root paths to the app `root`.
56+
- Prefer SOPS-encrypted `.env` files for secrets. Keep keys outside of the repo and load via `${AGE_KEY_FILE}`.
57+
- If not using SOPS, inject secrets via CI as environment variables and pass them through Compose `environment:`.
58+
59+
<!-- ## CI/CD recommendations
60+
61+
- Use `dockform plan` in PRs to preview changes; require approval before `apply`.
62+
- Pin the Docker context and set a clear `docker.identifier` per environment.
63+
- Provide required env vars (including SOPS keys if used) via CI secrets.
64+
- For ephemeral tests, set `DOCKFORM_RUN_ID` to isolate resources, then run `dockform destroy` or `prune` at the end. -->
65+
66+
## Safety and destructive operations
67+
68+
Always ensure you have recent backups for stateful volumes before destructive commands.
69+
70+
::: warning
71+
72+
`destroy` removes all labeled resources for the active identifier (containers, networks, volumes). Use with care.
73+
74+
:::
75+
76+
## Performance and determinism
77+
78+
- Limit fileset sizes and use `exclude` aggressively for large repos.
79+
- Keep Compose and manifest changes minimal per deployment for faster diffs.
80+
- Prefer stable project and resource names to minimize churn and restarts.
81+
82+
## Suggested project structure
83+
84+
- Dockform is unopinionated, but grouping applications by folder is effective.
85+
86+
```text
87+
repo/
88+
dockform.yaml
89+
traefik/
90+
docker-compose.yaml
91+
config/
92+
app/
93+
docker-compose.yaml
94+
.env
95+
db/
96+
docker-compose.yaml
97+
```
98+
99+
## Troubleshooting tips
100+
101+
- If Compose fails, run `docker compose -f <file> config` to validate YAML.
102+
- If a service doesn’t update, check labels and config-hash drift; then run `dockform plan`.
103+
- If a volume/network is “missing” in Compose, ensure it is declared in the manifest and referenced as `external` with the correct name.
104+

docs/manifest/good_practices.md

Whitespace-only changes.

docs/manifest/secrets.md

Lines changed: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ You need both **SOPS** and **Age** installed:
2222

2323
Generate a new Age key pair and store it locally:
2424

25-
```sh
25+
```sh [terminal ~vscode-icons:file-type-shell~]
2626
$ age-keygen -o ~/.config/sops/age/keys.txt
2727
```
2828

2929
### 2. Reference the key file in the manifest
3030

3131
Point Dockform to your Age key file inside `dockform.yaml` (directly or via environment variable interpolation):
3232

33-
```yaml
33+
```yaml [dockform.yaml]
3434
sops:
3535
age:
3636
key_file: ${AGE_KEY_FILE}
@@ -40,7 +40,7 @@ sops:
4040
4141
Use Dockform to scaffold a new secrets file:
4242
43-
```sh
43+
```sh [terminal ~vscode-icons:file-type-shell~]
4444
$ dockform secrets create secrets.env
4545
# A template encrypted dotenv file will be created
4646
```
@@ -49,7 +49,7 @@ $ dockform secrets create secrets.env
4949

5050
Open the file securely with your `$EDITOR`. Dockform decrypts it on the fly and re-encrypts on save:
5151

52-
```sh
52+
```sh [terminal ~vscode-icons:file-type-shell~]
5353
$ dockform secrets edit secrets.env
5454
```
5555

@@ -58,28 +58,92 @@ $ dockform secrets edit secrets.env
5858
Reference the encrypted dotenv file inside your manifest.
5959
Secrets can be defined globally or scoped to a specific application.
6060

61-
```yaml
61+
```yaml [dockform.yaml]
6262
secrets:
6363
sops:
6464
- app/secrets.env
6565
```
6666
6767
For application-specific secrets:
6868
69-
```yaml
69+
```yaml [dockform.yaml]
7070
applications:
7171
web:
7272
secrets:
7373
sops:
7474
- web/secrets.env
7575
```
7676
77-
---
77+
## Using secrets without SOPS (CI-managed)
78+
79+
If you prefer not to use SOPS, you can manage sensitive values via your CI/CD system’s secret store (e.g., GitHub Actions). Provide secrets as environment variables at runtime and reference them from Compose or the manifest.
80+
81+
- Set CI environment variables from your secret store.
82+
- Add them to Dockform `environment.inline` to ensure Compose receives them during planning and apply.
83+
84+
::: code-group
85+
86+
```yaml [dockform.yaml]
87+
docker:
88+
context: default
89+
identifier: production
90+
91+
environment:
92+
inline:
93+
# These values are interpolated from CI-provided env vars at load time
94+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
95+
- OIDC_CLIENT_SECRET=${OIDC_CLIENT_SECRET}
7896
79-
## Summary
97+
applications:
98+
app:
99+
root: ./app
100+
files: [docker-compose.yaml]
101+
```
102+
103+
```yaml [app/docker-compose.yaml]
104+
services:
105+
api:
106+
image: ghcr.io/example/api:latest
107+
environment:
108+
# Compose reads values from the process environment (provided by CI or Dockform inline env)
109+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
110+
OIDC_CLIENT_SECRET: ${OIDC_CLIENT_SECRET}
111+
```
112+
113+
```yaml [ .github/workflows/deploy.yml ]
114+
name: Deploy
115+
on:
116+
workflow_dispatch:
117+
push:
118+
branches: [ main ]
119+
120+
jobs:
121+
deploy:
122+
runs-on: ubuntu-latest
123+
env:
124+
# Provide secrets from GitHub Actions to the process environment
125+
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
126+
OIDC_CLIENT_SECRET: ${{ secrets.OIDC_CLIENT_SECRET }}
127+
# Optional: set a stable run identifier for scoping
128+
DOCKFORM_RUN_ID: production
129+
steps:
130+
- uses: actions/checkout@v4
131+
132+
- name: Install Dockform
133+
run: |
134+
curl -L https://github.com/gcstr/dockform/releases/latest/download/dockform_linux_amd64 -o dockform
135+
chmod +x dockform
136+
sudo mv dockform /usr/local/bin/dockform
137+
138+
- name: Plan
139+
run: dockform plan -c .
140+
141+
- name: Apply
142+
run: dockform apply -c .
143+
```
80144

81-
- Secrets are stored in encrypted dotenv files managed by SOPS.
82-
- Age provides the encryption keys.
83-
- Dockform offers commands to create and edit secrets without exposing raw values.
84-
- Encrypted files can safely live in git repositories, while being decrypted only at runtime.
145+
:::
85146

147+
Notes:
148+
- Environment variable interpolation (`${VAR}`) in `dockform.yaml` occurs at load time using the runner’s environment.
149+
- You can mix CI-managed env vars with SOPS-managed secrets if needed.

0 commit comments

Comments
 (0)