Compare commits

...

2 Commits

Author SHA1 Message Date
adc8e2fb40 test: debug
All checks were successful
Build / build (pull_request) Successful in 4m27s
2025-01-25 18:09:00 +11:00
7a1d25f3b6 feat: add build workflows
All checks were successful
Build / build (pull_request) Successful in 7s
- 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 17:14:28 +11:00
4 changed files with 82 additions and 12 deletions

View File

@ -0,0 +1,31 @@
name: Build
on:
pull_request:
jobs:
build:
runs-on: almalinux-8
container:
image: git.query.consul/unkin/almalinux9-actionsdind:latest
options: --privileged
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch master branch
run: |
git fetch origin master:master
- name: Show changed files
run: |
git diff --name-only master
- name: Run Packer Builds
env:
VAULT_ROLEID: ${{ secrets.PACKER_BUILDER_VAULT_ROLEID }}
run: |
make

View File

@ -0,0 +1,31 @@
name: Deploy
on:
push:
branches:
- master
jobs:
build:
runs-on: almalinux-8
container:
image: git.query.consul/unkin/almalinux9-actionsdind:latest
options: --privileged
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch master branch
run: |
git fetch origin master:master
- name: Run Packer Builds
env:
VAULT_ROLEID: ${{ secrets.PACKER_BUILDER_VAULT_ROLEID }}
DOCKER_USERNAME: ${{ secrets.UPLOAD_USER }}
DOCKER_PASSWORD: ${{ secrets.UPLOAD_PASS }}
run: |
make

View File

@ -8,7 +8,8 @@ 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 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)
# Find all subdirectories under the IMAGES_PATH
@ -17,7 +18,8 @@ DIRS := $(shell find $(IMAGES_PATH) -mindepth 3 -maxdepth 3 -type d | sed 's|$(I
.PHONY: list $(DIRS)
.DEFAULT_GOAL := default
default:
default: clean
dnf install tree -y
./ci/build.sh
# Make all images
@ -39,12 +41,12 @@ $(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
@eval $$(vault kv get -format=json kv/service/packer/builder/env | jq -r '.data.data | to_entries[] | "export \(.key)=\(.value)"')
export VAULT_ADDR=https://vault.query.consul:8200
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)"')
# 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); \
@ -58,15 +60,18 @@ $(DIRS):
fi
# Link .hcl files
@find $(LIBRARY_PATH) -name '*.hcl' -exec sh -c 'ln -sf $$PWD/{} $(IMAGES_PATH)/$@/$(SYMLINK_PREFIX)$$(basename {})' \;
@echo "Linking .hcl files for $@"
find $(LIBRARY_PATH) -name '*.hcl' -exec sh -c 'ln -sf $$PWD/{} $(IMAGES_PATH)/$@/$(SYMLINK_PREFIX)$$(basename {})' \;
# Link builds
@for build in $$(cat $(IMAGES_PATH)/$@/builds); do \
@echo "Linking build files for $@"
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
@(cd $(IMAGES_PATH)/$@ && \
tree /workspace
(cd $(IMAGES_PATH)/$@ && \
export DATE=$(DATE_TAG) && \
export OS_NAME=$$(echo $@ | cut -d'/' -f1) && \
export OS_VERSION_FULL=$$(echo $@ | cut -d'/' -f2) && \
@ -78,11 +83,13 @@ $(DIRS):
export SUFFIX=$(SUFFIX) && \
export GIT_COMMIT=$(GIT_COMMIT) && \
export GIT_BRANCH=$(GIT_BRANCH) && \
packer init . && \
packer build . )
echo "Starting packer init for $@" && \
/usr/bin/packer init . && \
echo "Starting packer build for $@" && \
/usr/bin/packer build -debug . )
# 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

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