Compare commits

..

1 Commits

Author SHA1 Message Date
1bd6bed8d5 feat: add build workflows
All checks were successful
Build / build (pull_request) Successful in 5s
- enable fetch-depth for code_checkout
- fetch master branch before checking for changed files
- ensure the clean target is called with the default
- improve makefile failure handling
- ensure VAULT_ADDR is set before VAULT_TOKEN
2025-01-25 18:17:01 +11:00
3 changed files with 11 additions and 18 deletions

View File

@ -8,7 +8,6 @@ REGISTRY := git.query.consul
OWNER := unkin
DATE_TAG := $(shell date +%Y%m%d)
SUFFIX=$(shell basename $$(mktemp -u) | cut -d . -f 2)
#GIT_BRANCH=$(shell git branch --show-current)
GIT_BRANCH=$(shell git symbolic-ref --short HEAD 2>/dev/null || echo $$GITHUB_HEAD_REF)
GIT_COMMIT := $(shell git rev-parse --short HEAD)
@ -19,7 +18,6 @@ DIRS := $(shell find $(IMAGES_PATH) -mindepth 3 -maxdepth 3 -type d | sed 's|$(I
.DEFAULT_GOAL := default
default: clean
dnf install tree -y
./ci/build.sh
# Make all images
@ -45,8 +43,10 @@ $(DIRS):
export VAULT_TOKEN=$$(vault write -field=token auth/approle/login role_id=$$VAULT_ROLEID) && \
eval $$(vault kv get -format=json kv/service/packer/builder/env | jq -r '.data.data | to_entries[] | "export \(.key)=\(.value)"')
@echo "Environment retrieved for $@"
# Check if on master branch
if [ "$(GIT_BRANCH)" = "master" ]; then \
@if [ "$(GIT_BRANCH)" = "master" ]; then \
echo "Current branch is $(GIT_BRANCH), checking latest timestamp in consul."; \
LAST_BUILD_TIMESTAMP=$$(consul kv get infra/packer/$@/timestamp || echo "0"); \
CURRENT_TIME=$$(date +%s); \
@ -60,18 +60,15 @@ $(DIRS):
fi
# Link .hcl files
@echo "Linking .hcl files for $@"
find $(LIBRARY_PATH) -name '*.hcl' -exec sh -c 'ln -sf $$PWD/{} $(IMAGES_PATH)/$@/$(SYMLINK_PREFIX)$$(basename {})' \;
@find $(LIBRARY_PATH) -name '*.hcl' -exec sh -c 'ln -sf $$PWD/{} $(IMAGES_PATH)/$@/$(SYMLINK_PREFIX)$$(basename {})' \;
# Link builds
@echo "Linking build files for $@"
for build in $$(cat $(IMAGES_PATH)/$@/builds); do \
@for build in $$(cat $(IMAGES_PATH)/$@/builds); do \
ln -sf ../../../../builds/$${build}.pkr.hcl $(IMAGES_PATH)/$@/library_$${build}.build.pkr.hcl; \
done
# Build the image
tree /workspace
(cd $(IMAGES_PATH)/$@ && \
@(cd $(IMAGES_PATH)/$@ && \
export DATE=$(DATE_TAG) && \
export OS_NAME=$$(echo $@ | cut -d'/' -f1) && \
export OS_VERSION_FULL=$$(echo $@ | cut -d'/' -f2) && \
@ -83,13 +80,11 @@ $(DIRS):
export SUFFIX=$(SUFFIX) && \
export GIT_COMMIT=$(GIT_COMMIT) && \
export GIT_BRANCH=$(GIT_BRANCH) && \
echo "Starting packer init for $@" && \
/usr/bin/packer init . && \
echo "Starting packer build for $@" && \
/usr/bin/packer build -debug . )
/usr/bin/packer build . )
# Update build timestamp and date in Consul if on master branch
if [ "$(GIT_BRANCH)" = "master" ]; then \
@if [ "$(GIT_BRANCH)" = "master" ]; then \
echo "Current branch is $(GIT_BRANCH), updating consul."; \
CURRENT_TIMESTAMP=$$(date +%s); \
READABLE_DATE=$$(date '+%Y-%m-%d %H:%M:%S %Z'); \

View File

@ -1,6 +1,7 @@
#!/bin/bash
# Check for changes in images/ folder and the builds/ folder
git fetch origin master:master
if [ "$(git branch --show-current)" = "master" ]; then
builds_changes=$(git diff --name-only HEAD^...master | grep -E '^builds/')
images_changes=$(git diff --name-only HEAD^...master | grep -E '^images/')
@ -11,7 +12,7 @@ fi
# Run `make all` if there are changes in builds/
if [ -n "$builds_changes" ]; then
echo "Changes detected in builds/. Running 'make build-all'..."
echo "Changes detected in builds/. Running 'make all'..."
make all
fi
@ -20,9 +21,7 @@ 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|/[^/]+$||')
for target in $(echo $images_changes | sed -E 's|images/||; s|/[^/]+$||' | sort -u); do
echo "Running 'make $target'..."
make "$target"
done

View File

@ -1 +0,0 @@
packer-images