Skip to content

Commit 4fb1873

Browse files
committed
Add Docker registry mirror support for kdevops workflows
Add local Docker image caching support through a registry mirror at /mirror/docker/ This is similar to how git repositories are mirrored. The mirror acts as a pull-through cache for Docker Hub, significantly speeding up container deployments and enabling offline operation. When the mirror is detected, workflows should automatically rewrite the image URLs in Kconfig to use the local registry at localhost:5000. Docker dependencies are installed per-distro. Systemd timers update images daily at 2 AM to handle nightly builds and latest tags. Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 06dd46a commit 4fb1873

22 files changed

+1594
-1
lines changed

Makefile.linux-mirror

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,44 @@ mirror-status: $(KDEVOPS_EXTRA_VARS)
4343

4444
PHONY += mirror-status
4545

46+
docker-mirror: docker-mirror-setup
47+
48+
PHONY += docker-mirror
49+
50+
docker-mirror-setup: $(KDEVOPS_EXTRA_VARS)
51+
$(Q)ansible-playbook \
52+
--tags vars,docker-mirror \
53+
$(KDEVOPS_PLAYBOOKS_DIR)/docker-mirror.yml \
54+
--extra-vars=@./extra_vars.yaml
55+
56+
PHONY += docker-mirror-setup
57+
58+
docker-mirror-pull: $(KDEVOPS_EXTRA_VARS)
59+
$(Q)ansible-playbook \
60+
--tags vars,docker-mirror-pull \
61+
$(KDEVOPS_PLAYBOOKS_DIR)/docker-mirror.yml \
62+
--extra-vars=@./extra_vars.yaml
63+
64+
PHONY += docker-mirror-pull
65+
66+
docker-mirror-status:
67+
$(Q)scripts/check_docker_mirror.sh DOCKER_MIRROR_EXISTS
68+
69+
PHONY += docker-mirror-status
70+
4671
ANSIBLE_EXTRA_ARGS += $(LINUX_MIRROR_ARGS)
4772
LOCALHOST_SETUP_WORK += mirror
4873

4974
mirror-help-menu:
5075
@echo "Mirror options:"
51-
@echo "mirror - sets up systemd mirrors"
76+
@echo "mirror - sets up all mirrors (git, nix, docker)"
5277
@echo "mirror-status - checks systemd mirrors status"
5378
@echo ""
79+
@echo "Docker mirror specific targets:"
80+
@echo "docker-mirror - sets up Docker registry mirror only"
81+
@echo "docker-mirror-pull - pull and cache Docker images"
82+
@echo "docker-mirror-status - check Docker mirror status"
83+
@echo ""
5484

5585
HELP_TARGETS += mirror-help-menu
5686
endif

defconfigs/mirror

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ CONFIG_WORKFLOWS=n
33
CONFIG_INSTALL_LOCAL_LINUX_MIRROR=y
44
CONFIG_LINUX_MIRROR_NFS=y
55
CONFIG_INSTALL_NIX_CACHE_MIRROR=y
6+
CONFIG_ENABLE_DOCKER_MIRROR=y
7+
CONFIG_INSTALL_DOCKER_MIRROR=y

