1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
|
# Container Registry Infrastructure
Local container registry for Yocto/OE builds - analogous to package-index for containers.
## Quick Start
```bash
# 1. Configure in local.conf
CONTAINER_REGISTRY_URL = "localhost:5000"
CONTAINER_REGISTRY_NAMESPACE = "yocto"
CONTAINER_REGISTRY_INSECURE = "1"
# 2. Generate the helper script
bitbake container-registry-index -c generate_registry_script
# 3. Start registry, push images
$TOPDIR/container-registry/container-registry.sh start
$TOPDIR/container-registry/container-registry.sh push
# 4. Import 3rd party images
$TOPDIR/container-registry/container-registry.sh import docker.io/library/alpine:latest
# 5. Use with vdkr (10.0.2.2 is QEMU slirp gateway to localhost)
vdkr vconfig registry 10.0.2.2:5000/yocto
vdkr pull container-base
```
## Helper Script Commands
Script location: `${TOPDIR}/container-registry/container-registry.sh` (outside tmp/, persists)
| Command | Description |
|---------|-------------|
| `start` | Start the container registry server |
| `stop` | Stop the container registry server |
| `status` | Check if registry is running |
| `push [image] [options]` | Push OCI images from deploy/ to registry |
| `import <image> [name]` | Import 3rd party image to registry |
| `delete <image>:<tag>` | Delete a tagged image from registry |
| `gc` | Garbage collect unreferenced blobs |
| `list` | List all images with their tags |
| `tags <image>` | List tags for a specific image |
| `catalog` | Raw API catalog output |
### Push Options
```bash
# Explicit tags (require image name)
container-registry.sh push container-base --tag v1.0.0
container-registry.sh push container-base --tag latest --tag v1.0.0
# Strategy-based (see Tag Strategies below)
container-registry.sh push --strategy "sha branch latest"
container-registry.sh push --strategy semver --version 1.2.3
# Environment variable override
CONTAINER_REGISTRY_TAG_STRATEGY="sha latest" container-registry.sh push
```
## Tag Strategies
Configure tag generation via `CONTAINER_REGISTRY_TAG_STRATEGY` (space-separated):
| Strategy | Output | Description |
|----------|--------|-------------|
| `timestamp` | `20260112-143022` | Build timestamp |
| `sha` / `git` | `8a3f2b1` | Short git commit hash |
| `branch` | `main`, `feature-login` | Git branch name (sanitized) |
| `semver` | `1.2.3`, `1.2`, `1` | Nested SemVer from PV |
| `version` | `1.2.3` | Single version tag |
| `latest` | `latest` | The "latest" tag |
| `arch` | `*-x86_64` | Append architecture suffix |
### Example Workflows
**Development builds** (track code changes):
```bitbake
CONTAINER_REGISTRY_TAG_STRATEGY = "sha branch latest"
```
Result: `my-app:8a3f2b1`, `my-app:feature-login`, `my-app:latest`
**Release builds** (semantic versioning):
```bitbake
CONTAINER_REGISTRY_TAG_STRATEGY = "semver latest"
PV = "1.2.3"
```
Result: `my-app:1.2.3`, `my-app:1.2`, `my-app:1`, `my-app:latest`
**CI/CD** (traceability):
```bash
IMAGE_VERSION=1.2.3 container-registry.sh push --strategy "semver sha latest"
```
## Development Loop
The default strategy (`timestamp latest`) supports a simple development workflow:
```bash
# Build
bitbake container-base
# Push (creates both timestamp tag AND :latest)
./container-registry/container-registry.sh push
# Pull on target - :latest is implicit, gets your most recent push
vdkr pull container-base
# Test
vdkr run container-base /bin/sh
# Repeat: rebuild, push, pull - no tag hunting needed
```
Each push overwrites `:latest` with your newest build. The timestamp tags (`20260112-143022`) remain for rollback/debugging.
## Build-Time OCI Labels
Container images automatically include standard OCI traceability labels:
```bash
$ skopeo inspect oci:container-base-oci | jq '.Labels'
{
"org.opencontainers.image.revision": "8a3f2b1",
"org.opencontainers.image.ref.name": "master",
"org.opencontainers.image.created": "2026-01-12T20:32:24Z"
}
```
| Label | Source | Description |
|-------|--------|-------------|
| `org.opencontainers.image.revision` | git SHA from TOPDIR | Code traceability |
| `org.opencontainers.image.ref.name` | git branch from TOPDIR | Branch tracking |
| `org.opencontainers.image.created` | Build timestamp | When image was built |
| `org.opencontainers.image.version` | PV (if set) | Semantic version |
### Customizing Labels
```bitbake
# In local.conf or image recipe
# Explicit override (e.g., from CI/CD)
OCI_IMAGE_REVISION = "${CI_COMMIT_SHA}"
OCI_IMAGE_BRANCH = "${CI_BRANCH}"
# Disable specific label
OCI_IMAGE_REVISION = "none"
# Disable all auto-labels
OCI_IMAGE_AUTO_LABELS = "0"
```
## Configuration (local.conf)
```bitbake
# Registry endpoint (host-side)
CONTAINER_REGISTRY_URL = "localhost:5000"
# Image namespace
CONTAINER_REGISTRY_NAMESPACE = "yocto"
# Mark as insecure (HTTP)
CONTAINER_REGISTRY_INSECURE = "1"
# Tag strategy (default: "timestamp latest")
CONTAINER_REGISTRY_TAG_STRATEGY = "sha branch latest"
# For Docker targets
DOCKER_REGISTRY_INSECURE = "localhost:5000"
# Persistent storage (default: ${TOPDIR}/container-registry)
CONTAINER_REGISTRY_STORAGE = "/data/container-registry"
```
## Authentication
Support for pushing to authenticated registries (Docker Hub, GitHub Container Registry, private registries).
### Authentication Modes
| Mode | BitBake | Script | Description |
|------|---------|--------|-------------|
| `none` | Yes | Yes | No authentication (default, local registries) |
| `home` | Yes | Yes | Use `~/.docker/config.json` (opt-in) |
| `authfile` | Yes | Yes | Explicit Docker-style config.json path |
| `credsfile` | Yes | Yes | Simple key=value credentials file |
| `env` | No | Yes | Environment variables (script only) |
### BitBake Configuration
```bitbake
# Authentication mode
CONTAINER_REGISTRY_AUTH_MODE = "none" # Default, no auth
CONTAINER_REGISTRY_AUTH_MODE = "home" # Use ~/.docker/config.json
CONTAINER_REGISTRY_AUTH_MODE = "authfile" # Explicit auth file
CONTAINER_REGISTRY_AUTH_MODE = "credsfile" # Simple credentials file
# For authfile mode
CONTAINER_REGISTRY_AUTHFILE = "/path/to/docker-config.json"
# For credsfile mode
CONTAINER_REGISTRY_CREDSFILE = "${HOME}/.config/container-registry/credentials"
```
### Script Options
```bash
# Use existing Docker login (~/.docker/config.json)
container-registry.sh push --use-home-auth
# Explicit auth file
container-registry.sh push --authfile /path/to/docker-config.json
# Simple credentials file
container-registry.sh push --credsfile ~/.config/container-registry/credentials
# Environment variables
export CONTAINER_REGISTRY_AUTH_MODE=env
export CONTAINER_REGISTRY_TOKEN=ghp_xxxxx
container-registry.sh push
# Direct credentials (less secure - in shell history)
container-registry.sh push --creds user:password
container-registry.sh push --token ghp_xxxxx
# Import from authenticated source registry
container-registry.sh import ghcr.io/org/private:v1 --src-authfile ~/.docker/config.json
container-registry.sh import ghcr.io/org/private:v1 --src-credsfile ~/.config/ghcr-creds
```
### Credentials File Format
Simple key=value format (not checked into source control):
```bash
# ~/.config/container-registry/credentials
# Username/password OR token (token takes precedence)
CONTAINER_REGISTRY_USER=myuser
CONTAINER_REGISTRY_PASSWORD=mypassword
# Or for token-based auth (GitHub, GitLab, etc.):
CONTAINER_REGISTRY_TOKEN=ghp_xxxxxxxxxxxx
```
Create with proper permissions:
```bash
mkdir -p ~/.config/container-registry
cat > ~/.config/container-registry/credentials << 'EOF'
CONTAINER_REGISTRY_TOKEN=ghp_xxxxxxxxxxxx
EOF
chmod 600 ~/.config/container-registry/credentials
```
### CI/CD Integration
For CI/CD with BitBake, use `credsfile` mode and have CI write the credentials file:
```yaml
# Example GitHub Actions
- name: Setup registry credentials
run: |
mkdir -p ~/.config/container-registry
echo "CONTAINER_REGISTRY_TOKEN=${{ secrets.GHCR_TOKEN }}" > ~/.config/container-registry/credentials
chmod 600 ~/.config/container-registry/credentials
- name: Build and push
run: |
bitbake container-base
./container-registry/container-registry.sh push --credsfile ~/.config/container-registry/credentials
```
For script-only usage, environment variables are simpler:
```yaml
- name: Push to registry
env:
CONTAINER_REGISTRY_AUTH_MODE: env
CONTAINER_REGISTRY_TOKEN: ${{ secrets.GHCR_TOKEN }}
run: ./container-registry/container-registry.sh push
```
### Security Notes
- **No credentials in BitBake variables**: Like git fetcher, avoid passwords in metadata that gets logged/shared
- **Use file-based auth**: Credentials files can be excluded from version control and have proper permissions
- **Opt-in for home directory**: `home` mode requires explicit opt-in (like `BB_USE_HOME_NPMRC`)
- **Prefer tokens over passwords**: Tokens can be scoped and revoked
## Secure Registry Mode
Enable TLS and authentication for the local registry (opt-in).
### Configuration
```bitbake
# Enable secure mode
CONTAINER_REGISTRY_SECURE = "1"
# Optional: custom username (default: yocto)
CONTAINER_REGISTRY_USERNAME = "myuser"
# Optional: explicit password (default: auto-generate)
CONTAINER_REGISTRY_PASSWORD = "mypassword"
# Optional: certificate validity (days)
CONTAINER_REGISTRY_CERT_DAYS = "365" # Server cert
CONTAINER_REGISTRY_CA_DAYS = "3650" # CA cert (10 years)
# Optional: additional SAN entries for server cert
CONTAINER_REGISTRY_CERT_SAN = "DNS:myhost.local,IP:192.168.1.100"
```
### Setup
PKI (CA and server certificates) is auto-generated during the bitbake build:
```bash
# Generate script AND PKI infrastructure
bitbake container-registry-index -c generate_registry_script
# Build target image (CA cert is automatically baked in)
bitbake container-image-host
```
The `generate_registry_script` task automatically generates the PKI if it doesn't exist. No manual steps required.
### Starting the Registry
To actually run the registry (for pushing/pulling images):
```bash
# Start registry (generates htpasswd auth on first run)
./container-registry/container-registry.sh start
```
Output:
```
Setting up authentication...
Password saved to: .../auth/password
Starting SECURE container registry...
URL: https://localhost:5000
```
### Generated Files
```
${CONTAINER_REGISTRY_STORAGE}/
├── pki/ # Generated by: bitbake ... -c generate_registry_script
│ ├── ca.key # CA private key (600)
│ ├── ca.crt # CA certificate - baked into target images
│ ├── server.key # Server private key (600)
│ └── server.crt # Server certificate with SAN
├── auth/ # Generated by: container-registry.sh start
│ ├── htpasswd # Bcrypt credentials for registry
│ └── password # Plaintext password for reference (600)
└── ...
```
### Push (auto-uses credentials)
```bash
./container-registry/container-registry.sh push
# Automatically uses:
# --dest-cert-dir=.../pki
# --dest-creds=yocto:<auto-password>
```
### Target Integration
Install CA certificate on target images:
```bitbake
# Automatically included when CONTAINER_REGISTRY_SECURE = "1"
# and IMAGE_FEATURES:append = " container-registry"
IMAGE_INSTALL:append = " container-registry-ca"
```
This installs CA cert to:
- `/etc/docker/certs.d/{registry}/ca.crt` (Docker)
- `/etc/containers/certs.d/{registry}/ca.crt` (Podman/CRI-O)
- `/usr/local/share/ca-certificates/container-registry-ca.crt` (system)
### vdkr with Secure Registry
```bash
# Pass secure mode and CA cert to VM
vdkr --secure-registry --ca-cert $STORAGE/pki/ca.crt pull myimage
# Or with credentials
vdkr --secure-registry --ca-cert $STORAGE/pki/ca.crt \
--registry-user yocto --registry-password mypass pull myimage
```
### Verification
```bash
# Verify TLS with curl
curl --cacert $STORAGE/pki/ca.crt \
-u yocto:$(cat $STORAGE/auth/password) \
https://localhost:5000/v2/_catalog
# Check server certificate SAN
openssl x509 -in $STORAGE/pki/server.crt -noout -text | grep -A1 "Subject Alternative Name"
```
### Secure Mode vs Insecure Mode
| Feature | Insecure (`SECURE=0`) | Secure (`SECURE=1`) |
|---------|----------------------|---------------------|
| Protocol | HTTP | HTTPS |
| TLS | None | Self-signed CA + server cert |
| Auth | Optional | Required (htpasswd) |
| Target config | `insecure-registries` | CA cert distribution |
| Skopeo args | `--dest-tls-verify=false` | `--dest-cert-dir` |
## vdkr Registry Usage
### Pull Behavior with Registry Fallback
When a registry is configured, vdkr uses **registry-first, Docker Hub fallback** for pulls:
1. Try configured registry first (e.g., `10.0.2.2:5000/yocto/alpine`)
2. If not found, fall back to Docker Hub (`docker.io/library/alpine`)
This allows you to override images with local builds while still pulling public images normally.
```bash
# One-off
vdkr --registry 10.0.2.2:5000/yocto pull alpine
# Persistent config
vdkr vconfig registry 10.0.2.2:5000/yocto
vdkr pull alpine # Tries registry first, falls back to Docker Hub
vdkr pull container-base # Pulls from registry (your Yocto-built image)
vdkr run alpine echo hello
# Clear config
vdkr vconfig registry --reset
# Image management (all commands use registry prefix for stored images)
vdkr image ls
vdkr image inspect alpine # Works for both registry and Docker Hub images
vdkr image rm <image>
vdkr image rm e7b39c54cdec # Image IDs work without transformation
```
### Registry Transform
When a registry is configured:
- `pull`, `run` - Use fallback (registry first, then Docker Hub)
- `inspect`, `history`, `rmi`, `tag`, `images` - No transform (use actual local image names)
- Image IDs (hex strings like `e7b39c54cdec`) - Never transformed
## Baking Registry Config into Target Images
Use `IMAGE_FEATURES` to auto-select the right package based on `CONTAINER_PROFILE`:
```bitbake
# In local.conf
CONTAINER_REGISTRY_URL = "localhost:5000"
CONTAINER_REGISTRY_INSECURE = "1"
DOCKER_REGISTRY_INSECURE = "localhost:5000"
# Enable the feature
IMAGE_FEATURES:append = " container-registry"
```
This installs:
- **Docker profile** → `docker-registry-config` → `/etc/docker/daemon.json`
- **Podman profile** → `container-oci-registry-config` → `/etc/containers/registries.conf.d/`
## Files
| File | Description |
|------|-------------|
| `container-registry-index.bb` | Generates helper script with baked-in paths |
| `container-registry-ca.bb` | Target package for CA certificate (secure mode) |
| `container-oci-registry-config.bb` | OCI tools config (Podman/Skopeo/Buildah/CRI-O) |
| `docker-registry-config.bb` | Docker daemon config |
| `files/container-registry-dev.yml` | Development registry config (HTTP) |
| `files/container-registry-secure.yml` | Secure registry config template (HTTPS+auth) |
## Storage
Registry data and script are stored at `${TOPDIR}/container-registry/` by default:
- Outside tmp/, persists across builds and cleanall
- Imported and pushed images are copied here
- Script regenerates with same paths after tmp/ cleanup
## Localhost to 10.0.2.2 Translation
For vdkr baked configs, `localhost` URLs are auto-translated to `10.0.2.2` (QEMU slirp gateway):
- Set `CONTAINER_REGISTRY_URL = "localhost:5000"` in local.conf
- Host-side operations use localhost directly
- vdkr inside QEMU accesses via 10.0.2.2 automatically
|