Skip to content

refactor: shared Python deploy tooling with shell CLI orchestration - #12

Merged
malon64 merged 3 commits into
mainfrom
refactor/shared-python-deploy-tooling
Jul 6, 2026
Merged

malon64 merged 3 commits into
mainfrom
refactor/shared-python-deploy-tooling

Conversation

@malon64

@malon64 malon64 commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Context

The deploy pipeline was ~6,900 lines of bash across scripts/{local,azure,aws}, with environment-agnostic logic duplicated three times and several concerns embedded as Python heredocs inside shell. scripts/local/* was also acting as shared code for the cloud environments.

This splits responsibilities by tool strength:

  • Shell stays the orchestrator for CLIs (terraform, kubectl, helm, docker, dbt, floe, aws, az).
  • Python owns cross-environment logic — REST/API calls, object-storage uploads, report bundle manipulation, credential handling, and provider-contract parsing — in one uv-managed package, tools/olf, behind the olf CLI.

Recorded in ADR 0017.

What changed

New tools/olf package (uv-managed, ruff + pytest in CI). Each subcommand replaces duplicated/heredoc logic:

olf command Replaced
contracts env emit-contract-env.py + the defaulting/branching body of load-runtime-env.sh
floe render-profile render-floe-profile.py
artifacts upload-manifests --via port-forward|direct upload-floe-manifest.sh + AWS's inline upload_floe_manifests_to_s3()
superset deploy-reports / export-reports superset-reports-deploy.sh / -export.sh
openmetadata deploy-metadata the 669-line openmetadata-metadata-deploy.sh
k8s set-project-code-image the 3 heredoc patch fns duplicated in Azure+AWS deploy scripts
polaris check-credentials the duplicated curl OAuth preflight

Shared shell helpers deduped into scripts/lib/{common,helm,kube,python}.sh. The three env infra-up.sh / deploy-artifacts.sh are now thin orchestrators.

Reorganized so scripts/local/* no longer doubles as shared code: scripts/contracts/ and scripts/artifacts/ are env-neutral. Terraform stays the contract source of truth; olf contracts env keeps exported variable names byte-identical.

make <env>-up is now a full wrapper — foundation + infra + artifacts (foundation apply is a Terraform no-op when the cluster exists). Former behavior preserved as make <env>-stack-up; all granular targets retained.

Net: −2,625 / +288 lines in scripts/, replaced by a tested/linted Python package + 267 lines of shared shell libs. Host gains one prerequisite: uv.

Verification

  • make check-structure, make check-contracts pass
  • ruff check clean, 31 pytest pass
  • All shell scripts pass bash -n
  • Byte-identical parity: olf contracts env and olf floe render-profile diffed against the original scripts (local + AWS-shaped envs, with/without Terraform state) — zero diff

Not run here (need environment): local e2e (make local-up, Docker/kind), cloud (make aws-up / make azure-up, sandbox creds).

Follow-up (logged in technical-debt.md)

check-* and e2e scripts remain bash and check-contracts.sh grep-asserts on source text — the natural next step is to rewrite them on top of tools/olf.

Split the deploy pipeline by tool strength: shell keeps orchestrating the
CLIs (terraform, kubectl, helm, docker, dbt, floe, aws, az), while
cross-environment logic (REST/API calls, object-storage uploads, report
bundle manipulation, credential handling, contract parsing) moves into one
uv-managed Python package, tools/olf, exposed through the `olf` CLI.

- New olf subcommands replace duplicated/heredoc logic: contracts env,
  floe render-profile, artifacts upload-manifests, superset deploy/export,
  openmetadata deploy-metadata, k8s set-project-code-image, polaris
  check-credentials.
- Shared shell helpers deduped into scripts/lib/{common,helm,kube,python}.sh;
  the three env infra-up/deploy-artifacts scripts are now thin orchestrators.
- Env-neutral shell moved out of scripts/local: scripts/contracts/ and
  scripts/artifacts/. Terraform stays the provider-contract source of truth;
  olf contracts env keeps the exported variable names byte-identical.
- make <env>-up is now a full foundation+infra+artifacts wrapper (foundation
  apply is a Terraform no-op when the cluster exists); former behavior kept as
  make <env>-stack-up. All granular targets retained.
- CI gains a tooling job (ruff + pytest) and uv on the contracts/dbt jobs.
- Records ADR 0017; logs the bash check-*/e2e rewrite as follow-up debt.

Verified: check-structure, check-contracts, ruff, and 31 pytest pass;
contract-env and Floe-profile output diffed byte-identical against the
original scripts.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f2dbe1029e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/olf/olf/contracts.py Resolved
Comment thread tools/olf/olf/s3.py Resolved
Address two P1 review findings from the subprocess isolation of the new
contract resolver:

