diff --git a/Makefile b/Makefile index e0e8185..bb341da 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,19 @@ BRANCH=$(shell git branch --show-current) # Find all subdirectories under the IMAGES_PATH DIRS := $(shell find $(IMAGES_PATH) -mindepth 3 -maxdepth 3 -type d | sed 's|$(IMAGES_PATH)/||') -TAGS := $(shell find $(IMAGES_PATH) -mindepth 3 -maxdepth 3 -type d | sed 's|$(IMAGES_PATH)/|tag-|') -PUSH := $(shell find $(IMAGES_PATH) -mindepth 3 -maxdepth 3 -type d | sed 's|$(IMAGES_PATH)/|push-|') .PHONY: list $(DIRS) +.DEFAULT_GOAL := default +default: + ./ci/build.sh + +# Make all images +all: + @for dir in $(DIRS); do \ + $(MAKE) $$dir; \ + done + # List all directories list: @echo "Images:" @@ -30,6 +38,8 @@ $(DIRS): @echo "Building for $@" # Export environment + export VAULT_TOKEN=$$(vault write -field=token auth/approle/login role_id=$$VAULT_ROLEID) + export VAULT_ADDR=https://vault.service.consul:8200 @for kv in $$(vault kv get -format=json kv/service/packer/builder/env | jq -r '.data.data | to_entries[] | "\(.key)=\(.value)"'); do \ export "$kv"; \ done @@ -77,34 +87,6 @@ $(DIRS): consul kv put infra/packer/$@/date "$$READABLE_DATE"; \ fi -.PHONY: $(DIRS) $(TAGS) $(PUSH) - -# Tag Docker images -$(TAGS): - @echo "Tagging Docker image for $$(echo $@ | sed 's|tag-||')" - @OS_NAME=$$(echo "$@" | sed 's|tag-||' | cut -d'/' -f1); \ - OS_VERSION_FULL=$$(echo "$@" | sed 's|tag-||' | cut -d'/' -f2); \ - OS_IMAGE=$$(echo "$@" | sed 's|tag-||' | cut -d'/' -f3); \ - OS_VERSION_MAJOR=$$(echo $$OS_VERSION_FULL | cut -d'.' -f1); \ - IMAGE_NAME="$(REGISTRY)/$(OWNER)/$$OS_NAME$$OS_VERSION_MAJOR-$$OS_IMAGE"; \ - echo "Tagging Image Name: $$IMAGE_NAME:$(DATE_TAG)"; \ - docker tag $$IMAGE_NAME $$IMAGE_NAME:$(DATE_TAG); \ - echo "Tagging Image Name: $$IMAGE_NAME:latest"; \ - docker tag $$IMAGE_NAME $$IMAGE_NAME:latest - -# Push Docker images -$(PUSH): - @echo "Pushing Docker image for $$(echo $@ | sed 's|push-||')" - @OS_NAME=$$(echo "$@" | sed 's|push-||' | cut -d'/' -f1); \ - OS_VERSION_FULL=$$(echo "$@" | sed 's|push-||' | cut -d'/' -f2); \ - OS_IMAGE=$$(echo "$@" | sed 's|push-||' | cut -d'/' -f3); \ - OS_VERSION_MAJOR=$$(echo $$OS_VERSION_FULL | cut -d'.' -f1); \ - IMAGE_NAME="$(REGISTRY)/$(OWNER)/$$OS_NAME$$OS_VERSION_MAJOR-$$OS_IMAGE"; \ - echo "Pushing Image Name: $$IMAGE_NAME:$(DATE_TAG)"; \ - docker push $$IMAGE_NAME:$(DATE_TAG); \ - echo "Pushing Image Name: $$IMAGE_NAME:latest"; \ - docker push $$IMAGE_NAME:latest - # Clean all symlinks clean: @echo "Cleaning up symlinks..." diff --git a/ci/build.sh b/ci/build.sh new file mode 100755 index 0000000..55681ed --- /dev/null +++ b/ci/build.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Check for changes in builds/ folder +builds_changes=$(git diff --name-only master | grep -E '^builds/') + +# Check for changes in images/ folder +images_changes=$(git diff --name-only master | grep -E '^images/') + +# Run `make all` if there are changes in builds/ +if [ -n "$builds_changes" ]; then + echo "Changes detected in builds/. Running 'make build-all'..." + make build-all +fi + +# Run specific `make` commands for each changed file in images/ +if [ -n "$images_changes" ]; then + echo "Changes detected in images/. Running specific 'make' commands..." + + # Extract unique paths for `make` commands + for file in $images_changes; do + # Get the subdirectory path for the make command (e.g., almalinux/8.10/actionsdind) + target=$(echo "$file" | sed -E 's|images/||; s|/[^/]+$||') + echo "Running 'make $target'..." + make "$target" + done +fi + +# If no changes, output a message +if [ -z "$builds_changes" ] && [ -z "$images_changes" ]; then + echo "No relevant changes detected." +fi diff --git a/images/almalinux/8.10/actionsdind/variables.auto.pkrvars.hcl b/images/almalinux/8.10/actionsdind/variables.auto.pkrvars.hcl index dc0ba68..06f2a53 100644 --- a/images/almalinux/8.10/actionsdind/variables.auto.pkrvars.hcl +++ b/images/almalinux/8.10/actionsdind/variables.auto.pkrvars.hcl @@ -2,10 +2,16 @@ docker_source = "git.query.consul/unkin/almalinux8-base:latest" packages = [ "bash", + "consul", "docker-ce-cli", + "jq", "make", "nodejs", - "unzip" + "packer", + "terraform", + "terragrunt", + "unzip", + "vault" ] scripts_pre_packages = [ "dnf install -y yum-utils", diff --git a/images/almalinux/9.5/actionsdind/variables.auto.pkrvars.hcl b/images/almalinux/9.5/actionsdind/variables.auto.pkrvars.hcl index 812b45f..46e693e 100644 --- a/images/almalinux/9.5/actionsdind/variables.auto.pkrvars.hcl +++ b/images/almalinux/9.5/actionsdind/variables.auto.pkrvars.hcl @@ -2,10 +2,16 @@ docker_source = "git.query.consul/unkin/almalinux9-base:latest" packages = [ "bash", + "consul", "docker-ce-cli", + "jq", "make", "nodejs", - "unzip" + "packer", + "terraform", + "terragrunt", + "unzip", + "vault" ] scripts_pre_packages = [ "dnf install -y yum-utils",