:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(hobby): preserve shell variables during upgrade rendering (#104481)
Paul D'Ambrade73fff1a73a
diff --git a/.github/workflows/ci-hobby.yml b/.github/workflows/ci-hobby.ymlindex 54c97d9f8158..80de44242438 100644--- a/.github/workflows/ci-hobby.yml+++ b/.github/workflows/ci-hobby.yml@@ -85,6 +85,8 @@ jobs:- 'bin/hobby-ci-setup-user.py'- 'bin/hobby-ci.py'- 'bin/upgrade-hobby'+ - 'bin/helpers/render-hobby-compose.sh'+ - 'bin/test/test_render_hobby_compose.py'- 'bin/migrate-*-hobby'# Docker runtime (Dockerfile CMD chain)- 'bin/docker'@@ -122,6 +124,31 @@ jobs:core.setOutput('has_label', hasLabel.toString());core.setOutput('label_removed', labelRemoved.toString());+ upgrade-render-test:+ name: Test hobby upgrade rendering+ needs: changes+ if: ${{ !cancelled() && (needs.changes.outputs.should_run == 'true' || github.event_name == 'push' || github.event_name == 'schedule') }}+ runs-on: ubuntu-24.04+ timeout-minutes: 5+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ with:+ persist-credentials: false+ sparse-checkout: |+ bin/helpers/render-hobby-compose.sh+ bin/test/test_render_hobby_compose.py+ sparse-checkout-cone-mode: false+ - name: Install envsubst+ run: sudo apt-get update && sudo apt-get install -y gettext-base+ - name: Check upgrade rendering+ # Branches opened before the renderer landed have no test file yet; skip instead of failing discovery.+ run: |+ if [ ! -f bin/test/test_render_hobby_compose.py ]; then+ echo "Renderer test is not on this branch yet, skipping"+ exit 0+ fi+ python3 -m unittest discover -s bin/test -p test_render_hobby_compose.py+wait-for-docker-image:name: Wait for Docker image buildneeds: changesdiff --git a/bin/helpers/render-hobby-compose.sh b/bin/helpers/render-hobby-compose.shnew file mode 100755index 000000000000..28fcf847d8b7--- /dev/null+++ b/bin/helpers/render-hobby-compose.sh@@ -0,0 +1,5 @@+#!/usr/bin/env bash+set -euo pipefail++# Preserve Compose escapes and container shell variables during upgrade rendering.+envsubst '$DOMAIN $POSTHOG_SECRET $ENCRYPTION_SALT_KEYS $REGISTRY_URL $POSTHOG_APP_TAG $TLS_BLOCK'diff --git a/bin/test/test_render_hobby_compose.py b/bin/test/test_render_hobby_compose.pynew file mode 100644index 000000000000..a92cc4f1f66e--- /dev/null+++ b/bin/test/test_render_hobby_compose.py@@ -0,0 +1,50 @@+import os+import subprocess+from pathlib import Path++import unittest+++class TestRenderHobbyCompose(unittest.TestCase):+ def test_deployment_values_preserve_container_variables(self) -> None:+ renderer = Path(__file__).resolve().parents[1] / "helpers" / "render-hobby-compose.sh"+ deployment = {+ "DOMAIN": "example.com",+ "POSTHOG_SECRET": "example-secret",+ "ENCRYPTION_SALT_KEYS": "example-salt",+ "REGISTRY_URL": "example/posthog",+ "POSTHOG_APP_TAG": "example-tag",+ "TLS_BLOCK": "tls internal",+ }+ container_script = """TIMEOUT=60+ELAPSED=0+ELAPSED=$$((ELAPSED + 2))+[ $$ELAPSED -lt $$TIMEOUT ] || exit 1+TOPICS="example_events example_logs"+for topic in $$TOPICS; do+ printf '%s\n' "$$topic"+done+printf '%s\n' "$${ELAPSED}s"+"""+ deployment_template = "\n".join("${" + key + "}" for key in deployment) + "\n"+ compose_default = "${OPTIONAL_SETTING:-fallback}\n"+ for polluted in (False, True):+ with self.subTest(exported_container_variables=polluted):+ env = {"PATH": os.environ["PATH"], **deployment}+ if polluted:+ env.update(dict.fromkeys(("TOPICS", "topic", "ELAPSED", "TIMEOUT"), "unexpected"))+ rendered = subprocess.run(+ ["bash", str(renderer)],+ input=deployment_template + compose_default + container_script,+ text=True,+ capture_output=True,+ check=True,+ env=env,+ ).stdout+ self.assertEqual(+ rendered,+ "\n".join(deployment.values()) + "\n" + compose_default + container_script,+ )+ command = rendered.split(compose_default, 1)[1].replace("$$", "$")+ result = subprocess.run(["sh", "-c", command], text=True, capture_output=True, check=True, env=env)+ self.assertEqual(result.stdout.splitlines(), ["example_events", "example_logs", "2s"])diff --git a/bin/upgrade-hobby b/bin/upgrade-hobbyindex 3f0a34304b79..e9de28006f71 100755--- a/bin/upgrade-hobby+++ b/bin/upgrade-hobby@@ -126,6 +126,8 @@ if ! grep -q "ENCRYPTION_SALT_KEYS" .env; thenecho "ENCRYPTION_SALT_KEYS=$ENCRYPTION_KEY" >> .envecho "Added missing ENCRYPTION_SALT_KEYS to .env file"source .env+ # The earlier `set -a` is off by now, so the new key needs an explicit export to reach the Compose renderer.+ export ENCRYPTION_SALT_KEYSelse# Read the existing keyEXISTING_KEY=$(grep "ENCRYPTION_SALT_KEYS" .env | cut -d '=' -f2)@@ -355,7 +357,7 @@ rm -f docker-compose.ymlcp posthog/docker-compose.base.yml docker-compose.base.ymlcp posthog/docker-compose.hobby.yml docker-compose.yml.tmplcp posthog/.env.services .env.services-envsubst < docker-compose.yml.tmpl > docker-compose.yml+bash posthog/bin/helpers/render-hobby-compose.sh < docker-compose.yml.tmpl > docker-compose.ymlrm docker-compose.yml.tmpldocker-compose pulldiff --git a/docs/internal/hobby-minio-removal.md b/docs/internal/hobby-minio-removal.mdindex 741ea82c2607..b474b92233e3 100644--- a/docs/internal/hobby-minio-removal.md+++ b/docs/internal/hobby-minio-removal.md@@ -58,6 +58,13 @@ It picks that volume by name (`<project>_objectstorage`) and refuses to guess whIts preflight checks warn instead, whenever the legacy volume is still on the host, and ask you to confirm before the upgrade continues.The warning clears once you copy the objects across and delete the old volume.+## Upgrade rendering checks++The hobby smoke test starts the Go installer, which copies the Compose file directly.+It does not execute `bin/upgrade-hobby` or its environment substitution step.+The separate `Test hobby upgrade rendering` CI job exercises `bin/helpers/render-hobby-compose.sh`, which the upgrade script calls.+It checks that deployment values render while container shell variables and Compose defaults stay intact.+## Option 2: stay on your current versionAnswer `N` at the upgrade prompt.