- olf contracts env resolved AWS_REGION during the pre-contract default pass
  (storage region still at the us-east-1 default) and never re-derived it once
  provider contracts set the real region. The old bash saw a shell-local
  AWS_REGION in-process; the uv subprocess cannot, so a cloud stack kept the
  stale us-east-1 and mis-targeted ECR. AWS_REGION/AWS_DEFAULT_REGION now
  follow the resolved storage region unless the caller exported them. Local
  output stays byte-identical (us-east-1 -> us-east-1).
- discover_runtime_manifests only globbed one directory down, but
  floe-manifest.sh persists the two-level <domain>/<product>/ layout, so direct
  AWS upload found nothing. It now recurses and takes the domain from the first
  path segment, matching the original find-based upload.

Tests updated (32 pass); local contract-env output diffed byte-identical
against the pre-refactor scripts.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: acc22378cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/contracts/load-runtime-env.sh Resolved
@malon64
malon64 merged commit 547d322 into main Jul 6, 2026
6 checks passed
@malon64
malon64 deleted the refactor/shared-python-deploy-tooling branch July 6, 2026 09:06

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff94225d6c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/lib/kube.sh
Comment on lines +95 to +100
if [[ "${status}" -eq 3 ]]; then
POLARIS_BOOTSTRAP_GENERATION="rebootstrap-$(date -u +%Y%m%d%H%M%S)"
cleanup_jobs_by_prefix "polaris-bootstrap-"
cleanup_jobs_by_prefix "openmetadata-bootstrap-"
cleanup_failed_jobs_by_prefix "openmetadata-polaris-refresh-"
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Propagate Polaris helper failures

When olf_run polaris check-credentials exits with any non-stale error (for example a uv/Python failure or an unexpected kubectl error), this function falls through the if [[ "${status}" -eq 3 ]] block and returns success, so local-infra-up/azure-infra-up continue as if the preflight passed. The helper already maps unreachable/unknown Polaris to exit 0 and stale credentials to 3, so other statuses should be returned; otherwise the stack can apply with an unchanged bootstrap generation after the credential check failed.

Useful? React with 👍 / 👎.

chouaibmouidis-py pushed a commit to chouaibmouidis-py/openlakeforge that referenced this pull request Nov 4, 2026
…penLakeForge#12)

* refactor: shared Python deploy tooling with shell CLI orchestration

Split the deploy pipeline by tool strength: shell keeps orchestrating the
CLIs (terraform, kubectl, helm, docker, dbt, floe, aws, az), while
cross-environment logic (REST/API calls, object-storage uploads, report
bundle manipulation, credential handling, contract parsing) moves into one
uv-managed Python package, tools/olf, exposed through the `olf` CLI.

- New olf subcommands replace duplicated/heredoc logic: contracts env,
  floe render-profile, artifacts upload-manifests, superset deploy/export,
  openmetadata deploy-metadata, k8s set-project-code-image, polaris
  check-credentials.
- Shared shell helpers deduped into scripts/lib/{common,helm,kube,python}.sh;
  the three env infra-up/deploy-artifacts scripts are now thin orchestrators.
- Env-neutral shell moved out of scripts/local: scripts/contracts/ and
  scripts/artifacts/. Terraform stays the provider-contract source of truth;
  olf contracts env keeps the exported variable names byte-identical.
- make <env>-up is now a full foundation+infra+artifacts wrapper (foundation
  apply is a Terraform no-op when the cluster exists); former behavior kept as
  make <env>-stack-up. All granular targets retained.
- CI gains a tooling job (ruff + pytest) and uv on the contracts/dbt jobs.
- Records ADR 0017; logs the bash check-*/e2e rewrite as follow-up debt.

Verified: check-structure, check-contracts, ruff, and 31 pytest pass;
contract-env and Floe-profile output diffed byte-identical against the
original scripts.

* fix: correct AWS region resolution and runtime manifest discovery

Address two P1 review findings from the subprocess isolation of the new
contract resolver:

- olf contracts env resolved AWS_REGION during the pre-contract default pass
  (storage region still at the us-east-1 default) and never re-derived it once
  provider contracts set the real region. The old bash saw a shell-local
  AWS_REGION in-process; the uv subprocess cannot, so a cloud stack kept the
  stale us-east-1 and mis-targeted ECR. AWS_REGION/AWS_DEFAULT_REGION now
  follow the resolved storage region unless the caller exported them. Local
  output stays byte-identical (us-east-1 -> us-east-1).
- discover_runtime_manifests only globbed one directory down, but
  floe-manifest.sh persists the two-level <domain>/<product>/ layout, so direct
  AWS upload found nothing. It now recurses and takes the domain from the first
  path segment, matching the original find-based upload.

Tests updated (32 pass); local contract-env output diffed byte-identical
against the pre-refactor scripts.

* fix(polaris): remove orphan helm release and bump floe to 0.6.6

---------

Co-authored-by: a.metwalli <alexis.metwalli_ext@sonepar.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant