diff --git a/Makefile b/Makefile index b500073..e670f7a 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,20 @@ .SUFFIXES: +# Use bash if available, otherwise fall back to default shell +SHELL := $(shell which bash 2>/dev/null || echo /bin/sh) + # Find all directories containing metadata.hcl FILES := $(shell find . -type f -name metadata.hcl) DIRS := $(patsubst %/,%,$(patsubst ./%,%,$(dir $(FILES)))) -.PHONY: all clean check prereqs $(DIRS) +ifeq ($(DIRS),) +$(error No subdirectories with metadata.hcl files found) +endif + +# Create push targets for each directory +PUSH_TARGETS := $(addprefix push-,$(DIRS)) + +.PHONY: all check prereqs push $(DIRS) $(PUSH_TARGETS) # Colours GREEN := \033[0;32m @@ -15,6 +25,8 @@ NC := \033[0m # Dry run flag DRY_RUN ?= false +default: all + # -------------------------- # Prerequisite checks # -------------------------- @@ -32,29 +44,23 @@ prereqs: check: prereqs @echo -e "$(BLUE)Performing bake --check for all projects...$(NC)" @$(foreach dir,$(DIRS), \ - echo -e "$(BLUE)[CHECK] $dir$(NC)"; \ + echo -e "$(BLUE)[CHECK] $(dir) $(NC)"; \ docker buildx bake -f $(dir)/metadata.hcl -f docker-bake.hcl --check; \ ) # -------------------------- # Push all images # -------------------------- -push: all - @echo -e "$(BLUE)Performing bake --push for all projects...$(NC)" - @$(foreach dir,$(DIRS), \ - echo -e "$(BLUE)[PUSH] $dir$(NC)"; \ - if [ "$(DRY_RUN)" = "true" ]; then \ - echo -e "$(GREEN)[DRY RUN] docker buildx bake -f $(dir)/metadata.hcl -f docker-bake.hcl --push$(NC)"; \ - else \ - docker buildx bake -f $(dir)/metadata.hcl -f docker-bake.hcl --push; \ - fi; \ - ) +push: prereqs $(PUSH_TARGETS) + @echo -e "$(GREEN)======================================================$(NC)" + @echo -e "$(GREEN)Push successful for all projects: $(DIRS)$(NC)" + @echo -e "$(GREEN)======================================================$(NC)" # -------------------------- # Generic per-project push # Usage: make push- # -------------------------- -push-%: prereqs +$(PUSH_TARGETS): push-%: prereqs @echo -e "$(BLUE)Performing bake --push for $*...$(NC)" ifeq ($(DRY_RUN),true) @echo -e "$(GREEN)[DRY RUN] docker buildx bake -f $*/metadata.hcl -f docker-bake.hcl --push$(NC)"