feat: update actions container

- cleanup TAGS/PUSH make targets
- update actionsdind to include consul, packer, terraform, terragrunt and vault
- add script to build only images that changed, or all if build/ scripts are changed
This commit is contained in:
Ben Vincent 2025-01-12 13:05:03 +11:00
parent 980d2c495b
commit f497194dda
4 changed files with 57 additions and 32 deletions

View File

@ -12,11 +12,19 @@ BRANCH=$(shell git branch --show-current)
# Find all subdirectories under the IMAGES_PATH # Find all subdirectories under the IMAGES_PATH
DIRS := $(shell find $(IMAGES_PATH) -mindepth 3 -maxdepth 3 -type d | sed 's|$(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) .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 all directories
list: list:
@echo "Images:" @echo "Images:"
@ -30,6 +38,8 @@ $(DIRS):
@echo "Building for $@" @echo "Building for $@"
# Export environment # 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 \ @for kv in $$(vault kv get -format=json kv/service/packer/builder/env | jq -r '.data.data | to_entries[] | "\(.key)=\(.value)"'); do \
export "$kv"; \ export "$kv"; \
done done
@ -77,34 +87,6 @@ $(DIRS):
consul kv put infra/packer/$@/date "$$READABLE_DATE"; \ consul kv put infra/packer/$@/date "$$READABLE_DATE"; \
fi 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 all symlinks
clean: clean:
@echo "Cleaning up symlinks..." @echo "Cleaning up symlinks..."

31
ci/build.sh Executable file
View File

@ -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

View File

@ -2,10 +2,16 @@
docker_source = "git.query.consul/unkin/almalinux8-base:latest" docker_source = "git.query.consul/unkin/almalinux8-base:latest"
packages = [ packages = [
"bash", "bash",
"consul",
"docker-ce-cli", "docker-ce-cli",
"jq",
"make", "make",
"nodejs", "nodejs",
"unzip" "packer",
"terraform",
"terragrunt",
"unzip",
"vault"
] ]
scripts_pre_packages = [ scripts_pre_packages = [
"dnf install -y yum-utils", "dnf install -y yum-utils",

View File

@ -2,10 +2,16 @@
docker_source = "git.query.consul/unkin/almalinux9-base:latest" docker_source = "git.query.consul/unkin/almalinux9-base:latest"
packages = [ packages = [
"bash", "bash",
"consul",
"docker-ce-cli", "docker-ce-cli",
"jq",
"make", "make",
"nodejs", "nodejs",
"unzip" "packer",
"terraform",
"terragrunt",
"unzip",
"vault"
] ]
scripts_pre_packages = [ scripts_pre_packages = [
"dnf install -y yum-utils", "dnf install -y yum-utils",