docs/docker-mirror.md

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
# Docker Mirror Support for kdevops
2+
3+
This document describes the Docker registry mirror feature in kdevops, which provides local caching of Docker images to speed up container-based workflows.
4+
5+
## Overview
6+
7+
The Docker mirror feature provides a local Docker registry that acts as a pull-through cache for Docker Hub and other registries. This significantly speeds up container deployments and enables offline operation with cached images.
8+
9+
## Features
10+
11+
- **Local Docker Registry**: Runs a Docker registry mirror on localhost:5000
12+
- **Pull-through Cache**: Automatically caches images as they are pulled
13+
- **Automatic Detection**: Workflows automatically detect and use the mirror when available
14+
- **NFS Server Integration**: Mirror can be shared via NFS to other systems
15+
- **Offline Operation**: Use cached images without internet connectivity
16+
17+
## Configuration
18+
19+
Enable Docker mirror support in menuconfig:
20+
21+
```bash
22+
make menuconfig
23+
# Navigate to: Kernel development environment -> Mirror options
24+
# Enable: Enable Docker registry mirror support
25+
# Enable: Install Docker registry mirror
26+
```
27+
28+
Configuration options:
29+
30+
- `CONFIG_ENABLE_DOCKER_MIRROR`: Enable Docker mirror support (auto-detected)
31+
- `CONFIG_USE_DOCKER_MIRROR`: Use Docker mirror if available (auto-detected)
32+
- `CONFIG_INSTALL_DOCKER_MIRROR`: Install Docker registry mirror
33+
- `CONFIG_DOCKER_MIRROR_PORT`: Registry port (default: 5000)
34+
- `CONFIG_DOCKER_MIRROR_PATH`: Storage path (default: /mirror/docker)
35+
- `CONFIG_DOCKER_MIRROR_PULL_THROUGH_CACHE`: Enable pull-through cache mode
36+
37+
## Usage
38+
39+
### Setup the Docker Mirror
40+
41+
```bash
42+
# Configure and install the mirror
43+
make menuconfig # Enable Docker mirror options
44+
make mirror # Sets up all mirrors with background downloads
45+
46+
# Or setup Docker mirror only
47+
make docker-mirror # Quick setup, downloads happen in background
48+
```
49+
50+
The setup completes immediately and downloads happen in the background via systemd:
51+
- Initial download starts immediately upon timer activation
52+
- Daily updates at 2 AM local time
53+
- Check progress: `journalctl -u docker-mirror-update.service -f`
54+
- Check status: `systemctl status docker-mirror-update.timer`
55+
56+
### Manual Image Operations (Optional)
57+
58+
```bash
59+
# Force immediate image pull (blocks until complete)
60+
make docker-mirror-pull
61+
62+
# Or use the script directly with custom images
63+
scripts/mirror-docker-images.sh [images-list-file] [--scan] [--archive]
64+
```
65+
66+
### Check Mirror Status
67+
68+
```bash
69+
# Check if Docker mirror is running
70+
make docker-mirror-status
71+
72+
# Or use the script
73+
scripts/check_docker_mirror.sh DOCKER_MIRROR_EXISTS
74+
```
75+
76+
## How It Works
77+
78+
### Mirror Detection
79+
80+
The system automatically detects if a Docker mirror is available by:
81+
82+
1. Checking if `/mirror/docker/` directory exists
83+
2. Verifying the registry service is running on the configured port
84+
3. Testing registry accessibility via HTTP
85+
86+
### Workflow Integration
87+
88+
Workflows automatically use the Docker mirror based on Kconfig detection:
89+
90+
1. Kconfig detects if `/mirror/docker/` exists and registry is running
91+
2. Sets `use_docker_mirror` variable automatically
92+
3. Workflows rewrite image URLs when mirror is enabled
93+
4. Fall back to original registries if mirror is unavailable
94+
95+
Example from MinIO workflow:
96+
97+
```yaml
98+
- name: Set MinIO container image with Docker mirror if enabled
99+
ansible.builtin.set_fact:
100+
minio_container_image_final: "localhost:{{ docker_mirror_port }}/{{ minio_container_image | regex_replace('^[^/]+/', '') }}"
101+
when:
102+
- use_docker_mirror | default(false) | bool
103+
104+
- name: Start MinIO container
105+
community.docker.docker_container:
106+
name: "{{ minio_container_name }}"
107+
image: "{{ minio_container_image_final }}"
108+
```
109+
110+
### Supported Images
111+
112+
The Docker mirror automatically caches the following images:
113+
114+
- **MinIO**: Object storage service
115+
- **Milvus**: Vector database for AI workloads
116+
- **vLLM**: High-performance LLM inference engine
117+
- `vllm/vllm-openai:latest` for standard GPU deployments
118+
- `openeuler/vllm-cpu:latest` for CPU inference deployments
119+
- `ghcr.io/vllm-project/production-stack/router:latest` for production stack router
120+
- **LMCache**: Advanced KV cache offloading for vLLM
121+
- `lmcache/vllm-openai:2025-05-27-v1` for stable LMCache features
122+
- `lmcache/vllm-openai:latest-nightly` for experimental cache server features
123+
- **Registry**: Docker registry itself
124+
- **etcd**: Distributed key-value store
125+
126+
#### vLLM and LMCache Images
127+
128+
The mirror includes support for vLLM inference deployments:
129+
130+
- **Standard GPU deployments**: Use `vllm/vllm-openai:latest` for single-node LLM serving with GPU
131+
- **CPU inference deployments**: Use `openeuler/vllm-cpu:latest` for CPU-only inference (includes CPU optimizations)
132+
- **Production stack**: Use `ghcr.io/vllm-project/production-stack/router:latest` with the Helm-based deployment
133+
- **LMCache deployments**: Use `lmcache/vllm-openai:2025-05-27-v1` for:
134+
- KV cache offloading to reduce GPU memory usage
135+
- Disaggregated prefill for better resource utilization
136+
- KV-aware routing and prefix caching
137+
- **Experimental features**: Use `lmcache/vllm-openai:latest-nightly` for testing newest cache server capabilities
138+
139+
These images are automatically updated daily via systemd timers to ensure you have the latest optimizations and fixes.
140+
141+
## Scripts
142+
143+
### docker-mirror-setup.sh
144+
145+
Sets up the Docker registry mirror:
146+
147+
```bash
148+
./scripts/docker-mirror-setup.sh [MIRROR_DIR] [REGISTRY_PORT] [REGISTRY_NAME]
149+
```
150+
151+
Features:
152+
- Creates directory structure
153+
- Configures registry with pull-through cache
154+
- Starts registry container
155+
- Optional Docker daemon configuration
156+
157+
### mirror-docker-images.sh
158+
159+
Pulls and caches Docker images:
160+
161+
```bash
162+
./scripts/mirror-docker-images.sh [images-list-file] [options]
163+
164+
Options:
165+
--scan Scan kdevops configuration for Docker images
166+
--archive Save images to compressed tar archives
167+
```
168+
169+
### check_docker_mirror.sh
170+
171+
Checks Docker mirror availability:
172+
173+
```bash
174+
./scripts/check_docker_mirror.sh [CHECK_TYPE]
175+
176+
CHECK_TYPE:
177+
DOCKER_MIRROR_URL - Returns mirror URL if available
178+
DOCKER_MIRROR_EXISTS - Returns true/false for mirror existence
179+
DOCKER_MIRROR_DIR - Returns mirror directory if exists
180+
IMAGE_EXISTS [image] - Check if specific image exists in mirror
181+
```
182+
183+
## Architecture
184+
185+
```
186+
/mirror/docker/
187+
├── registry/ # Registry data storage
188+
├── config/ # Registry configuration
189+
│ └── config.yml # Registry config with pull-through cache
190+
├── images/ # Image management
191+
│ ├── manifest.txt # List of cached images
192+
│ └── archives/ # Optional tar archives of images
193+
└── ...
194+
```
195+
196+
## Benefits
197+
198+
1. **Faster Deployments**: Images are served from local cache
199+
2. **Bandwidth Savings**: Images downloaded once, used many times
200+
3. **Offline Operation**: Continue working without internet access
201+
4. **Consistent Environments**: All systems use same image versions
202+
5. **Integration with NFS**: Share cached images across network
203+
204+
## Troubleshooting
205+
206+
### Registry Not Starting
207+
208+
Check if port 5000 is available:
209+
```bash
210+
sudo netstat -tlnp | grep 5000
211+
```
212+
213+
### Images Not Being Cached
214+
215+
Verify registry is in pull-through mode:
216+
```bash
217+
docker exec kdevops-docker-mirror cat /etc/docker/registry/config.yml | grep proxy
218+
```
219+
220+
### Workflows Not Using Mirror
221+
222+
Check if auto-detect is enabled:
223+
```bash
224+
grep DOCKER_MIRROR_AUTO_DETECT .config
225+
```
226+
227+
## Systemd Timers
228+
229+
Docker images are automatically updated daily via systemd timers:
230+
231+
- **Service**: `docker-mirror-update.service` - Updates Docker images
232+
- **Timer**: `docker-mirror-update.timer` - Runs daily at 2 AM
233+
- **Logs**: Stored in `/mirror/docker/logs/` with 30-day rotation
234+
235+
Check timer status:
236+
```bash
237+
systemctl status docker-mirror-update.timer
238+
systemctl list-timers docker-mirror-update.timer
239+
```
240+
241+
Run manual update:
242+
```bash
243+
systemctl start docker-mirror-update.service
244+
```
245+
246+
## Future Enhancements
247+
248+
- Support for multiple upstream registries
249+
- Image garbage collection policies
250+
- Web UI for registry management
251+
- Metrics and monitoring integration
252+
- Support for private registries with authentication

