fix: deploy demos with immutable image tag
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details

This commit is contained in:
juvenal.diaz 2026-10-01 22:11:03 -06:00
parent 0d8067b566
commit 27186662f9
4 changed files with 31 additions and 4 deletions

View File

@ -23,8 +23,8 @@ spec:
fsGroupChangePolicy: OnRootMismatch fsGroupChangePolicy: OnRootMismatch
containers: containers:
- name: demos-static - name: demos-static
image: 192.168.100.73:30500/demos-static:latest image: 192.168.100.73:30500/demos-static:bootstrap
imagePullPolicy: Always imagePullPolicy: IfNotPresent
securityContext: securityContext:
allowPrivilegeEscalation: false allowPrivilegeEscalation: false
readOnlyRootFilesystem: true readOnlyRootFilesystem: true

View File

@ -24,6 +24,11 @@ locals {
kustomize = { kustomize = {
images = ["php-website=${var.website_image_ref}"] images = ["php-website=${var.website_image_ref}"]
} }
} : {},
name == "demos-static" && var.demos_image_ref != "" ? {
kustomize = {
images = ["demos-static=${var.demos_image_ref}"]
}
} : {} } : {}
) )
} }

View File

@ -18,6 +18,11 @@ variable "website_image_ref" {
default = "" default = ""
} }
variable "demos_image_ref" {
type = string
default = ""
}
variable "applications" { variable "applications" {
type = map(object({ type = map(object({
project = string project = string

View File

@ -3821,6 +3821,12 @@ website_image_tag() {
printf 'src-%s\n' "${source_hash:0:12}" printf 'src-%s\n' "${source_hash:0:12}"
} }
demos_image_tag() {
local source_hash="$1"
printf 'src-%s\n' "${source_hash:0:12}"
}
apps_registry_endpoint() { apps_registry_endpoint() {
if [[ -n "${TF_VAR_registry_endpoint:-}" ]]; then if [[ -n "${TF_VAR_registry_endpoint:-}" ]]; then
printf '%s\n' "${TF_VAR_registry_endpoint}" printf '%s\n' "${TF_VAR_registry_endpoint}"
@ -3929,6 +3935,7 @@ demos_image_is_current() {
local platforms="$3" local platforms="$3"
local image_ref="$4" local image_ref="$4"
local registry_endpoint="$5" local registry_endpoint="$5"
local image_tag
local saved_hash local saved_hash
local saved_platforms local saved_platforms
local saved_image local saved_image
@ -3943,7 +3950,8 @@ demos_image_is_current() {
[[ "${saved_platforms}" == "${platforms}" ]] || return 1 [[ "${saved_platforms}" == "${platforms}" ]] || return 1
[[ "${saved_image}" == "${image_ref}" ]] || return 1 [[ "${saved_image}" == "${image_ref}" ]] || return 1
registry_image_exists "${registry_endpoint}" demos-static latest image_tag="$(image_ref_tag "${image_ref}")"
registry_image_exists "${registry_endpoint}" demos-static "${image_tag}"
} }
write_website_image_state() { write_website_image_state() {
@ -6333,16 +6341,17 @@ apps() {
registry_endpoint="$(apps_registry_endpoint)" registry_endpoint="$(apps_registry_endpoint)"
demos_registry_endpoint="$(demos_registry_endpoint)" demos_registry_endpoint="$(demos_registry_endpoint)"
demos_image_ref="${registry_endpoint}/demos-static:latest"
demos_image_state_file="${REPO_ROOT}/.lab/demos-static-image.state" demos_image_state_file="${REPO_ROOT}/.lab/demos-static-image.state"
demos_platforms="${DEMOS_IMAGE_PLATFORMS:-linux/amd64,linux/arm64}" demos_platforms="${DEMOS_IMAGE_PLATFORMS:-linux/amd64,linux/arm64}"
demos_source_hash="$(demos_source_hash)" demos_source_hash="$(demos_source_hash)"
demos_image_ref="${registry_endpoint}/demos-static:${DEMOS_IMAGE_TAG:-$(demos_image_tag "${demos_source_hash}")}"
website_image_state_file="${REPO_ROOT}/.lab/php-website-image.state" website_image_state_file="${REPO_ROOT}/.lab/php-website-image.state"
website_platforms="${WEBSITE_IMAGE_PLATFORMS:-linux/amd64,linux/arm64}" website_platforms="${WEBSITE_IMAGE_PLATFORMS:-linux/amd64,linux/arm64}"
website_source_hash="$(website_source_hash)" website_source_hash="$(website_source_hash)"
website_image_ref="${registry_endpoint}/php-website:${WEBSITE_IMAGE_TAG:-$(website_image_tag "${website_source_hash}")}" website_image_ref="${registry_endpoint}/php-website:${WEBSITE_IMAGE_TAG:-$(website_image_tag "${website_source_hash}")}"
export TF_VAR_registry_endpoint="${TF_VAR_registry_endpoint:-${registry_endpoint}}" export TF_VAR_registry_endpoint="${TF_VAR_registry_endpoint:-${registry_endpoint}}"
export TF_VAR_website_image_ref="${TF_VAR_website_image_ref:-${website_image_ref}}" export TF_VAR_website_image_ref="${TF_VAR_website_image_ref:-${website_image_ref}}"
export TF_VAR_demos_image_ref="${TF_VAR_demos_image_ref:-${demos_image_ref}}"
export TF_VAR_kubeconfig_path="${TF_VAR_kubeconfig_path:-${KUBECONFIG_PATH}}" export TF_VAR_kubeconfig_path="${TF_VAR_kubeconfig_path:-${KUBECONFIG_PATH}}"
export KUBECONFIG_PATH="${TF_VAR_kubeconfig_path}" export KUBECONFIG_PATH="${TF_VAR_kubeconfig_path}"
@ -6364,6 +6373,10 @@ apps() {
echo "TF_VAR_website_image_ref must match the buildx website image ref (${website_image_ref})" >&2 echo "TF_VAR_website_image_ref must match the buildx website image ref (${website_image_ref})" >&2
exit 1 exit 1
fi fi
if [[ "${TF_VAR_demos_image_ref}" != "${demos_image_ref}" ]]; then
echo "TF_VAR_demos_image_ref must match the buildx demos image ref (${demos_image_ref})" >&2
exit 1
fi
if [[ "${demos_registry_endpoint}" != "${registry_endpoint}" ]]; then if [[ "${demos_registry_endpoint}" != "${registry_endpoint}" ]]; then
echo "apps/demos-static/web-app.yaml registry endpoint (${demos_registry_endpoint}) must match app registry endpoint (${registry_endpoint})" >&2 echo "apps/demos-static/web-app.yaml registry endpoint (${demos_registry_endpoint}) must match app registry endpoint (${registry_endpoint})" >&2
@ -6374,6 +6387,10 @@ apps() {
echo "apps/website/web-app.yaml must use an immutable php-website image tag, not latest." >&2 echo "apps/website/web-app.yaml must use an immutable php-website image tag, not latest." >&2
exit 1 exit 1
fi fi
if [[ "$(image_ref_tag "${demos_image_ref}")" == "latest" ]]; then
echo "apps/demos-static/web-app.yaml must use an immutable demos-static image tag, not latest." >&2
exit 1
fi
ensure_website_image_tag_not_reused "${website_image_state_file}" "${website_source_hash}" "${website_image_ref}" ensure_website_image_tag_not_reused "${website_image_state_file}" "${website_source_hash}" "${website_image_ref}"
echo "Deploying homelab applications..." echo "Deploying homelab applications..."