diff --git a/.github/scripts/check_release_drift.js b/.github/scripts/check_release_drift.js index fb4e29e..6f257b9 100644 --- a/.github/scripts/check_release_drift.js +++ b/.github/scripts/check_release_drift.js @@ -1,73 +1,58 @@ #!/usr/bin/env node /** - * Fails the build when the site's fallback release drifts from the release the - * package repository actually mirrors. + * Fails the build when either of the site's fallback releases drifts from the + * release its package channel actually mirrors. * * The /packages page used to hardcode its versions, and they went stale: the * page still advertised 0.114-0 (and 0.113-0 for the repository examples) after - * v0.116-0 had been published and mirrored. The page now reads - * out/packages/release-info.json at runtime, but it still needs a compiled-in - * fallback for the first paint and for the case where that fetch fails - so the - * fallback can drift in exactly the same way, just less visibly. + * v0.116-0 had been published and mirrored. The page now reads each channel's + * release feed at runtime, but it still needs a compiled-in fallback for the + * first paint and for the case where that fetch fails - so the fallback can + * drift in exactly the same way, just less visibly. * - * This check closes that loop: whenever the deployment mirrors a release, the - * fallback baked into the bundle must name the same one. + * This check closes that loop: whenever the deployment mirrors the releases, + * each fallback baked into the bundle must name its channel's release. * - * Skipped when release-info.json is absent, which is the normal case for a - * site-only build (BUILD_PACKAGES=false, or any fork without the packaging - * secrets). There is nothing to compare against then. + * Skipped when neither feed exists, which is the normal case for a site-only + * build (BUILD_PACKAGES=false, or any fork without the packaging secrets). + * There is nothing to compare against then. */ const fs = require("node:fs"); const path = require("node:path"); -const releaseInfoPath = path.join(process.cwd(), "out", "packages", "release-info.json"); -const fallbackSourcePath = path.join(process.cwd(), "app", "lib", "releaseInfo.ts"); +// Mirrors releaseInfoPaths in app/lib/releaseInfo.ts. +const channels = [ + { channel: "latest", feed: path.join("out", "packages", "release-info-latest.json") }, + { channel: "stable", feed: path.join("out", "packages", "release-info.json") }, +]; +const fallbackSourcePath = path.join("app", "lib", "releaseInfo.ts"); -if (!fs.existsSync(releaseInfoPath)) { - console.log(`No ${path.relative(process.cwd(), releaseInfoPath)}; skipping release drift check.`); +const present = channels.filter(({ feed }) => fs.existsSync(feed)); +if (present.length === 0) { + console.log("No release feeds in out/packages; skipping release drift check."); process.exit(0); } +// A deploy mirrors both channels, so a lone feed means the other channel was not built. +if (present.length !== channels.length) { + const missing = channels.filter((entry) => !present.includes(entry)).map(({ feed }) => feed); + console.error(`Release drift: ${missing.join(", ")} is missing; cannot verify every fallback release.`); + process.exit(1); +} const source = fs.readFileSync(fallbackSourcePath, "utf8"); +const fallbacks = source.slice(source.indexOf("export const FALLBACK_RELEASES")); -/** Reads a string field out of the FALLBACK_RELEASE object literal. */ -function fallbackField(field) { - const match = new RegExp(`${field}:\\s*"([^"]+)"`).exec(source); +/** Reads a string field out of FALLBACK_RELEASES[channel]. */ +function fallbackField(channel, field) { + const entry = new RegExp(`\\b${channel}:\\s*\\{([^}]*)\\}`).exec(fallbacks); + const match = entry && new RegExp(`\\b${field}:\\s*"([^"]+)"`).exec(entry[1]); return match ? match[1] : null; } -const mirrored = JSON.parse(fs.readFileSync(releaseInfoPath, "utf8")); -const mirroredTag = mirrored.tag_name; -if (typeof mirroredTag !== "string" || mirroredTag.length === 0) { - console.error("release-info.json has no tag_name; cannot verify the site's fallback release."); - process.exit(1); -} - -const fallbackTag = fallbackField("tagName"); -if (fallbackTag !== mirroredTag) { - console.error( - [ - "Release drift: the site's fallback release does not match the mirrored release.", - "", - ` mirrored (out/packages/release-info.json): ${mirroredTag}`, - ` fallback (app/lib/releaseInfo.ts): ${fallbackTag ?? ""}`, - "", - "Update FALLBACK_RELEASE in app/lib/releaseInfo.ts to the mirrored release.", - "It is what visitors see before the release feed loads, and permanently if", - "that fetch fails.", - ].join("\n"), - ); - process.exit(1); -} - // The version strings are derived from real asset filenames, so a mismatch here // means the fallback would render install commands for packages the release // does not contain. -const assetNames = Array.isArray(mirrored.assets) - ? mirrored.assets.map((asset) => asset && asset.name).filter((name) => typeof name === "string") - : []; - const derived = [ { field: "aptVersion", @@ -84,26 +69,60 @@ const derived = [ ]; let failed = false; -for (const { field, pattern } of derived) { - const actual = assetNames.map((name) => pattern.exec(name)).find((m) => m && m[1]); - if (!actual) { - // The release simply does not ship that package shape; the fallback keeps - // whatever it had, which is not drift. +for (const { channel, feed } of channels) { + const mirrored = JSON.parse(fs.readFileSync(feed, "utf8")); + const mirroredTag = mirrored.tag_name; + if (typeof mirroredTag !== "string" || mirroredTag.length === 0) { + console.error(`${feed} has no tag_name; cannot verify the ${channel} fallback release.`); + failed = true; continue; } - const expected = actual[1]; - const declared = fallbackField(field); - if (declared !== expected) { + + const fallbackTag = fallbackField(channel, "tagName"); + if (fallbackTag !== mirroredTag) { console.error( - `Release drift: FALLBACK_RELEASE.${field} is "${declared}" but ${mirroredTag} ships "${expected}".`, + [ + `Release drift: the site's ${channel} fallback release does not match the mirrored release.`, + "", + ` mirrored (${feed}): ${mirroredTag}`, + ` fallback (FALLBACK_RELEASES.${channel}): ${fallbackTag ?? ""}`, + "", + ].join("\n"), ); failed = true; + continue; + } + + const assetNames = Array.isArray(mirrored.assets) + ? mirrored.assets.map((asset) => asset && asset.name).filter((name) => typeof name === "string") + : []; + let channelFailed = false; + for (const { field, pattern } of derived) { + const actual = assetNames.map((name) => pattern.exec(name)).find((m) => m && m[1]); + if (!actual) { + // The release simply does not ship that package shape; the fallback keeps + // whatever it had, which is not drift. + continue; + } + const expected = actual[1]; + const declared = fallbackField(channel, field); + if (declared !== expected) { + console.error( + `Release drift: FALLBACK_RELEASES.${channel}.${field} is "${declared}" but ${mirroredTag} ships "${expected}".`, + ); + channelFailed = true; + } + } + failed ||= channelFailed; + if (!channelFailed) { + console.log(`The ${channel} fallback matches the mirrored release (${mirroredTag}).`); } } if (failed) { - console.error("\nUpdate FALLBACK_RELEASE in app/lib/releaseInfo.ts."); + console.error( + "\nUpdate FALLBACK_RELEASES in app/lib/releaseInfo.ts. It is what visitors see before the\n" + + "release feeds load, and permanently if a fetch fails.", + ); process.exit(1); } - -console.log(`Release fallback matches the mirrored release (${mirroredTag}).`); diff --git a/PACKAGE-INSTALL.md b/PACKAGE-INSTALL.md index 334fd55..dbcefe6 100644 --- a/PACKAGE-INSTALL.md +++ b/PACKAGE-INSTALL.md @@ -2,7 +2,7 @@ Repository-backed installation commands for DocumentDB. -> The `stable` channel serves v1.0-0; see [Release channels](#release-channels). +> The `latest` channel serves v1.2-0 and `stable` serves v1.0-0; see [Release channels](#release-channels). ## Clean-host installer @@ -13,10 +13,22 @@ curl -fsSLo documentdb-install.sh https://documentdb.io/install.sh && sudo sh documentdb-install.sh ``` -This installs v1.0-0 from this repository on PostgreSQL 18; add `--pg-major 17` -for 17. On a host where DocumentDB is already set up, it only reports that instance's status -and doesn't upgrade it; to move an existing install to 1.0, see -[Upgrading an existing install](#upgrading-an-existing-install). +This installs v1.2-0 from the `latest` channel on PostgreSQL 18; add `--pg-major 17` for 17. +The host keeps that channel, so `apt upgrade` and `dnf upgrade` follow `latest` to new releases. +To choose another release, add one option: + +- `--stable`: the `stable` channel (v1.0-0), with the same repository definition the 1.0 + installer wrote. +- `--version 1.0.0`: exactly that release (1.0.0 or later; `1.2` means `1.2.0`), downloaded from + its GitHub release and checked against its `SHA256SUMS`. No DocumentDB repository is + configured, so the package manager never upgrades it. + +The installer only sets up new installs: on a host where DocumentDB is already installed it +changes no packages. To move an existing install to a newer release, see +[Upgrading an existing install](#upgrading-an-existing-install). A host whose DocumentDB +repository file is the other channel's is refused, not rewritten: rerun with the matching option, +or remove `/etc/apt/sources.list.d/documentdb.list` or `/etc/yum.repos.d/documentdb.repo` to +switch. The site serves the `install.sh` attached to the release named in `scripts/publish-installer.mjs`, and the build fails if its SHA256 changes. @@ -24,15 +36,16 @@ The site serves the `install.sh` attached to the release named in ## Release channels The repository publishes two channels, each signed with the same key and listing only its own -release's packages. The commands on this page use `stable`. +release's packages. The commands on this page use `latest`. | Channel | Release | APT source | DNF `baseurl` | |---|---|---|---| +| `latest` | v1.2-0 | `https://documentdb.io/deb latest ubuntu24` | `https://documentdb.io/rpm/latest/rhel9` | | `stable` | v1.0-0 | `https://documentdb.io/deb stable ubuntu24` | `https://documentdb.io/rpm/rhel9` | -| `latest` | the newest release | `https://documentdb.io/deb latest ubuntu24` | `https://documentdb.io/rpm/latest/rhel9` | -Release metadata is at `https://documentdb.io/packages/release-info.json` for `stable` and -`https://documentdb.io/packages/release-info-latest.json` for `latest`. +`stable` takes new releases later than `latest`. Release metadata is at +`https://documentdb.io/packages/release-info-latest.json` for `latest` and +`https://documentdb.io/packages/release-info.json` for `stable`. ## What is published @@ -91,6 +104,9 @@ release tag. Those paths are not part of the current hosted support matrix. This is the recommended path. It installs the whole stack and brings up a working wire-protocol endpoint. +These commands use the `latest` channel. For `stable` (v1.0-0), write `stable` in place of +`latest` in the DocumentDB APT line, or use `baseurl=https://documentdb.io/rpm/rhel9` on EL9. + > These commands assume a regular Linux host where you use `sudo`. In a clean container that > already runs as `root`, omit `sudo`, and on Debian/Ubuntu also > `export DEBIAN_FRONTEND=noninteractive` first, or `tzdata` will hang the install with an @@ -104,7 +120,7 @@ sudo apt install -y curl ca-certificates gnupg && \ curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor --yes -o /usr/share/keyrings/postgresql.gpg && \ echo "deb [signed-by=/usr/share/keyrings/postgresql.gpg] https://apt.postgresql.org/pub/repos/apt noble-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list >/dev/null && \ curl -fsSL https://documentdb.io/documentdb-archive-keyring.gpg | sudo gpg --dearmor --yes -o /usr/share/keyrings/documentdb-archive-keyring.gpg && \ -echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/documentdb-archive-keyring.gpg] https://documentdb.io/deb stable ubuntu24" | sudo tee /etc/apt/sources.list.d/documentdb.list >/dev/null && \ +echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/documentdb-archive-keyring.gpg] https://documentdb.io/deb latest ubuntu24" | sudo tee /etc/apt/sources.list.d/documentdb.list >/dev/null && \ sudo apt update && \ sudo apt install -y documentdb ``` @@ -127,7 +143,7 @@ sudo rpm --import https://documentdb.io/documentdb-archive-keyring.gpg && \ printf '%s\n' \ '[documentdb]' \ 'name=DocumentDB Repository' \ - 'baseurl=https://documentdb.io/rpm/rhel9' \ + 'baseurl=https://documentdb.io/rpm/latest/rhel9' \ 'enabled=1' \ 'gpgcheck=1' \ 'gpgkey=https://documentdb.io/documentdb-archive-keyring.gpg' | sudo tee /etc/yum.repos.d/documentdb.repo >/dev/null && \ @@ -148,7 +164,7 @@ sudo rpm --import https://documentdb.io/documentdb-archive-keyring.gpg && \ printf '%s\n' \ '[documentdb]' \ 'name=DocumentDB Repository' \ - 'baseurl=https://documentdb.io/rpm/rhel9' \ + 'baseurl=https://documentdb.io/rpm/latest/rhel9' \ 'enabled=1' \ 'gpgcheck=1' \ 'gpgkey=https://documentdb.io/documentdb-archive-keyring.gpg' | sudo tee /etc/yum.repos.d/documentdb.repo >/dev/null && \ @@ -238,7 +254,7 @@ Before using this anywhere but a private machine: ```bash sudo documentdb-setup --status # gateway listener, service states, resolved paths -documentdb-gateway --version # DocumentDB version (1.0.0) +documentdb-gateway --version # DocumentDB version (1.2.0 on latest) dpkg -l | grep documentdb # or: rpm -qa | grep documentdb ``` @@ -381,7 +397,8 @@ The current release publishes PostgreSQL 17 and 18. Install `documentdb-17` or ## Upgrading an existing install -Package installs from v0.116 or v0.117 upgrade in place to 1.0. Move the entire stack +Package installs from v0.116 or v0.117 upgrade in place to 1.0 from the `stable` channel; to +take a 1.0.0 install to 1.2, [switch it to `latest`](#switch-from-stable-to-latest). Move the entire stack together; upgrading only `postgresql-N-documentdb` does not update the gateway, tools, common payload, or `documentdb-N`. These steps use systemd; upgrading a host without it isn't covered here. On a package-managed private PostgreSQL 18 instance: @@ -465,8 +482,40 @@ Confirm afterwards with: SELECT extname, extversion FROM pg_extension WHERE extname LIKE 'documentdb%'; ``` +## Switch from `stable` to `latest` + +`stable` still serves 1.0.0 and takes new releases later than `latest`, which serves 1.2. To move a +1.0.0 install to 1.2 now, point its one repository file at `latest` and upgrade the packages. +This is one-way: 1.0 does not run correctly on data that 1.2 has updated, so back up the data +directory first. + +```bash +# Debian / Ubuntu +sudo sed -i 's/ stable ubuntu24$/ latest ubuntu24/' /etc/apt/sources.list.d/documentdb.list && +sudo apt update && +sudo apt upgrade + +# EL9: use this instead of the apt commands above +sudo sed -i 's|/rpm/rhel9$|/rpm/latest/rhel9|' /etc/yum.repos.d/documentdb.repo && +sudo dnf upgrade +``` + +Then re-run setup with the PostgreSQL major, plus any `--data-dir` or `--pg-port` you installed +with. It restarts PostgreSQL once to load the new libraries, updates the extensions, and starts the +gateway; without `--admin-user` it keeps every admin user and password: + +```bash +sudo documentdb-setup --pg-version 18 --yes +``` + +For an adopted PostgreSQL instance, run `sudo documentdb-setup --target-postgres-instance 18/main --yes` +(with your cluster name) instead, then the restart and setup commands it prints. + ## Version pinning +Each channel lists only its own release. To install one exact release that the package manager +never upgrades, use the installer's `--version` option instead. + Run the repository setup for your distro first, then: ### APT @@ -492,17 +541,17 @@ published in the documentdb.io package repositories. Community builds are welcom For example, after checking out the matching release tag, build an extension package with: ```bash -./packaging/build_packages.sh --os deb12 --pg 16 --version 1.0.0 +./packaging/build_packages.sh --os deb12 --pg 16 --version 1.2.0 ``` -`v1.0-0` and `v1.0-RC2` are on the same commit, so pass `--version`; without it the scripts can build RC-versioned packages. That command builds only `postgresql-N-documentdb`. A custom full-stack package set uses +Without `--version`, the script takes the version from the checked-out release tag, or else from the control file; at `v1.2-0` both give 1.2.0. That command builds only `postgresql-N-documentdb`. A custom full-stack package set uses three entry points: - `packaging/build_packages.sh` — PostgreSQL extension - `packaging/gateway/build_gateway_packages.sh` — wire-protocol gateway - `packaging/build_extra_packages.sh` — tools, common payload, `documentdb-N`, and meta package -The [v1.0 packaging guide](https://github.com/documentdb/documentdb/blob/v1.0-0/packaging/README.md) +The [v1.2 packaging guide](https://github.com/documentdb/documentdb/blob/v1.2-0/packaging/README.md) documents their required arguments, version formats, prerequisites, and accepted targets. PostgreSQL 15 remains extension-only for package-managed installs because the setup tools require PostgreSQL 16 or newer. @@ -517,9 +566,9 @@ they do not retain packages from older releases. Examples: ```text -ubuntu24.04-documentdb_1.0.0_all.deb -ubuntu24.04-postgresql-18-documentdb_1.0-0_amd64.deb -rhel9-postgresql18-documentdb-1.0.0-1.el9.x86_64.rpm +ubuntu24.04-documentdb_1.2.0_all.deb +ubuntu24.04-postgresql-18-documentdb_1.2-0_amd64.deb +rhel9-postgresql18-documentdb-1.2.0-1.el9.x86_64.rpm ``` For a full stack, pass the five packages for the selected PostgreSQL major to one command: @@ -531,10 +580,12 @@ dependencies are not included still fails. Alternatively, use the repository-bac above. - GitHub Releases: https://github.com/documentdb/documentdb/releases -- Release metadata: https://documentdb.io/packages/release-info.json +- Release metadata: https://documentdb.io/packages/release-info-latest.json (`latest`), + https://documentdb.io/packages/release-info.json (`stable`) ## Notes -- The current release publishes the `ubuntu24` APT component and the `rpm/rhel9` repository. +- Each channel publishes the `ubuntu24` APT component and an `rhel9` RPM repository + (`rpm/latest/rhel9` and `rpm/rhel9`). - The RPM flow depends on EPEL plus PostgreSQL's upstream RPM repository because DocumentDB depends on PostgreSQL, `pg_cron`, `pgvector`, PostGIS, and `rum` for PostgreSQL 17. - On Debian/Ubuntu, the distro-packaged `cargo` can be older than the current gateway workspace lockfile. `rustup` avoids that mismatch. diff --git a/app/lib/packageInstall.ts b/app/lib/packageInstall.ts index 4cfaafb..21ace6a 100644 --- a/app/lib/packageInstall.ts +++ b/app/lib/packageInstall.ts @@ -1,3 +1,5 @@ +import type { ReleaseChannel } from "./releaseInfo"; + export type AptDistro = "ubuntu24"; export type RpmDistro = "rocky9" | "rhel9"; export type AptArch = "amd64" | "arm64" | "auto"; @@ -32,6 +34,12 @@ const rpmRepositoryPaths: Record = { rhel9: "rhel9", }; +// stable keeps the paths it had before channels existed; install.sh recognises exactly these definitions. +const rpmChannelPrefixes: Record = { + latest: "latest/", + stable: "", +}; + // The website mirrors the official release's Tier-1 package matrix exactly. export const aptFullStackDistros: readonly AptDistro[] = ["ubuntu24"]; export const rpmFullStackDistros: readonly RpmDistro[] = ["rocky9", "rhel9"]; @@ -62,6 +70,7 @@ export function buildAptInstallCommand( aptTarget: AptDistro, aptArch: AptArch, aptPgVersion: AptPgVersion, + channel: ReleaseChannel = "latest", ): string { const pgdgSuite = aptPgdgSuites[aptTarget]; // "auto" resolves the architecture on the host running the command, so a @@ -80,7 +89,7 @@ sudo apt install -y curl ca-certificates gnupg && \\ curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor --yes -o /usr/share/keyrings/postgresql.gpg && \\ echo "deb [signed-by=/usr/share/keyrings/postgresql.gpg] https://apt.postgresql.org/pub/repos/apt ${pgdgSuite}-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list >/dev/null && \\ curl -fsSL https://documentdb.io/documentdb-archive-keyring.gpg | sudo gpg --dearmor --yes -o /usr/share/keyrings/documentdb-archive-keyring.gpg && \\ -echo "deb [arch=${arch} signed-by=/usr/share/keyrings/documentdb-archive-keyring.gpg] https://documentdb.io/deb stable ${aptTarget}" | sudo tee /etc/apt/sources.list.d/documentdb.list >/dev/null && \\ +echo "deb [arch=${arch} signed-by=/usr/share/keyrings/documentdb-archive-keyring.gpg] https://documentdb.io/deb ${channel} ${aptTarget}" | sudo tee /etc/apt/sources.list.d/documentdb.list >/dev/null && \\ sudo apt update && \\ sudo apt install -y ${installTarget}`; } @@ -89,9 +98,10 @@ export function buildRpmInstallCommand( rpmTarget: RpmDistro, rpmArch: RpmArch, rpmPgVersion: RpmPgVersion, + channel: ReleaseChannel = "latest", ): string { const rhelMajorVersion = rpmMajorVersions[rpmTarget]; - const repositoryPath = rpmRepositoryPaths[rpmTarget]; + const repositoryPath = `${rpmChannelPrefixes[channel]}${rpmRepositoryPaths[rpmTarget]}`; // See buildAptInstallCommand: "auto" resolves on the host so one published // example works on x86_64 and aarch64 alike. const arch = rpmArch === "auto" ? "$(uname -m)" : rpmArch; diff --git a/app/lib/releaseInfo.ts b/app/lib/releaseInfo.ts index 52e45f6..b1daa37 100644 --- a/app/lib/releaseInfo.ts +++ b/app/lib/releaseInfo.ts @@ -2,10 +2,10 @@ import { useEffect, useState } from "react"; -// The site publishes out/packages/release-info.json on every deployment, built -// from the GitHub release the package repository actually mirrors. It is the +// The site publishes one release feed per package channel on every deployment, +// built from the GitHub release that channel actually mirrors. They are the // only authoritative statement of "what version is on documentdb.io", so the -// UI derives its version strings from it rather than repeating them. +// UI derives its version strings from them rather than repeating them. // // Before this module the versions were hardcoded in the page, and they drifted: // the page still advertised 0.114-0 (and 0.113-0 for the repository examples) @@ -34,15 +34,34 @@ export type ReleaseInfo = { assetNames: readonly string[]; }; -// A reference release, not evidence of current repository availability. -export const FALLBACK_RELEASE: ReleaseInfo = { - tagName: "v1.0-0", - aptVersion: "1.0-0", - rpmVersion: "1.0.0-1.el9", - metaVersion: "1.0.0", - metaRpmVersion: "1.0.0-1", - releaseUrl: "https://github.com/documentdb/documentdb/releases/tag/v1.0-0", - assetNames: [], +export type ReleaseChannel = "latest" | "stable"; + +// stable kept the feed path it had before channels existed. +export const releaseInfoPaths: Record = { + latest: "/packages/release-info-latest.json", + stable: "/packages/release-info.json", +}; + +// Reference releases, not evidence of availability; check_release_drift.js parses these literals. +export const FALLBACK_RELEASES: Record = { + latest: { + tagName: "v1.2-0", + aptVersion: "1.2-0", + rpmVersion: "1.2.0-1.el9", + metaVersion: "1.2.0", + metaRpmVersion: "1.2.0-1", + releaseUrl: "https://github.com/documentdb/documentdb/releases/tag/v1.2-0", + assetNames: [], + }, + stable: { + tagName: "v1.0-0", + aptVersion: "1.0-0", + rpmVersion: "1.0.0-1.el9", + metaVersion: "1.0.0", + metaRpmVersion: "1.0.0-1", + releaseUrl: "https://github.com/documentdb/documentdb/releases/tag/v1.0-0", + assetNames: [], + }, }; type RawReleaseInfo = { @@ -126,9 +145,9 @@ export type ReleaseState = { error: string | null; }; -export function useReleaseInfo(): ReleaseState { +export function useReleaseInfo(channel: ReleaseChannel): ReleaseState { const [state, setState] = useState({ - release: FALLBACK_RELEASE, + release: FALLBACK_RELEASES[channel], status: "loading", error: null, }); @@ -139,7 +158,7 @@ export function useReleaseInfo(): ReleaseState { const controller = new AbortController(); const timeout = window.setTimeout(() => controller.abort(), 15000); - fetch(`${basePath}/packages/release-info.json`, { signal: controller.signal }) + fetch(`${basePath}${releaseInfoPaths[channel]}`, { signal: controller.signal }) .then((response) => { if (!response.ok) { throw new Error(`Release metadata is unavailable (HTTP ${response.status}).`); @@ -154,7 +173,7 @@ export function useReleaseInfo(): ReleaseState { .catch((error: unknown) => { if (!cancelled) { setState({ - release: FALLBACK_RELEASE, + release: FALLBACK_RELEASES[channel], status: "fallback", error: error instanceof Error && error.name !== "AbortError" ? error.message @@ -169,7 +188,7 @@ export function useReleaseInfo(): ReleaseState { window.clearTimeout(timeout); controller.abort(); }; - }, []); + }, [channel]); return state; } diff --git a/app/packages/page.tsx b/app/packages/page.tsx index 2857316..0386220 100644 --- a/app/packages/page.tsx +++ b/app/packages/page.tsx @@ -70,7 +70,9 @@ function InstallLocation({ onChange }: { onChange: (result: SelectionResult) => } export default function PackagesPage() { - const { release, status: releaseStatus, error: releaseError } = useReleaseInfo(); + // The commands install from latest; stable is only named beside them. + const { release, status: releaseStatus, error: releaseError } = useReleaseInfo("latest"); + const { release: stableRelease } = useReleaseInfo("stable"); const [state, setState] = useState(null); const [dockerSetup, setDockerSetup] = useState("command"); @@ -217,7 +219,7 @@ export default function PackagesPage() {