kconfigs/Kconfig.mirror

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,5 +740,82 @@ config NIX_CACHE_MIRROR_PATH
740740
This should be on a filesystem with sufficient space as the cache
741741
can grow to several GB over time.
742742

743+
config ENABLE_DOCKER_MIRROR
744+
bool "Enable Docker registry mirror support"
745+
default $(shell, scripts/check_docker_mirror.sh ENABLE_DOCKER_MIRROR)
746+
help
747+
Enable Docker registry mirror support to cache container images locally.
748+
This option enables the Docker mirror infrastructure if /mirror/docker/
749+
directory exists.
750+
751+
config USE_DOCKER_MIRROR
752+
bool "Use Docker registry mirror"
753+
output yaml
754+
default $(shell, scripts/check_docker_mirror.sh USE_DOCKER_MIRROR)
755+
depends on ENABLE_DOCKER_MIRROR
756+
help
757+
Automatically use the Docker registry mirror if it's running and accessible.
758+
This will configure workflows to use localhost:5000 as the registry mirror.
759+
760+
config INSTALL_DOCKER_MIRROR
761+
bool "Install Docker registry mirror"
762+
output yaml
763+
default $(shell, scripts/check_docker_mirror.sh INSTALL_DOCKER_MIRROR)
764+
depends on ENABLE_DOCKER_MIRROR
765+
help
766+
Enable this to set up a local Docker registry mirror for all guests
767+
and workflows that use Docker containers. This will significantly
768+
speed up container deployments by caching Docker images locally.
769+
770+
When enabled, this creates:
771+
- A local Docker registry mirror at /mirror/docker/
772+
- A Docker registry server on port 5000 (configurable)
773+
- Automatic caching of pulled images
774+
- Support for offline operation with cached images
775+
776+
This is particularly useful for workflows that use Docker containers
777+
such as:
778+
- MinIO object storage
779+
- Milvus vector database
780+
- AI/ML workflows with containerized services
781+
- Database benchmarking with sysbench
782+
783+
The mirror will be available at: http://localhost:5000/
784+
785+
config DOCKER_MIRROR_PORT
786+
int "Docker registry mirror port"
787+
output yaml
788+
default 5000
789+
depends on INSTALL_DOCKER_MIRROR
790+
help
791+
The port for the local Docker registry mirror server.
792+
Default is 5000. Ensure this port is available and not blocked by firewall.
793+
794+
config DOCKER_MIRROR_PATH
795+
string "Docker registry mirror storage path"
796+
output yaml
797+
default "/mirror/docker"
798+
depends on INSTALL_DOCKER_MIRROR
799+
help
800+
Local filesystem path where the Docker registry mirror will store images.
801+
This should be on a filesystem with sufficient space as Docker images
802+
can consume significant storage (several GB to tens of GB depending on
803+
the workflows you use).
804+
805+
config DOCKER_MIRROR_PULL_THROUGH_CACHE
806+
bool "Enable pull-through cache mode"
807+
output yaml
808+
default y
809+
depends on INSTALL_DOCKER_MIRROR
810+
help
811+
Enable pull-through cache mode for the Docker registry mirror.
812+
When enabled, the registry will automatically cache images as they
813+
are pulled through it, acting as a transparent proxy to Docker Hub
814+
and other registries.
815+
816+
This is the recommended mode as it requires no changes to image
817+
names and transparently caches all pulled images.
818+
819+
743820
endif # ENABLE_LOCAL_LINUX_MIRROR
744821
endif # TERRAFORM

0 commit comments

Comments
 (0)