feat: modularize application deployments
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-21 20:41:48 -06:00
parent 9f526c7704
commit 20e98064e0
2 changed files with 160 additions and 95 deletions

View File

@ -382,7 +382,7 @@ case "${1:-}" in
require_debian_server "apps"
jeannie_log_start "apps"
jeannie_step_plan 1
run_step "Applications" apps
run_step "Applications" apps "${2:-all}"
echo "Log: ${JEANNIE_LOG_FILE}"
;;
website-translation-model)

View File

@ -736,7 +736,7 @@ run_tofu_stack() {
if [[ "${stack}" == "bootstrap/platform" ]] && ! tofu_apply_has_targets "${apply_args[@]}"; then
adopt_platform_existing_resources
fi
if [[ "${stack}" == "bootstrap/apps" ]]; then
if [[ "${stack}" == "bootstrap/apps" ]] && ! tofu_apply_has_targets "${apply_args[@]}"; then
adopt_apps_existing_resources
fi
ensure_kubernetes_api_ready_for_tofu_stack "${stack}"
@ -7437,6 +7437,7 @@ PIMOX_NODE_STORAGE_EOF
}
apps() {
local app_selector="${1:-all}"
local app_ready_wait_seconds="${LAB_APPS_READY_WAIT_SECONDS:-180}"
local app_resource_wait_seconds="${LAB_APPS_RESOURCE_WAIT_SECONDS:-120}"
local buildx_builder_ready=false
@ -7452,6 +7453,47 @@ apps() {
local website_image_state_file
local website_platforms
local website_source_hash
local -a app_targets=()
local deploy_demos=false
local deploy_registry=false
local deploy_supply_chain=false
local deploy_website=false
case "${app_selector}" in
all)
deploy_demos=true
deploy_website=true
;;
website)
deploy_website=true
app_targets=('kubernetes_manifest.argocd_application["website-production"]')
;;
demos-static)
deploy_demos=true
app_targets=('kubernetes_manifest.argocd_application["demos-static"]')
;;
container-registry)
deploy_registry=true
app_targets=('kubernetes_manifest.argocd_application["container-registry"]')
;;
supply-chain-policy)
deploy_supply_chain=true
app_targets=('kubernetes_manifest.argocd_application["supply-chain-policy"]')
;;
heimdall)
app_targets=('kubernetes_manifest.argocd_application["heimdall"]')
;;
n8n)
app_targets=('kubernetes_manifest.argocd_application["n8n"]')
;;
gitea-runner)
app_targets=('kubernetes_manifest.argocd_application["gitea-runner"]')
;;
*)
echo "Unknown app '${app_selector}'. Use all, website, demos-static, container-registry, supply-chain-policy, heimdall, n8n, or gitea-runner." >&2
return 2
;;
esac
require_debian_server "apps"
@ -7474,66 +7516,76 @@ apps() {
ensure_pimox_kubeconfig
require_argocd_application_controller
require_pimox_app_worker_capacity
ensure_pimox_registry_storage_path
ensure_pimox_registry_endpoint_forwarding "${registry_endpoint}"
ensure_pimox_containerd_registry_refresh "${registry_endpoint}"
ensure_pimox_node_ephemeral_storage_headroom
ensure_cosign_keypair
publish_cosign_public_key_config_map
if [[ "${deploy_website}" == "true" || "${deploy_demos}" == "true" || "${deploy_registry}" == "true" ]]; then
ensure_pimox_registry_storage_path
ensure_pimox_registry_endpoint_forwarding "${registry_endpoint}"
ensure_pimox_containerd_registry_refresh "${registry_endpoint}"
ensure_pimox_node_ephemeral_storage_headroom
ensure_cosign_keypair
publish_cosign_public_key_config_map
fi
if [[ "${TF_VAR_registry_endpoint}" != "${registry_endpoint}" ]]; then
echo "TF_VAR_registry_endpoint changed after registry endpoint resolution (${registry_endpoint})" >&2
exit 1
fi
if [[ "${TF_VAR_website_image_ref}" != "${website_image_ref}" ]]; then
echo "TF_VAR_website_image_ref must match the buildx website image ref (${website_image_ref})" >&2
exit 1
if [[ "${deploy_website}" == "true" || "${deploy_demos}" == "true" ]]; then
if [[ "${TF_VAR_website_image_ref}" != "${website_image_ref}" ]]; then
echo "TF_VAR_website_image_ref must match the buildx website image ref (${website_image_ref})" >&2
exit 1
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
echo "apps/demos-static/web-app.yaml registry endpoint (${demos_registry_endpoint}) must match app registry endpoint (${registry_endpoint})" >&2
exit 1
fi
if [[ "${deploy_website}" == "true" && "$(image_ref_tag "${website_image_ref}")" == "latest" ]]; then
echo "apps/website/web-app.yaml must use an immutable php-website image tag, not latest." >&2
exit 1
fi
if [[ "${deploy_demos}" == "true" && "$(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
if [[ "${deploy_website}" == "true" ]]; then
ensure_website_image_tag_not_reused "${website_image_state_file}" "${website_source_hash}" "${website_image_ref}"
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
echo "apps/demos-static/web-app.yaml registry endpoint (${demos_registry_endpoint}) must match app registry endpoint (${registry_endpoint})" >&2
exit 1
fi
if [[ "$(image_ref_tag "${website_image_ref}")" == "latest" ]]; then
echo "apps/website/web-app.yaml must use an immutable php-website image tag, not latest." >&2
exit 1
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}"
echo "Deploying homelab applications..."
run_tofu_stack "bootstrap/apps"
if [[ "${LAB_CLUSTER_PROFILE:-debian}" == "pimox" ]] && ! truthy "${LAB_APPS_WAIT_GITEA_RUNNER_ON_PIMOX:-false}"; then
refresh_argocd_application gitea-runner
wait_for_namespace gitea-runner gitea-runner "${app_resource_wait_seconds}"
wait_for_namespaced_resource gitea-runner deployment gitea-runner gitea-runner "${app_resource_wait_seconds}"
scale_down_disabled_deployment gitea-runner gitea-runner app=gitea-runner gitea-runner
if ((${#app_targets[@]})); then
run_tofu_stack "bootstrap/apps" "${app_targets[@]}"
else
run_tofu_stack "bootstrap/apps"
fi
refresh_argocd_application container-registry
refresh_argocd_application supply-chain-policy
if [[ "${app_selector}" == "all" || "${deploy_registry}" == "true" || "${deploy_supply_chain}" == "true" ]]; then
if [[ "${app_selector}" == "all" || "${deploy_registry}" == "true" ]]; then
refresh_argocd_application container-registry
fi
if [[ "${app_selector}" == "all" || "${deploy_supply_chain}" == "true" ]]; then
refresh_argocd_application supply-chain-policy
fi
fi
if [[ "${app_selector}" == "all" || "${deploy_registry}" == "true" || "${deploy_supply_chain}" == "true" || "${deploy_website}" == "true" || "${deploy_demos}" == "true" ]]; then
wait_for_cluster_resource imagevalidatingpolicies.policies.kyverno.io homelab-local-registry-supply-chain supply-chain-policy "${app_resource_wait_seconds}"
fi
if [[ "${app_selector}" == "all" || "${deploy_registry}" == "true" || "${deploy_website}" == "true" || "${deploy_demos}" == "true" ]]; then
wait_for_namespace container-registry container-registry "${app_resource_wait_seconds}"
wait_for_namespaced_resource container-registry deployment local-registry container-registry "${app_resource_wait_seconds}"
wait_for_deployment_ready container-registry local-registry container-registry "${app_ready_wait_seconds}"
fi
wait_for_cluster_resource imagevalidatingpolicies.policies.kyverno.io homelab-local-registry-supply-chain supply-chain-policy "${app_resource_wait_seconds}"
wait_for_namespace container-registry container-registry "${app_resource_wait_seconds}"
wait_for_namespaced_resource container-registry deployment local-registry container-registry "${app_resource_wait_seconds}"
wait_for_deployment_ready container-registry local-registry container-registry "${app_ready_wait_seconds}"
if website_image_is_current "${website_image_state_file}" "${website_source_hash}" "${website_platforms}" "${website_image_ref}" "${registry_endpoint}" &&
image_supply_chain_metadata_exists "${website_image_ref}" "${registry_endpoint}"; then
echo "Website image ${website_image_ref} is already current (${website_source_hash}); skipping build."
else
if [[ "${deploy_website}" == "true" ]]; then
if website_image_is_current "${website_image_state_file}" "${website_source_hash}" "${website_platforms}" "${website_image_ref}" "${registry_endpoint}" &&
image_supply_chain_metadata_exists "${website_image_ref}" "${registry_endpoint}"; then
echo "Website image ${website_image_ref} is already current (${website_source_hash}); skipping build."
else
echo "Building website image ${website_image_ref} for ${website_platforms} (${website_source_hash})..."
ensure_docker_build_space
if [[ "${buildx_builder_ready}" != "true" ]]; then
@ -7554,14 +7606,16 @@ apps() {
echo "Website image build failed for ${website_image_ref}; not publishing supply-chain metadata." >&2
return 1
fi
website_image_built=true
website_image_built=true
fi
publish_image_supply_chain_metadata "${website_image_ref}" "${registry_endpoint}" "${website_source_hash}"
fi
publish_image_supply_chain_metadata "${website_image_ref}" "${registry_endpoint}" "${website_source_hash}"
if demos_image_is_current "${demos_image_state_file}" "${demos_source_hash}" "${demos_platforms}" "${demos_image_ref}" "${registry_endpoint}" &&
image_supply_chain_metadata_exists "${demos_image_ref}" "${registry_endpoint}"; then
echo "Demos image ${demos_image_ref} is already current (${demos_source_hash}); skipping build."
else
if [[ "${deploy_demos}" == "true" ]]; then
if demos_image_is_current "${demos_image_state_file}" "${demos_source_hash}" "${demos_platforms}" "${demos_image_ref}" "${registry_endpoint}" &&
image_supply_chain_metadata_exists "${demos_image_ref}" "${registry_endpoint}"; then
echo "Demos image ${demos_image_ref} is already current (${demos_source_hash}); skipping build."
else
echo "Building demos image ${demos_image_ref} for ${demos_platforms} (${demos_source_hash})..."
ensure_docker_build_space
if [[ "${buildx_builder_ready}" != "true" ]]; then
@ -7582,52 +7636,63 @@ apps() {
echo "Demos image build failed for ${demos_image_ref}; not publishing supply-chain metadata." >&2
return 1
fi
demos_image_built=true
fi
publish_image_supply_chain_metadata "${demos_image_ref}" "${registry_endpoint}" "${demos_source_hash}"
refresh_argocd_application website-production
wait_for_namespace website-production website-production "${app_resource_wait_seconds}"
wait_for_namespaced_resource website-production deployment php-website-deployment website-production "${app_resource_wait_seconds}"
ensure_deployment_container_image website-production php-website-deployment php-app "${website_image_ref}" website-production
recreate_pods_for_selector website-production app=php-website website-production
wait_for_deployment_ready website-production php-website-deployment website-production "${app_ready_wait_seconds}"
if [[ "${website_image_built}" == "true" ]]; then
write_website_image_state "${website_image_state_file}" "${website_source_hash}" "${website_platforms}" "${website_image_ref}"
demos_image_built=true
fi
publish_image_supply_chain_metadata "${demos_image_ref}" "${registry_endpoint}" "${demos_source_hash}"
fi
refresh_argocd_application demos-static
wait_for_namespace demos-static demos-static "${app_resource_wait_seconds}"
wait_for_namespaced_resource demos-static deployment demos-static demos-static "${app_resource_wait_seconds}"
ensure_deployment_container_image demos-static demos-static demos-static "${demos_image_ref}" demos-static
recreate_pods_for_selector demos-static app=demos-static demos-static
wait_for_deployment_ready demos-static demos-static demos-static "${app_ready_wait_seconds}"
if [[ "${demos_image_built}" == "true" ]]; then
write_demos_image_state "${demos_image_state_file}" "${demos_source_hash}" "${demos_platforms}" "${demos_image_ref}"
if [[ "${deploy_website}" == "true" ]]; then
refresh_argocd_application website-production
wait_for_namespace website-production website-production "${app_resource_wait_seconds}"
wait_for_namespaced_resource website-production deployment php-website-deployment website-production "${app_resource_wait_seconds}"
ensure_deployment_container_image website-production php-website-deployment php-app "${website_image_ref}" website-production
recreate_pods_for_selector website-production app=php-website website-production
wait_for_deployment_ready website-production php-website-deployment website-production "${app_ready_wait_seconds}"
if [[ "${website_image_built}" == "true" ]]; then
write_website_image_state "${website_image_state_file}" "${website_source_hash}" "${website_platforms}" "${website_image_ref}"
fi
fi
refresh_argocd_application heimdall
wait_for_namespaced_resource monitoring ingress grafana heimdall "${app_resource_wait_seconds}"
wait_for_namespaced_resource monitoring ingress prometheus heimdall "${app_resource_wait_seconds}"
wait_for_namespaced_resource monitoring ingress alertmanager heimdall "${app_resource_wait_seconds}"
wait_for_namespaced_resource argocd ingress argocd-server heimdall "${app_resource_wait_seconds}"
if [[ "${deploy_demos}" == "true" ]]; then
refresh_argocd_application demos-static
wait_for_namespace demos-static demos-static "${app_resource_wait_seconds}"
wait_for_namespaced_resource demos-static deployment demos-static demos-static "${app_resource_wait_seconds}"
ensure_deployment_container_image demos-static demos-static demos-static "${demos_image_ref}" demos-static
recreate_pods_for_selector demos-static app=demos-static demos-static
wait_for_deployment_ready demos-static demos-static demos-static "${app_ready_wait_seconds}"
if [[ "${demos_image_built}" == "true" ]]; then
write_demos_image_state "${demos_image_state_file}" "${demos_source_hash}" "${demos_platforms}" "${demos_image_ref}"
fi
fi
refresh_argocd_application n8n
wait_for_namespace n8n n8n "${app_resource_wait_seconds}"
wait_for_namespaced_resource n8n deployment n8n n8n "${app_resource_wait_seconds}"
wait_for_deployment_ready n8n n8n n8n "${app_ready_wait_seconds}"
if [[ "${app_selector}" == "all" || "${app_selector}" == "heimdall" ]]; then
refresh_argocd_application heimdall
wait_for_namespaced_resource monitoring ingress grafana heimdall "${app_resource_wait_seconds}"
wait_for_namespaced_resource monitoring ingress prometheus heimdall "${app_resource_wait_seconds}"
wait_for_namespaced_resource monitoring ingress alertmanager heimdall "${app_resource_wait_seconds}"
wait_for_namespaced_resource argocd ingress argocd-server heimdall "${app_resource_wait_seconds}"
fi
apply_gitea_runner_secret_file
refresh_argocd_application gitea-runner
if [[ "${LAB_CLUSTER_PROFILE:-debian}" == "pimox" ]] && ! truthy "${LAB_APPS_WAIT_GITEA_RUNNER_ON_PIMOX:-false}"; then
wait_for_namespace gitea-runner gitea-runner "${app_resource_wait_seconds}"
wait_for_namespaced_resource gitea-runner deployment gitea-runner gitea-runner "${app_resource_wait_seconds}"
scale_down_disabled_deployment gitea-runner gitea-runner app=gitea-runner gitea-runner
echo "Skipping Gitea Kubernetes runner readiness on Pimox; the current runner manifest needs a Docker socket and is kept scaled down."
else
wait_for_namespace gitea-runner gitea-runner "${app_resource_wait_seconds}"
wait_for_namespaced_resource gitea-runner deployment gitea-runner gitea-runner "${app_resource_wait_seconds}"
wait_for_deployment_ready gitea-runner gitea-runner gitea-runner "${app_ready_wait_seconds}"
if [[ "${app_selector}" == "all" || "${app_selector}" == "n8n" ]]; then
refresh_argocd_application n8n
wait_for_namespace n8n n8n "${app_resource_wait_seconds}"
wait_for_namespaced_resource n8n deployment n8n n8n "${app_resource_wait_seconds}"
wait_for_deployment_ready n8n n8n n8n "${app_ready_wait_seconds}"
fi
if [[ "${app_selector}" == "all" || "${app_selector}" == "gitea-runner" ]]; then
apply_gitea_runner_secret_file
refresh_argocd_application gitea-runner
if [[ "${LAB_CLUSTER_PROFILE:-debian}" == "pimox" ]] && ! truthy "${LAB_APPS_WAIT_GITEA_RUNNER_ON_PIMOX:-false}"; then
wait_for_namespace gitea-runner gitea-runner "${app_resource_wait_seconds}"
wait_for_namespaced_resource gitea-runner deployment gitea-runner gitea-runner "${app_resource_wait_seconds}"
scale_down_disabled_deployment gitea-runner gitea-runner app=gitea-runner gitea-runner
echo "Skipping Gitea Kubernetes runner readiness on Pimox; the current runner manifest needs a Docker socket and is kept scaled down."
else
wait_for_namespace gitea-runner gitea-runner "${app_resource_wait_seconds}"
wait_for_namespaced_resource gitea-runner deployment gitea-runner gitea-runner "${app_resource_wait_seconds}"
wait_for_deployment_ready gitea-runner gitea-runner gitea-runner "${app_ready_wait_seconds}"
fi
fi
echo "Application deployment successfully completed."