Cannot confirm the current repository release. {releaseError}

- The commands below install the latest packages from the repository. Last known + The commands below install from the latest channel. Last known release: {release.tagName}.{" "} Browse release assets{" "} or . @@ -238,10 +240,25 @@ export default function PackagesPage() { )}

1. Install

-

Adds the PostgreSQL and DocumentDB repositories (plus EPEL and CRB on EL9), then installs PostgreSQL, the extension, and the gateway.

+

Adds the PostgreSQL repository and the DocumentDB latest channel (plus EPEL and CRB on EL9), then installs PostgreSQL, the extension, and the gateway.

{canInstall ? : (

No command is shown for this selection.

)} + {canInstall && ( +

+ latest serves {release.tagName}, and{" "} + {family === "apt" ? "apt upgrade" : "dnf upgrade"} follows it to + new releases. For stable ({stableRelease.tagName}),{" "} + {family === "apt" ? ( + <>write stable in place of latest in the DocumentDB line. + ) : ( + <>use baseurl=https://documentdb.io/rpm/rhel9. + )}{" "} + For one release that is never upgraded, use the{" "} + installer with{" "} + --version. +

+ )} {family === "apt" && (

In a clean Ubuntu container as root, run{" "} diff --git a/app/services/articleService.ts b/app/services/articleService.ts index 8f07f28..a7956cf 100644 --- a/app/services/articleService.ts +++ b/app/services/articleService.ts @@ -73,7 +73,7 @@ ${documentdbLocalTelemetryNote} > \`--init-data true\` seeds the built-in sample data into \`StoreData\`, which the > verification step below queries. It is **not** enabled by default — without it the > container starts with no \`StoreData\` database and \`use StoreData\` returns nothing. The data is -> seeded once per data volume. Existing volumes are not migrated automatically; +> seeded once per data volume. Existing volumes keep the sample data they were seeded with; > re-create the volume to seed again. See > [DocumentDB Local](/docs/documentdb-local) for \`--init-data-path\`, certificate setup, > and additional runtime options. @@ -161,10 +161,13 @@ Until you remove it, re-running \`docker run --name documentdb\` fails with \`Conflict. The container name "/documentdb" is already in use\`. Mount a named volume (\`-v documentdb-data:/data\`) before storing anything you want to keep. -A newer image on an existing data volume does not update the DocumentDB schema in that -volume ([documentdb#773](https://github.com/documentdb/documentdb/issues/773)). To move data -from an earlier release or a 1.0 release candidate to 1.0, start the 1.0 image on a new -volume and reload your data, for example with \`mongodump\` and \`mongorestore\`. +From 1.2, the image updates the DocumentDB extensions on an existing 1.0 or later data volume +when it starts, and logs \`Updating the DocumentDB extensions on this data volume\`. If the +update fails, it is rolled back and the container exits with the volume unchanged. This only +goes forward: an older image starts on the updated volume, but some commands then fail, so back +up the volume first if you may need to go back. To move data from a release before 1.0 or a 1.0 +release candidate, start the image on a new volume and reload your data, for example with +\`mongodump\` and \`mongorestore\`. ## Troubleshooting and debugging @@ -196,10 +199,10 @@ The current official release publishes the full stack — extension, gateway, se **Recommended:** install the complete stack, then create a new private PostgreSQL 18 instance. The commands detect architecture on the Linux host where you run them. For containers or macOS/Windows evaluation, choose [Docker installation](/packages?method=docker). > [!IMPORTANT] -> Already running v0.116 or v0.117 from packages? Follow [Upgrading](/docs/linux-packages#upgrading) instead of installing again. Hosts that ran a 1.0 release candidate have no upgrade path; use a clean host. Removing packages preserves database files; reinstalling is not a data reset. +> Already running DocumentDB from packages? Follow [Upgrading](/docs/linux-packages#upgrading) instead of installing again. Hosts that ran a 1.0 release candidate have no upgrade path; use a clean host. Removing packages preserves database files; reinstalling is not a data reset. > [!NOTE] -> Need another distribution or PostgreSQL major? We welcome community builds. Check out the \`v1.0-0\` tag, pass \`--version 1.0.0\`, and use the version-parameterized [packaging scripts](https://github.com/documentdb/documentdb/blob/v1.0-0/packaging/README.md). \`build_packages.sh\` builds the extension, \`gateway/build_gateway_packages.sh\` builds the gateway, and \`build_extra_packages.sh\` builds the common, tools, stand-alone, and meta packages. PostgreSQL 15 is extension-only because the setup tools require PostgreSQL 16 or newer. These builds are on demand and are not official release assets hosted by documentdb.io. +> Need another distribution or PostgreSQL major? We welcome community builds. Check out the \`v1.2-0\` tag, pass \`--version 1.2.0\`, and use the version-parameterized [packaging scripts](https://github.com/documentdb/documentdb/blob/v1.2-0/packaging/README.md). \`build_packages.sh\` builds the extension, \`gateway/build_gateway_packages.sh\` builds the gateway, and \`build_extra_packages.sh\` builds the common, tools, stand-alone, and meta packages. PostgreSQL 15 is extension-only because the setup tools require PostgreSQL 16 or newer. These builds are on demand and are not official release assets hosted by documentdb.io. You do not need PostgreSQL already installed — the setup wizard creates and manages its own instance. The install does add the PGDG repository and pull PostgreSQL, PostGIS and around 160 packages (about 140 MB), so pick a host you are willing to have PGDG on. @@ -212,11 +215,17 @@ curl -fsSLo documentdb-install.sh https://documentdb.io/install.sh && sudo sh documentdb-install.sh \`\`\` -This installs the current release (v1.0-0) from the package repository on PostgreSQL 18; add \`--pg-major 17\` for 17. -On a host where DocumentDB is already set up, the installer only reports its status and doesn't upgrade it; to move an existing install to 1.0, follow [Upgrading](/docs/linux-packages#upgrading). +This installs the current release (v1.2-0) from the \`latest\` channel of the package repository, on PostgreSQL 18; add \`--pg-major 17\` for 17. The host keeps that channel, so \`apt upgrade\` and \`dnf upgrade\` follow \`latest\` to new releases. To choose another release, add one option: + +- \`--stable\`: the \`stable\` channel, which serves v1.0-0 and takes new releases later than \`latest\`. +- \`--version 1.0.0\`: exactly that release (1.0.0 or later), downloaded from its GitHub release. No DocumentDB repository is configured, so the package manager never upgrades it. + +The installer only sets up new installs: on a host where DocumentDB is already installed it changes no packages. To move an existing install to a newer release, follow [Upgrading](/docs/linux-packages#upgrading). ## Install +These commands use the \`latest\` channel. For \`stable\` (v1.0-0), write \`stable\` in place of \`latest\` in the DocumentDB APT line, or use \`baseurl=https://documentdb.io/rpm/rhel9\` on EL9. + ### Ubuntu 24.04, PostgreSQL 18 (APT) \`\`\`bash @@ -417,7 +426,7 @@ Use the extension package for your PostgreSQL major: \`postgresql-N-documentdb\` or \`postgresqlN-documentdb\` on EL9. You own PostgreSQL configuration, extension activation, and service restarts. Create \`documentdb_extended_rum\` as well as \`documentdb\`: \`CREATE EXTENSION documentdb CASCADE\` does not pull it in, and without it every index -creation fails. Follow the matching release's [manual package instructions](https://github.com/documentdb/documentdb/blob/v1.0-0/packaging/README.md), +creation fails. Follow the matching release's [manual package instructions](https://github.com/documentdb/documentdb/blob/v1.2-0/packaging/README.md), or the [extension-only offline instructions](/docs/linux-packages/offline#smaller-offline-cases) when PostgreSQL and all extension dependencies are already installed. @@ -438,7 +447,8 @@ For an adopted instance, use the operator's existing PostgreSQL connection inste ## Upgrading -Package installs from v0.116 or v0.117 upgrade in place to 1.0. Move the entire stack +Package installs from v0.116 or v0.117 upgrade in place to 1.0 from the \`stable\` channel; to +take a 1.0.0 install to 1.2, [switch it to \`latest\`](#switch-from-stable-to-latest). Move the entire stack together; upgrading only \`postgresql-N-documentdb\` does not update the gateway, tools, common payload, or \`documentdb-N\`. These steps use systemd; upgrading a host without it isn't covered here. On a package-managed private PostgreSQL 18 instance: @@ -518,6 +528,35 @@ updates the extensions and then starts the gateway. If setup has to change \`shared_preload_libraries\`, it exits without updating the extensions: restart PostgreSQL and run it once more. By hand, use that instance's own \`psql\` connection. +## Switch from \`stable\` to \`latest\` + +\`stable\` still serves 1.0.0 and takes new releases later than \`latest\`, which serves 1.2. To move a +1.0.0 install to 1.2 now, point its one repository file at \`latest\` and upgrade the packages. +This is one-way: 1.0 does not run correctly on data that 1.2 has updated, so back up the data +directory first. + +\`\`\`bash +# Debian / Ubuntu +sudo sed -i 's/ stable ubuntu24$/ latest ubuntu24/' /etc/apt/sources.list.d/documentdb.list && +sudo apt update && +sudo apt upgrade + +# EL9: use this instead of the apt commands above +sudo sed -i 's|/rpm/rhel9$|/rpm/latest/rhel9|' /etc/yum.repos.d/documentdb.repo && +sudo dnf upgrade +\`\`\` + +Then re-run setup with the PostgreSQL major, plus any \`--data-dir\` or \`--pg-port\` you installed +with. It restarts PostgreSQL once to load the new libraries, updates the extensions, and starts the +gateway; without \`--admin-user\` it keeps every admin user and password: + +\`\`\`bash +sudo documentdb-setup --pg-version 18 --yes +\`\`\` + +For an adopted PostgreSQL instance, run \`sudo documentdb-setup --target-postgres-instance 18/main --yes\` +(with your cluster name) instead, then the restart and setup commands it prints. + ## Remove or reset ### Greenfield: destroy the package-managed instance @@ -699,7 +738,7 @@ Then continue with [Set up and connect](/docs/getting-started/packages#set-up-an If the target already has PostgreSQL, the PGDG extension dependencies (\`postgresql-N-cron\`, \`-pgvector\`, \`-postgis-3\`) and \`jq\`, you do not need a bundle: -- **Extension only, one file** — \`sudo apt install ./ubuntu24.04-postgresql-18-documentdb_1.0-0_amd64.deb\`. No gateway and no \`documentdb-setup\`. +- **Extension only, one file** — \`sudo apt install ./ubuntu24.04-postgresql-18-documentdb_1.2-0_amd64.deb\`. No gateway and no \`documentdb-setup\`. - **Full stack from the release assets** — pass the five packages for the selected PostgreSQL major to a *single* \`apt install\` / \`dnf install\`: \`documentdb-N\`, the matching \`postgresql-N-documentdb\` / \`postgresqlN-documentdb\` extension, \`documentdb-common\`, \`documentdb-gateway\`, and \`documentdb-postgresql-tools\`. For PostgreSQL 18 only, the optional \`documentdb\` meta package may be included; it selects \`documentdb-18\`. Local files resolve dependencies only against enabled repositories, so a package whose dependencies are not included still fails. `; @@ -1528,7 +1567,7 @@ function updatePrebuiltPackagesContent(content: string): string { const legacyClaim = 'Everything else — PostgreSQL 15/16, Debian 11/12/13, Ubuntu 22.04, RHEL-compatible 8 — is not built by first-party CI for this release. The [package repository](https://documentdb.io/packages) serves those targets the extension package from an earlier release, or build from the tag with the scripts in [`packaging/`](https://github.com/documentdb/documentdb/blob/main/packaging/README.md). PostgreSQL 15 is extension-only: `documentdb-setup` needs 16 or newer.'; const currentPolicy = - 'Everything else — PostgreSQL 15/16, Debian 11/12/13, Ubuntu 22.04, RHEL-compatible 8 — is not built by first-party CI or hosted by documentdb.io for this release. Starting with v0.116, packages from earlier releases are not carried forward. Build from the matching tag with the [`packaging/` scripts](https://github.com/documentdb/documentdb/blob/v1.0-0/packaging/README.md); PostgreSQL 15 remains extension-only because `documentdb-setup` requires 16 or newer.'; + 'Everything else — PostgreSQL 15/16, Debian 11/12/13, Ubuntu 22.04, RHEL-compatible 8 — is not built by first-party CI or hosted by documentdb.io for this release. Starting with v0.116, packages from earlier releases are not carried forward. Build from the matching tag with the [`packaging/` scripts](https://github.com/documentdb/documentdb/blob/v1.2-0/packaging/README.md); PostgreSQL 15 remains extension-only because `documentdb-setup` requires 16 or newer.'; return content.replace(legacyClaim, currentPolicy); } diff --git a/app/v1/page.tsx b/app/v1/page.tsx index 24c1987..7e0c2c7 100644 --- a/app/v1/page.tsx +++ b/app/v1/page.tsx @@ -163,6 +163,11 @@ export default function ReleasePage() { repositories. On a clean host:

+

+ This installs the newest release from the latest channel. Add{" "} + --version 1.0.0 for exactly 1.0.0, which apt and dnf never upgrade, or{" "} + --stable for the stable channel. +

apt and dnf commands diff --git a/scripts/publish-installer.mjs b/scripts/publish-installer.mjs index 6effc5d..587b261 100644 --- a/scripts/publish-installer.mjs +++ b/scripts/publish-installer.mjs @@ -3,11 +3,10 @@ import { mkdir, writeFile } from 'node:fs/promises'; import { resolve } from 'node:path'; import { pathToFileURL } from 'node:url'; -// v1.0-0 attaches the same bytes as v1.0-RC2. Release assets can be replaced, -// so the digest is pinned too. +// Release assets can be replaced, so the digest is pinned too. export const installerSource = { - release: 'v1.0-0', - sha256: 'b9d16b3b86d3b1541e701be0ce38086dcb0bc904f761a36c7ede9fefe91d45f2', + release: 'v1.2-0', + sha256: '8b97d637d8e96d18fd46afeb2c28a3b48d52990038b0ef0a65d44147c3d5faf0', }; export async function publishInstaller(outputDirectory = 'out') { diff --git a/tests/installSelection.test.ts b/tests/installSelection.test.ts index 4ede569..6a786a4 100644 --- a/tests/installSelection.test.ts +++ b/tests/installSelection.test.ts @@ -1,3 +1,4 @@ +import { readFileSync } from "node:fs"; import { describe, expect, it } from "vitest"; import { defaultInstallSelection, @@ -7,7 +8,7 @@ import { releaseHasPackages, selectInstallTarget, } from "../app/lib/installSelection"; -import { FALLBACK_RELEASE, parseReleaseInfo } from "../app/lib/releaseInfo"; +import { FALLBACK_RELEASES, parseReleaseInfo, releaseInfoPaths } from "../app/lib/releaseInfo"; describe("install selection links", () => { it("defaults to Docker, with packages preset to the PG18 stack and host-resolved architecture", () => { @@ -116,24 +117,25 @@ describe("install selection links", () => { describe("published package availability", () => { const assetNames = [ ...["documentdb-18", "documentdb-common", "documentdb-postgresql-tools"].flatMap((name) => [ - `ubuntu24.04-${name}_1.0.0_all.deb`, - `${name}-1.0.0-1.noarch.rpm`, + `ubuntu24.04-${name}_1.2.0_all.deb`, + `${name}-1.2.0-1.noarch.rpm`, ]), ...["amd64", "arm64"].flatMap((arch) => [ - `ubuntu24.04-documentdb-gateway_1.0.0_${arch}.deb`, - `ubuntu24.04-postgresql-18-documentdb_1.0-0_${arch}.deb`, + `ubuntu24.04-documentdb-gateway_1.2.0_${arch}.deb`, + `ubuntu24.04-postgresql-18-documentdb_1.2-0_${arch}.deb`, ]), ...["x86_64", "aarch64"].flatMap((arch) => [ - `documentdb-gateway-1.0.0-1.el9.${arch}.rpm`, - `rhel9-postgresql18-documentdb-1.0.0-1.el9.${arch}.rpm`, + `documentdb-gateway-1.2.0-1.el9.${arch}.rpm`, + `rhel9-postgresql18-documentdb-1.2.0-1.el9.${arch}.rpm`, ]), ]; - const release = { ...FALLBACK_RELEASE, assetNames }; + // The commands install from latest, so its feed decides what the page offers. + const release = { ...FALLBACK_RELEASES.latest, assetNames }; it("requires the full stack, including both architectures for automatic selection", () => { expect(releaseHasPackages(release, defaultInstallSelection.packages)).toBe(true); expect(releaseHasPackages(release, { family: "rpm", target: "rhel9", arch: "auto", pg: "18" })).toBe(true); - expect(releaseHasPackages(FALLBACK_RELEASE, defaultInstallSelection.packages)).toBe(false); + expect(releaseHasPackages(FALLBACK_RELEASES.latest, defaultInstallSelection.packages)).toBe(false); expect(releaseHasPackages(release, { family: "apt", target: "ubuntu24", arch: "amd64", pg: "17" })).toBe(false); }); @@ -151,10 +153,22 @@ describe("published package availability", () => { expect(releaseHasPackages(partial, defaultInstallSelection.packages)).toBe(false); }); - it.each([null, {}, { tag_name: "v1.0-0", assets: [] }, { tag_name: "../other", assets: [] }])( + it.each([null, {}, { tag_name: "v1.2-0", assets: [] }, { tag_name: "../other", assets: [] }])( "surfaces malformed or incomplete metadata instead of inventing current versions", (payload) => { expect(() => parseReleaseInfo(payload)).toThrow(); }, ); + + it("reads each channel from the feed the deploy writes for it", () => { + const download = readFileSync(new URL("../.github/scripts/download_packages.sh", import.meta.url), "utf8"); + const drift = readFileSync(new URL("../.github/scripts/check_release_drift.js", import.meta.url), "utf8"); + for (const [channel, feed] of Object.entries(releaseInfoPaths)) { + const file = feed.split("/").pop(); + // [^;] keeps the match inside that channel's case arm, which ends with ;;. + expect(download).toMatch(new RegExp(`^ ${channel}\\)[^;]*RELEASE_INFO="out/packages/${file}"`, "m")); + expect(drift).toContain(`{ channel: "${channel}", feed: path.join("out", "packages", "${file}") }`); + } + expect(releaseInfoPaths.latest).not.toBe(releaseInfoPaths.stable); + }); }); diff --git a/tests/packageArticles.test.ts b/tests/packageArticles.test.ts index af1a9e9..bb3aa27 100644 --- a/tests/packageArticles.test.ts +++ b/tests/packageArticles.test.ts @@ -1,5 +1,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { execFileSync } from 'node:child_process'; import fs from 'node:fs'; +import { tmpdir } from 'node:os'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { kebabCase } from 'change-case'; @@ -13,13 +15,15 @@ import { buildRpmInstallCommand, buildSetupCommand, } from '../app/lib/packageInstall'; -import { FALLBACK_RELEASE } from '../app/lib/releaseInfo'; +import { FALLBACK_RELEASES } from '../app/lib/releaseInfo'; function getCodeBlocks(content: string, language: string): string[] { const pattern = new RegExp('```' + language + '\\n([\\s\\S]*?)\\n```', 'g'); return Array.from(content.matchAll(pattern), (match) => match[1]); } +const readRepoFile = (file: string) => fs.readFileSync(fileURLToPath(new URL(`../${file}`, import.meta.url)), 'utf8'); + describe('Linux package articles', () => { beforeEach(() => { const fixturePaths = new Map( @@ -293,28 +297,20 @@ describe('Linux package articles', () => { ].map((match) => match[1]); expect(tags.length).toBeGreaterThan(0); - expect(new Set(tags)).toEqual(new Set([FALLBACK_RELEASE.tagName])); - }); - - it('serves the stable installer without a pinned or RC version', () => { - expect(linuxPackagesGuideContent).toContain('https://documentdb.io/install.sh'); - expect(linuxPackagesGuideContent).toContain('installs the current release (v1.0-0) from the package repository'); - // install.sh rejects --version v1.0-0, and RCs are retired at GA. - expect(linuxPackagesGuideContent).not.toContain('--version v1.0'); - expect(linuxPackagesGuideContent).not.toMatch(/RC2|release-candidate/); + expect(new Set(tags)).toEqual(new Set([FALLBACK_RELEASES.latest.tagName])); }); it('uses the current release package guide and artifact version', () => { const offlineGuide = getArticleByPath('linux-packages', ['offline']); expect(linuxPackagesGuideContent).toContain( - 'documentdb/blob/v1.0-0/packaging/README.md', + 'documentdb/blob/v1.2-0/packaging/README.md', ); expect(linuxPackagesGuideContent).toContain( '`--load-sample-data` to the setup command to seed the `StoreData` database', ); expect(offlineGuide?.content).toContain( - 'ubuntu24.04-postgresql-18-documentdb_1.0-0_amd64.deb', + 'ubuntu24.04-postgresql-18-documentdb_1.2-0_amd64.deb', ); expect(offlineGuide?.content).toContain( 'pass the five packages for the selected PostgreSQL major', @@ -388,8 +384,14 @@ describe('Linux package articles', () => { '41,505 documents in `stores` and 2 documents in `ratings`', ); expect(dockerGuide?.content).toContain( - 'Existing volumes are not migrated automatically', + 'Existing volumes keep the sample data they were seeded with', ); + // The 1.2 image updates the extensions on a 1.0 or later volume at start, one way. + expect(dockerGuide?.content).toContain( + 'the image updates the DocumentDB extensions on an existing 1.0 or later data volume', + ); + expect(dockerGuide?.content).toContain('This only\ngoes forward'); + expect(dockerGuide?.content).not.toContain('does not update the DocumentDB schema'); expect(dockerGuide?.content).not.toContain('use sampledb'); const { readFile } = await import('node:fs/promises'); @@ -620,3 +622,125 @@ describe('docs-owned article normalization', () => { expect(article?.content).not.toContain('on a fresh volume'); }); }); + +describe('release channels', () => { + const { latest, stable } = FALLBACK_RELEASES; + const installer = 'curl -fsSLo documentdb-install.sh https://documentdb.io/install.sh &&\nsudo sh documentdb-install.sh'; + const docs = (): [string, string][] => [ + ['the quick start', linuxPackagesGuideContent], + ['PACKAGE-INSTALL.md', readRepoFile('PACKAGE-INSTALL.md')], + ]; + const switchSection = (text: string) => text.match(/^## Switch from `stable` to `latest`\n[\s\S]*?(?=^## )/m)?.[0]; + + it.each(docs())('leads %s with the plain installer and offers --stable and --version as options', (_name, text) => { + const block = text.indexOf('```sh\n' + installer + '\n```'); + expect(block).toBeGreaterThan(-1); + expect(text).toMatch(new RegExp(`installs (?:the current release \\()?${latest.tagName}\\)? from the \`latest\` channel`)); + const stableOption = text.match(/^- `--stable`: .*(?:\n {2}.*)*/m)?.[0] ?? ''; + const pinnedOption = text.match(/^- `--version 1\.0\.0`: .*(?:\n {2}.*)*/m)?.[0] ?? ''; + expect(stableOption).toContain(stable.tagName); + expect(pinnedOption.replace(/\s+/g, ' ')).toContain('the package manager never upgrades it'); + expect(text.indexOf(stableOption)).toBeGreaterThan(block); + expect(text.indexOf(pinnedOption)).toBeGreaterThan(block); + expect(text.replace(/\s+/g, ' ')).toContain('on a host where DocumentDB is already installed it changes no packages'); + // RCs exist only for disposable testing, so the pages do not offer them. + expect(text).not.toMatch(/--version [^\s`]*rc/i); + }); + + it('keeps the plain installer on the 1.0 page and names the 1.0.0 pin beside it', () => { + const source = readRepoFile('app/v1/page.tsx'); + expect(source).toContain('const installerCommand = `' + installer + '`;'); + const note = source.slice(source.indexOf('latest channel'); + expect(note).toContain('--version 1.0.0 for exactly 1.0.0, which apt and dnf never upgrade'); + expect(note).toContain('--stable for the stable channel'); + }); + + it.each(docs())('uses latest in the manual commands of %s and says in one line how stable differs', (_name, text) => { + const commands = getCodeBlocks(text, 'bash').join('\n'); + expect(commands).toContain('https://documentdb.io/deb latest ubuntu24"'); + expect(commands).toContain("'baseurl=https://documentdb.io/rpm/latest/rhel9'"); + expect(commands).not.toContain('https://documentdb.io/deb stable'); + expect(commands).not.toContain("'baseurl=https://documentdb.io/rpm/rhel9'"); + const stableBaseurl = buildRpmInstallCommand('rocky9', 'auto', '18', 'stable').match(/baseurl=[^']+/)?.[0]; + expect(text.replace(/\s+/g, ' ')).toContain( + `These commands use the \`latest\` channel. For \`stable\` (${stable.tagName}), write \`stable\` in place of \`latest\` in the DocumentDB APT line, or use \`${stableBaseurl}\` on EL9.`, + ); + }); + + it('installs from latest on /packages and shows stable from its own feed', () => { + const source = readRepoFile('app/packages/page.tsx'); + expect(source).toContain('useReleaseInfo("latest")'); + expect(source).toContain('useReleaseInfo("stable")'); + expect(source).toMatch(/buildAptInstallCommand\(packages\.target, packages\.arch, packages\.pg\)/); + expect(source).toMatch(/buildRpmInstallCommand\(packages\.target, packages\.arch, packages\.pg\)/); + expect(source).toContain('stable ({stableRelease.tagName})'); + expect(source).toContain(buildRpmInstallCommand('rocky9', 'auto', '18', 'stable').match(/baseurl=[^']+/)?.[0]); + expect(source).toContain('href="/docs/getting-started/packages#clean-host-installer"'); + }); + + it.each(docs().concat([['the operations guide', linuxPackagesOperationsContent]]))( + 'never pairs stable with a release other than its own in %s', + (_name, text) => { + const versions = Array.from(text.matchAll(/`stable`[^.\n]*?(v?\d+\.\d+(?:\.\d+|-\d+)?)/g), (m) => m[1]); + for (const version of versions) { + expect([stable.tagName, stable.metaVersion]).toContain(version); + } + }, + ); + + it('puts the same one-way switch note after the upgrade steps in both copies', () => { + const operations = switchSection(linuxPackagesOperationsContent); + const packageInstall = readRepoFile('PACKAGE-INSTALL.md'); + expect(operations).toBeDefined(); + expect(switchSection(packageInstall)).toBe(operations); + expect(linuxPackagesOperationsContent.indexOf(operations!)).toBeGreaterThan( + linuxPackagesOperationsContent.indexOf('## Upgrading'), + ); + const text = operations!.replace(/\s+/g, ' '); + expect(text).toContain('This is one-way: 1.0 does not run correctly on data that 1.2 has updated'); + expect(operations).toContain('```bash\nsudo documentdb-setup --pg-version 18 --yes\n```'); + expect(operations).not.toMatch(/documentdb-setup[^\n]*--admin-user/); + expect(operations).toContain('sudo apt upgrade'); + expect(operations).toContain('sudo dnf upgrade'); + // Both upgrade sections link to it. + for (const upgrade of [linuxPackagesOperationsContent, packageInstall]) { + expect(upgrade).toContain('[switch it to `latest`](#switch-from-stable-to-latest)'); + } + }); + + it('switches every stable definition to the latest one with the documented commands', () => { + const edits = switchSection(linuxPackagesOperationsContent)!.split('\n').filter((line) => line.startsWith('sudo sed -i ')); + expect(edits).toHaveLength(2); + const printed = (command: string) => { + const start = command.indexOf("printf '%s\\n'"); + return execFileSync('sh', ['-c', command.slice(start, command.indexOf(' | sudo tee', start))], { encoding: 'utf8' }); + }; + const aptLine = (channel: 'latest' | 'stable') => + `${buildAptInstallCommand('ubuntu24', 'amd64', '18', channel).match(/echo "(deb [^"]*documentdb\.io[^"]*)"/)![1]}\n`; + // What the 1.0 installer and install.sh --stable write; they differ from the site's RPM definition. + const installerRpm = (baseurl: string) => ['[documentdb]', 'name=DocumentDB Repository', `baseurl=${baseurl}`, + 'enabled=1', 'gpgcheck=1', 'repo_gpgcheck=1', 'gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-documentdb', ''].join('\n'); + const cases = [ + [edits[0], '/etc/apt/sources.list.d/documentdb.list', aptLine('stable'), aptLine('latest')], + [edits[1], '/etc/yum.repos.d/documentdb.repo', printed(buildRpmInstallCommand('rocky9', 'auto', '18', 'stable')), + printed(buildRpmInstallCommand('rocky9', 'auto', '18', 'latest'))], + [edits[1], '/etc/yum.repos.d/documentdb.repo', installerRpm('https://documentdb.io/rpm/rhel9'), + installerRpm('https://documentdb.io/rpm/latest/rhel9')], + ]; + const dir = fs.mkdtempSync(path.join(tmpdir(), 'channel-switch-')); + try { + for (const [edit, target, before, after] of cases) { + expect(edit).toContain(` ${target} &&`); + const file = path.join(dir, path.basename(target)); + fs.writeFileSync(file, before); + // -i.bak works with GNU and BSD sed; running it twice shows a rerun is harmless. + const script = edit.replace('sudo sed -i ', 'sed -i.bak ').replace(` ${target} &&`, ' "$1"'); + execFileSync('sh', ['-c', `${script} && ${script}`, 'sh', file]); + expect(fs.readFileSync(file, 'utf8')).toBe(after); + } + } finally { + fs.rmSync(dir, { recursive: true, force: true }); + } + }); +}); diff --git a/tests/packageInstall.test.ts b/tests/packageInstall.test.ts index 7f20d37..1254567 100644 --- a/tests/packageInstall.test.ts +++ b/tests/packageInstall.test.ts @@ -21,7 +21,7 @@ import type { RpmPgVersion, } from '../app/lib/packageInstall'; import { - FALLBACK_RELEASE, + FALLBACK_RELEASES, parseReleaseInfo, } from '../app/lib/releaseInfo'; @@ -79,8 +79,16 @@ describe('package metadata', () => { }); describe('release metadata', () => { - it('uses v1.0-0 for the first paint and feed fallback', () => { - expect(FALLBACK_RELEASE).toMatchObject({ + it('uses v1.2-0 for latest and v1.0-0 for stable before the feeds load', () => { + expect(FALLBACK_RELEASES.latest).toMatchObject({ + tagName: 'v1.2-0', + aptVersion: '1.2-0', + rpmVersion: '1.2.0-1.el9', + metaVersion: '1.2.0', + metaRpmVersion: '1.2.0-1', + releaseUrl: 'https://github.com/documentdb/documentdb/releases/tag/v1.2-0', + }); + expect(FALLBACK_RELEASES.stable).toMatchObject({ tagName: 'v1.0-0', aptVersion: '1.0-0', rpmVersion: '1.0.0-1.el9', @@ -90,24 +98,22 @@ describe('release metadata', () => { }); }); - it('derives v1.0 package versions from the published asset shapes', () => { - expect(parseReleaseInfo({ - tag_name: 'v1.0-0', - html_url: 'https://github.com/documentdb/documentdb/releases/tag/v1.0-0', - assets: [ - { name: 'ubuntu24.04-documentdb_1.0.0_all.deb' }, - { name: 'ubuntu24.04-postgresql-18-documentdb_1.0-0_amd64.deb' }, - { name: 'documentdb-1.0.0-1.noarch.rpm' }, - { name: 'rhel9-postgresql18-documentdb-1.0.0-1.el9.x86_64.rpm' }, - ], - })).toMatchObject({ - tagName: 'v1.0-0', - aptVersion: '1.0-0', - rpmVersion: '1.0.0-1.el9', - metaVersion: '1.0.0', - metaRpmVersion: '1.0.0-1', - }); - }); + it.each(Object.entries(FALLBACK_RELEASES))( + 'derives the %s fallback from its release\'s published asset shapes', + (_channel, fallback) => { + const { metaVersion, aptVersion, rpmVersion, metaRpmVersion } = fallback; + expect(parseReleaseInfo({ + tag_name: fallback.tagName, + html_url: fallback.releaseUrl, + assets: [ + { name: `ubuntu24.04-documentdb_${metaVersion}_all.deb` }, + { name: `ubuntu24.04-postgresql-18-documentdb_${aptVersion}_amd64.deb` }, + { name: `documentdb-${metaRpmVersion}.noarch.rpm` }, + { name: `rhel9-postgresql18-documentdb-${rpmVersion}.x86_64.rpm` }, + ], + })).toEqual({ ...fallback, assetNames: expect.any(Array) }); + }, + ); }); describe('buildAptInstallCommand', () => { @@ -137,9 +143,18 @@ describe('buildAptInstallCommand', () => { expect(command).not.toContain('[arch=arm64 '); }); - it.each(aptDistros)('uses %s as the DocumentDB repository component', (distro) => { + it.each(aptDistros)('uses %s as the DocumentDB repository component of latest by default', (distro) => { const command = buildAptInstallCommand(distro, 'amd64', aptTargetPgVersions[distro][0]); - expect(command).toContain(`documentdb.io/deb stable ${distro}`); + expect(command).toContain(`documentdb.io/deb latest ${distro}"`); + expect(command).not.toContain('documentdb.io/deb stable'); + }); + + it.each(['latest', 'stable'] as const)('writes the source install.sh recognises for the %s channel', (channel) => { + // install.sh refuses a documentdb.list that is not byte-for-byte one of its own definitions. + const command = buildAptInstallCommand('ubuntu24', 'amd64', '18', channel); + expect(command).toContain( + `echo "deb [arch=amd64 signed-by=/usr/share/keyrings/documentdb-archive-keyring.gpg] https://documentdb.io/deb ${channel} ubuntu24" | sudo tee /etc/apt/sources.list.d/documentdb.list >/dev/null`, + ); }); it.each(aptMatrix)('installs the right package for $distro/$arch/pg$pg', ({ distro, arch, pg }) => { @@ -184,10 +199,23 @@ describe('buildRpmInstallCommand', () => { expect(command).not.toContain('EL-9-aarch64'); }); - it.each(rpmDistros)('points %s at the shared EL9 DocumentDB repository', (distro) => { + it.each(rpmDistros)('points %s at the shared EL9 repository of the latest channel by default', (distro) => { const command = buildRpmInstallCommand(distro, 'x86_64', '17'); expect(command).toContain( - `baseurl=https://documentdb.io/rpm/${expectedRpmRepositoryPaths[distro]}`, + `'baseurl=https://documentdb.io/rpm/latest/${expectedRpmRepositoryPaths[distro]}'`, + ); + }); + + it.each([ + ['latest', 'https://documentdb.io/rpm/latest/rhel9'], + ['stable', 'https://documentdb.io/rpm/rhel9'], + ] as const)('writes the definition install.sh recognises for the %s channel', (channel, baseurl) => { + const command = buildRpmInstallCommand('rocky9', 'x86_64', '18', channel); + const printf = command.slice(command.indexOf("printf '%s\\n'"), command.indexOf(' | sudo tee /etc/yum.repos.d/documentdb.repo')); + // install.sh refuses any other documentdb.repo; running the printf also catches quoting mistakes. + expect(execFileSync('sh', ['-c', printf], { encoding: 'utf8' })).toBe( + ['[documentdb]', 'name=DocumentDB Repository', `baseurl=${baseurl}`, 'enabled=1', 'gpgcheck=1', + 'gpgkey=https://documentdb.io/documentdb-archive-keyring.gpg', ''].join('\n'), ); }); diff --git a/tests/releaseDrift.test.ts b/tests/releaseDrift.test.ts new file mode 100644 index 0000000..e977322 --- /dev/null +++ b/tests/releaseDrift.test.ts @@ -0,0 +1,93 @@ +import { spawnSync } from 'node:child_process'; +import { copyFileSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { afterEach, describe, expect, it } from 'vitest'; +import { FALLBACK_RELEASES, type ReleaseInfo } from '../app/lib/releaseInfo'; + +const script = fileURLToPath(new URL('../.github/scripts/check_release_drift.js', import.meta.url)); +const releaseInfoSource = fileURLToPath(new URL('../app/lib/releaseInfo.ts', import.meta.url)); +const directories: string[] = []; + +// The feed a deploy writes for a release, reduced to the assets the check reads. +function feed({ tagName, aptVersion, rpmVersion, metaVersion }: Pick) { + return { + tag_name: tagName, + assets: [ + `ubuntu24.04-documentdb_${metaVersion}_all.deb`, + `ubuntu24.04-postgresql-18-documentdb_${aptVersion}_amd64.deb`, + `rhel9-postgresql18-documentdb-${rpmVersion}.x86_64.rpm`, + ].map((name) => ({ name })), + }; +} + +// Runs the check from a scratch checkout holding the real fallbacks and the given feeds. +function checkDrift(feeds: { latest?: object; stable?: object }) { + const root = mkdtempSync(path.join(tmpdir(), 'release-drift-')); + directories.push(root); + mkdirSync(path.join(root, 'app', 'lib'), { recursive: true }); + copyFileSync(releaseInfoSource, path.join(root, 'app', 'lib', 'releaseInfo.ts')); + mkdirSync(path.join(root, 'out', 'packages'), { recursive: true }); + if (feeds.latest) writeFileSync(path.join(root, 'out', 'packages', 'release-info-latest.json'), JSON.stringify(feeds.latest)); + if (feeds.stable) writeFileSync(path.join(root, 'out', 'packages', 'release-info.json'), JSON.stringify(feeds.stable)); + const result = spawnSync(process.execPath, [script], { cwd: root, encoding: 'utf8' }); + return { status: result.status, output: `${result.stdout}${result.stderr}` }; +} + +afterEach(() => { + for (const directory of directories.splice(0)) rmSync(directory, { recursive: true, force: true }); +}); + +describe('release drift check', () => { + const latest = feed(FALLBACK_RELEASES.latest); + const stable = feed(FALLBACK_RELEASES.stable); + + it('passes when each fallback names the release its channel mirrors', () => { + const { status, output } = checkDrift({ latest, stable }); + expect(output).toContain('The latest fallback matches the mirrored release (v1.2-0).'); + expect(output).toContain('The stable fallback matches the mirrored release (v1.0-0).'); + expect(status).toBe(0); + }); + + it('skips a site-only build with no feeds', () => { + const { status, output } = checkDrift({}); + expect(output).toContain('skipping release drift check'); + expect(status).toBe(0); + }); + + it.each(['latest', 'stable'] as const)('fails when only the %s feed was built', (channel) => { + const { status, output } = checkDrift({ [channel]: channel === 'latest' ? latest : stable }); + expect(output).toContain('is missing'); + expect(status).toBe(1); + }); + + it('fails when stable moves to 1.2 but its fallback still names 1.0', () => { + const { status, output } = checkDrift({ latest, stable: latest }); + expect(output).toContain("the site's stable fallback release does not match"); + expect(output).toContain('FALLBACK_RELEASES.stable): v1.0-0'); + expect(output).not.toContain("the site's latest fallback release does not match"); + expect(status).toBe(1); + }); + + it('fails when latest moves on but its fallback does not', () => { + const next = feed({ tagName: 'v1.3-0', aptVersion: '1.3-0', rpmVersion: '1.3.0-1.el9', metaVersion: '1.3.0' }); + const { status, output } = checkDrift({ latest: next, stable }); + expect(output).toContain("the site's latest fallback release does not match"); + expect(output).toContain('The stable fallback matches the mirrored release (v1.0-0).'); + expect(status).toBe(1); + }); + + it('fails when a rebuilt release ships package versions the fallback does not name', () => { + const rebuilt = feed({ ...FALLBACK_RELEASES.latest, aptVersion: '1.2-1' }); + const { status, output } = checkDrift({ latest: rebuilt, stable }); + expect(output).toContain('FALLBACK_RELEASES.latest.aptVersion is "1.2-0" but v1.2-0 ships "1.2-1".'); + expect(status).toBe(1); + }); + + it('fails when a feed has no tag', () => { + const { status, output } = checkDrift({ latest: { assets: [] }, stable }); + expect(output).toContain('has no tag_name'); + expect(status).toBe(1); + }); +});