Skip to content

Commit 2e13bb9

Browse files
authored
feat: Add download and load images functionality to Makefile (#115)
1 parent fe42b03 commit 2e13bb9

File tree

1 file changed

+117
-4
lines changed

1 file changed

+117
-4
lines changed

Makefile

Lines changed: 117 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ MAKEFLAGS += --no-print-directory
33
WITH_MINERU ?= false # 默认不构建mineru
44
VERSION ?= latest
55
NAMESPACE ?= datamate
6+
PLATFORM ?= linux/amd64 # Default platform for image downloads
7+
SAVE ?= false # Default: only pull images, don't save to dist/
68

79
# Registry configuration: use --dev for local images, otherwise use GitHub registry
810
ifdef dev
@@ -28,10 +30,13 @@ help:
2830
@echo "Usage: make <target> [options]"
2931
@echo ""
3032
@echo "Options:"
31-
@echo " dev=true Use local images instead of registry (empty REGISTRY)"
32-
@echo " VERSION=<version> Set image version (default: latest)"
33-
@echo " NAMESPACE=<name> Set Kubernetes namespace (default: datamate)"
34-
@echo " INSTALLER=<type> Set installer type: docker or k8s"
33+
@echo " dev=true Use local images instead of registry (empty REGISTRY)"
34+
@echo " VERSION=<version> Set image version (default: latest)"
35+
@echo " NAMESPACE=<name> Set Kubernetes namespace (default: datamate)"
36+
@echo " INSTALLER=<type> Set installer type: docker or k8s"
37+
@echo " PLATFORM=<platform> Set platform for downloads (default: linux/amd64)"
38+
@echo " Options: linux/amd64, linux/arm64"
39+
@echo " SAVE=true Save images to dist/ during download (default: false)"
3540
@echo ""
3641
@echo "Build Commands:"
3742
@echo " make build Build all core images"
@@ -61,6 +66,13 @@ help:
6166
@echo "Upgrade Commands:"
6267
@echo " make datamate-docker-upgrade Upgrade datamate deployment"
6368
@echo ""
69+
@echo "Download Commands:"
70+
@echo " make download Pull all images (no save by default)"
71+
@echo " make download SAVE=true Download and save images to dist/"
72+
@echo " make download PLATFORM=linux/arm64 Download ARM64 images"
73+
@echo " make download SAVE=true PLATFORM=linux/arm64 Save ARM64 images"
74+
@echo " make load-images Load all downloaded images from dist/"
75+
@echo ""
6476
@echo "Utility Commands:"
6577
@echo " make create-namespace Create Kubernetes namespace"
6678
@echo " make help Show this help message"
@@ -372,4 +384,105 @@ VALID_UPGRADE_TARGETS := datamate
372384
fi
373385
@if [ "$*" = "datamate" ]; then \
374386
cd deployment/docker/datamate && docker compose -f docker-compose.yml --profile mineru up -d --force-recreate --remove-orphans; \
387+
fi
388+
389+
# ========== Download Targets ==========
390+
391+
# List of all images to download
392+
DOWNLOAD_IMAGES := \
393+
datamate-backend \
394+
datamate-database \
395+
datamate-frontend \
396+
datamate-runtime \
397+
datamate-backend-python
398+
399+
# Download all images for offline installation
400+
.PHONY: download
401+
download:
402+
@echo "Downloading images for platform: $(PLATFORM)"
403+
@echo "Registry: $(REGISTRY)"
404+
@echo "Version: $(VERSION)"
405+
@echo "Save to dist/: $(SAVE)"
406+
@echo ""
407+
@if [ "$(SAVE)" = "true" ]; then \
408+
mkdir -p dist; \
409+
fi
410+
@if [ -z "$(REGISTRY)" ] && [ "$(SAVE)" != "true" ]; then \
411+
echo "Error: REGISTRY is empty and SAVE=false"; \
412+
echo "Either set REGISTRY to pull images, or use SAVE=true to save local images"; \
413+
exit 1; \
414+
fi
415+
@failed=0; \
416+
for image in $(DOWNLOAD_IMAGES); do \
417+
if [ -z "$(REGISTRY)" ]; then \
418+
full_image="$$image:$(VERSION)"; \
419+
if [ "$(SAVE)" = "true" ]; then \
420+
echo "Saving local image $$full_image to dist/$$image-$(VERSION).tar..."; \
421+
if docker save -o dist/$$image-$(VERSION).tar $$full_image; then \
422+
echo "Compressing to dist/$$image-$(VERSION).tar.gz..."; \
423+
gzip -f dist/$$image-$(VERSION).tar; \
424+
echo "✓ Saved $$image to dist/$$image-$(VERSION).tar.gz"; \
425+
else \
426+
echo "✗ Failed to save $$full_image (image may not exist locally)"; \
427+
failed=$$((failed + 1)); \
428+
fi; \
429+
fi; \
430+
else \
431+
full_image="$(REGISTRY)$$image:$(VERSION)"; \
432+
echo "Pulling $$full_image for $(PLATFORM)..."; \
433+
if docker pull --platform $(PLATFORM) $$full_image; then \
434+
echo "✓ Pulled $$image"; \
435+
if [ "$(SAVE)" = "true" ]; then \
436+
echo "Saving $$full_image to dist/$$image-$(VERSION).tar..."; \
437+
docker save -o dist/$$image-$(VERSION).tar $$full_image; \
438+
echo "Compressing to dist/$$image-$(VERSION).tar.gz..."; \
439+
gzip -f dist/$$image-$(VERSION).tar; \
440+
echo "✓ Saved $$image to dist/$$image-$(VERSION).tar.gz"; \
441+
fi; \
442+
else \
443+
echo "✗ Failed to pull $$full_image"; \
444+
failed=$$((failed + 1)); \
445+
fi; \
446+
fi; \
447+
echo ""; \
448+
done; \
449+
if [ $$failed -eq 0 ]; then \
450+
if [ "$(SAVE)" = "true" ]; then \
451+
echo "All images downloaded successfully to dist/"; \
452+
echo "To load images on target machine: docker load -i <image-file>.tar.gz"; \
453+
else \
454+
echo "All images pulled successfully"; \
455+
echo "Use SAVE=true to save images to dist/ for offline installation"; \
456+
fi; \
457+
else \
458+
echo "Failed to download $$failed image(s)"; \
459+
echo "Please check your registry credentials and image availability"; \
460+
exit 1; \
461+
fi
462+
463+
# Load all downloaded images from dist/ directory
464+
.PHONY: load-images
465+
load-images:
466+
@if [ ! -d "dist" ]; then \
467+
echo "Error: dist/ directory not found"; \
468+
echo "Please run 'make download' first to download images"; \
469+
exit 1; \
470+
fi
471+
@echo "Loading images from dist/..."
472+
@count=0; \
473+
for tarfile in dist/*.tar.gz; do \
474+
if [ -f "$$tarfile" ]; then \
475+
echo "Loading $$tarfile..."; \
476+
docker load -i "$$tarfile"; \
477+
count=$$((count + 1)); \
478+
echo "✓ Loaded $$tarfile"; \
479+
echo ""; \
480+
fi; \
481+
done; \
482+
if [ $$count -eq 0 ]; then \
483+
echo "No image files found in dist/"; \
484+
echo "Please run 'make download' first"; \
485+
exit 1; \
486+
else \
487+
echo "Successfully loaded $$count image(s)"; \
375488
fi

0 commit comments

Comments
 (0)