Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 77 additions & 58 deletions .github/scripts/check_release_drift.js
Original file line number Diff line number Diff line change
@@ -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 ?? "<not found>"}`,
"",
"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",
Expand All @@ -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 ?? "<not found>"}`,
"",
].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}).`);
95 changes: 73 additions & 22 deletions PACKAGE-INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -13,26 +13,39 @@ 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.

## 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

Expand Down Expand Up @@ -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
Expand All @@ -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
```
Expand All @@ -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 && \
Expand All @@ -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 && \
Expand Down Expand Up @@ -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
```

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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.
Loading
Loading