OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
fix(self-hosting): doctor removes the obsolete compose `version` key
Carl-Gerhard Lindesvärde88e065ff6bf
diff --git a/self-hosting/cli/src/doctor/checks.ts b/self-hosting/cli/src/doctor/checks.tsindex 94cdbc985..89f63481c 100644--- a/self-hosting/cli/src/doctor/checks.ts+++ b/self-hosting/cli/src/doctor/checks.ts@@ -1,5 +1,12 @@import { randomBytes } from 'node:crypto';-import { type Document, isAlias, isMap, isSeq, parseDocument } from 'yaml';+import {+ type Document,+ isAlias,+ isMap,+ isNode,+ isSeq,+ parseDocument,+} from 'yaml';import { isNewer } from '../self-update';import {DEFAULT_EVENTS_TOPIC_PARTITIONS,@@ -616,6 +623,41 @@ export const caddyBullboardRedirect: Check = (install) => {};};+// The Compose spec dropped the top-level `version` key; Compose v2 warns about+// it on every command.+export const composeVersionKey: Check = (install) => {+ if (!install.compose.has('version')) {+ return null;+ }+ return {+ id: 'compose/version-key',+ severity: 'warn',+ title: 'docker-compose.yml has an obsolete top-level `version` key',+ detail: 'Docker Compose ignores it and prints a warning on every command.',+ fix: (target) => {+ const contents = target.compose.contents;+ if (!isMap(contents)) {+ return;+ }+ const removedKey = contents.items.find(+ (pair) => isNode(pair.key) && pair.key.toString() === 'version'+ )?.key;+ target.compose.delete('version');+ // The blank line and any comment that sat above `version` belong to+ // the new first key, not above it, or the written file never+ // round-trips identically and doctor keeps rewriting it.+ const firstKey = contents.items[0]?.key;+ if (!isNode(firstKey)) {+ return;+ }+ firstKey.spaceBefore = false;+ if (isNode(removedKey) && removedKey.commentBefore) {+ firstKey.commentBefore = removedKey.commentBefore;+ }+ },+ };+};+// Reminder, not a repair: surfaced only while the install still looks like it// predates Kafka (old worker image, or no Redpanda while using the bundled one).export const drainOldQueue: Check = (install) => {@@ -660,4 +702,5 @@ export const checks: Check[] = [enabledQueues,removedEnvVars,caddyBullboardRedirect,+ composeVersionKey,];diff --git a/self-hosting/cli/test/doctor-edge.test.ts b/self-hosting/cli/test/doctor-edge.test.tsindex 4f7d59f81..d3c8b76f4 100644--- a/self-hosting/cli/test/doctor-edge.test.ts+++ b/self-hosting/cli/test/doctor-edge.test.ts@@ -160,6 +160,16 @@ describe('env renames', () => {expect(env.has('BULLBOARD_USERNAME')).toBe(false);expect(env.has('BULLBOARD_PASSWORD')).toBe(false);});+});++describe('compose version key', () => {+ test('the obsolete top-level version key is removed', () => {+ const dir = v1Copy();+ expect(ids(dir)).toContain('compose/version-key');+ const compose = parseDocument(String(fixed(dir).compose)).toJS();+ expect(compose.version).toBeUndefined();+ expect(compose.services['op-api']).toBeDefined();+ });test('a missing API_URL is a manual step that suggests the bundled-Caddy address', () => {const dir = v1Copy();diff --git a/self-hosting/cli/test/doctor.test.ts b/self-hosting/cli/test/doctor.test.tsindex ac4125e7b..681b3f072 100644--- a/self-hosting/cli/test/doctor.test.ts+++ b/self-hosting/cli/test/doctor.test.ts@@ -39,6 +39,7 @@ describe('doctor on a v1 install', () => {'env/enabled-queues','env/removed-vars','caddy/bullboard-redirect',+ 'compose/version-key',]);});