Skip to content

Commit a3986e3

Browse files
ericfitzclaude
andcommitted
feat(terraform): add --push-env flag for external container build scripts
External container projects (tmi-ux, tmi-tf-wh) need OCIR registry info to push their images. Add --push-env flag that outputs eval-able shell env vars (OCIR_REGISTRY, OCIR_NAMESPACE, TMI_UX_IMAGE_URL, etc.) Usage from external projects: eval $(path/to/tmi/scripts/deploy-oci.sh --push-env) # or eval $(make -C path/to/tmi push-oci-env) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0b19bf1 commit a3986e3

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ tf-destroy: ## Destroy Terraform infrastructure (DESTRUCTIVE!)
11601160
@cd $(TF_DIR) && terraform destroy
11611161

11621162
# OCI-specific deployment shortcuts
1163-
.PHONY: deploy-oci deploy-oci-plan deploy-oci-skip-build destroy-oci push-oci-info
1163+
.PHONY: deploy-oci deploy-oci-plan deploy-oci-skip-build destroy-oci push-oci-info push-oci-env
11641164

11651165
deploy-oci: ## Deploy TMI to OCI (two-phase: infra, build containers, then K8s resources)
11661166
@scripts/deploy-oci.sh $(if $(AUTO_APPROVE),--auto-approve,)
@@ -1177,6 +1177,9 @@ destroy-oci: ## Destroy TMI OCI infrastructure (DESTRUCTIVE!)
11771177
push-oci-info: ## Show OCIR push instructions for external containers (tmi-ux, tmi-tf-wh)
11781178
@scripts/deploy-oci.sh --push-info
11791179

1180+
push-oci-env: ## Output OCIR registry info as env vars (use: eval $$(make push-oci-env))
1181+
@scripts/deploy-oci.sh --push-env
1182+
11801183
# ============================================================================
11811184
# PROMTAIL CONTAINER MANAGEMENT
11821185
# ============================================================================
@@ -1683,6 +1686,7 @@ help:
16831686
@echo " deploy-oci-skip-build - Deploy TMI to OCI without rebuilding containers"
16841687
@echo " destroy-oci - Destroy TMI OCI infrastructure"
16851688
@echo " push-oci-info - Show OCIR push info for external containers"
1689+
@echo " push-oci-env - Output OCIR registry env vars (eval-able)"
16861690
@echo ""
16871691
@echo "SBOM Generation (Software Bill of Materials):"
16881692
@echo " generate-sbom - Generate SBOM for Go application (cyclonedx-gomod)"

scripts/deploy-oci.sh

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# --auto-approve Skip terraform apply confirmation
2121
# --skip-build Skip container build+push (use existing images in OCIR)
2222
# --push-info Print OCIR push instructions for external containers and exit
23+
# --push-env Output OCIR registry info as shell env vars (eval-able)
2324
# --help Show this help message
2425
#
2526
# Examples:
@@ -60,6 +61,7 @@ DRY_RUN=false
6061
AUTO_APPROVE=false
6162
SKIP_BUILD=false
6263
PUSH_INFO=false
64+
PUSH_ENV=false
6365

6466
# Parse arguments
6567
while [[ $# -gt 0 ]]; do
@@ -96,8 +98,12 @@ while [[ $# -gt 0 ]]; do
9698
PUSH_INFO=true
9799
shift
98100
;;
101+
--push-env)
102+
PUSH_ENV=true
103+
shift
104+
;;
99105
--help)
100-
head -34 "$0" | tail -32
106+
head -35 "$0" | tail -33
101107
exit 0
102108
;;
103109
*)
@@ -330,9 +336,38 @@ print_external_container_info() {
330336
log_info "OCIR login (if not already authenticated):"
331337
echo -e " docker login ${registry} -u ${namespace}/<your-oci-username>"
332338
echo -e " (Use an OCI Auth Token as password — create at OCI Console > User Settings > Auth Tokens)"
339+
echo ""
340+
log_info "Or use eval to set env vars for external build scripts:"
341+
echo -e " eval \$(scripts/deploy-oci.sh --push-env)"
333342
fi
334343
}
335344

345+
# ---------------------------------------------------------------------------
346+
# Output OCIR registry info as shell env vars (machine-readable)
347+
# Usage from external projects: eval $(path/to/deploy-oci.sh --push-env)
348+
# ---------------------------------------------------------------------------
349+
print_push_env() {
350+
local namespace
351+
namespace=$(oci os ns get --query data --raw-output --profile "$OCI_PROFILE" 2>/dev/null || echo "")
352+
local registry="${OCI_REGION}.ocir.io"
353+
local name_prefix
354+
name_prefix=$(grep '^name_prefix' "$TF_DIR/terraform.tfvars" 2>/dev/null \
355+
| sed 's/.*= *"//;s/".*//' || echo "tmi")
356+
357+
# Common registry info
358+
echo "export OCIR_REGISTRY=${registry}"
359+
echo "export OCIR_NAMESPACE=${namespace}"
360+
echo "export OCIR_REGION=${OCI_REGION}"
361+
echo "export OCIR_BASE_URL=${registry}/${namespace}/${name_prefix}"
362+
echo "export OCIR_PLATFORM=linux/arm64"
363+
364+
# Per-component image URLs
365+
echo "export TMI_IMAGE_URL=${registry}/${namespace}/${name_prefix}/tmi:latest"
366+
echo "export TMI_REDIS_IMAGE_URL=${registry}/${namespace}/${name_prefix}/tmi-redis:latest"
367+
echo "export TMI_UX_IMAGE_URL=${registry}/${namespace}/${name_prefix}/tmi-ux:latest"
368+
echo "export TMI_TF_WH_IMAGE_URL=${registry}/${namespace}/${name_prefix}/tmi-tf-wh:latest"
369+
}
370+
336371
# ---------------------------------------------------------------------------
337372
# Delete orphaned OCI load balancers
338373
# ---------------------------------------------------------------------------
@@ -564,8 +599,8 @@ do_deploy() {
564599
# Main
565600
# ---------------------------------------------------------------------------
566601

567-
# Handle --push-info without full preflight
568-
if $PUSH_INFO; then
602+
# Handle --push-info and --push-env without full preflight
603+
if $PUSH_INFO || $PUSH_ENV; then
569604
# Minimal setup: read profile/region from tfvars
570605
if [[ -z "$OCI_PROFILE" ]]; then
571606
OCI_PROFILE=$(grep '^oci_config_profile' "$TF_DIR/terraform.tfvars" 2>/dev/null \
@@ -575,7 +610,11 @@ if $PUSH_INFO; then
575610
OCI_REGION=$(grep '^region' "$TF_DIR/terraform.tfvars" 2>/dev/null \
576611
| sed 's/.*= *"//;s/".*//' || echo "us-ashburn-1")
577612
fi
578-
print_external_container_info
613+
if $PUSH_ENV; then
614+
print_push_env
615+
else
616+
print_external_container_info
617+
fi
579618
exit 0
580619
fi
581620

0 commit comments

Comments
 (0)