Skip to content
Draft
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
20 changes: 20 additions & 0 deletions .github/workflows/make-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,23 @@ jobs:
run: |
git diff --exit-code
git ls-files --other --directory --exclude-standard | sed q1
# Not part of make check, as it needs packaging and signing tools that dev
# machines usually lack
release-e2e:
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.14"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install uv
sudo apt-get update
sudo apt-get install --yes rpm debsigs apt-utils createrepo-c
- name: Run the release end-to-end test
run: |
uv sync
uv run bash tests/release/e2e.sh
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Release data, kept in the published format
tests/release/data/
25 changes: 25 additions & 0 deletions src/cfengine_cli/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
)
from cfengine_cli import docs
from cfengine_cli.syntax_tree import syntax_tree
from cfengine_cli.release.release import release
from cfengine_cli.release.publish import publish
from cfengine_cli.release.update_repo import update_repo


def generate_release_information_command(
Expand Down Expand Up @@ -84,5 +87,27 @@ def dispatch_dev_subcommand(subcommand, args) -> int:
)
if subcommand == "generate-changelog":
return generate_changelog_impl(args)
if subcommand == "release":
return release(
project=args.project,
version=args.version,
build_dir=args.build,
output_dir=args.output,
dry_run=args.dry_run,
)
if subcommand == "publish":
return publish(
output_dir=args.output,
bucket=args.bucket,
release_data_only=args.release_data_only,
dry_run=args.dry_run,
)
if subcommand == "update-repo":
return update_repo(
version=args.version,
build_dir=args.build,
output_dir=args.output,
dry_run=args.dry_run,
)

raise UserError("Invalid cfengine dev subcommand - " + subcommand)
23 changes: 23 additions & 0 deletions src/cfengine_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
from cf_remote.utils import strip_user, CFRExitError
from cfengine_cli.cfengine_wrapper import cfengine_commands
from cfengine_cli.cfengine_wrapper.arg_parse import parse_wrapper_args
from cfengine_cli.release.args import (
add_publish_args,
add_release_args,
add_update_repo_args,
)
from cfengine_cli.version import cfengine_cli_version_string
from cfengine_cli import commands
from cfengine_cli.utils import UserError
Expand Down Expand Up @@ -211,6 +216,24 @@ def _get_arg_parser():
help="Commit range [other optional args], e.g. 3.27.0..origin/3.27.x",
)

parser = dev_subparsers.add_parser(
"release",
help="Release packages built by build-in-container",
)
add_release_args(parser)

parser = dev_subparsers.add_parser(
"update-repo",
help="Add a community release to the APT and YUM repositories",
)
add_update_repo_args(parser)

parser = dev_subparsers.add_parser(
"publish",
help="Upload the release files, repositories and release data to S3",
)
add_publish_args(parser)

inip = subp.add_parser(
"init", help="Initialize a [policy-set, policy-module, promise-type] example."
)
Expand Down
186 changes: 186 additions & 0 deletions src/cfengine_cli/release/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# Releasing CFEngine

These commands release the packages built by `build-in-container`.
They replace the legacy `release.py` and `sync-packages-to-s3.sh` in the infra repo.
Older branches, like `3.24.x` and `3.27.x`, keep using the legacy scripts until they reach EOL.
Both scripts can coexist

## The commands

### `cfengine dev release`

Releases a build. Works on local files only.

1. Reads the build and verifies its `sha256sums.txt` files.
2. Plans every file to publish.
3. Copies the files to `release/`, and signs the packages.
4. Creates the release data: `release-data/<project>/<version>.json`.
Appends the new version to `release-data/<project>/releases.json`.

Signing is reproducible. The signature time is the build time of the package.

### `cfengine dev update-repo`

Adds a community release to the local copy of the APT and YUM repositories in `repo/` on buildcache.
It regenerates and signs the repository metadata.
It adds the copies in `release/`, signed by `cfengine dev release`, and refuses unsigned ones.

### `cfengine dev publish`

Uploads to S3:

- `--bucket test` uploads the repositories to `cfengine-repotest`.
- `--bucket prod` uploads the release files, the repositories, and the release data to `cfengine-package-repos`.
- `--release-data-only` uploads only the release data, for nightlies.
Their release data links to the packages on buildcache itself, not on S3.

`--bucket test` uploads less than `--bucket prod`, as only the repositories have a test bucket.
ENT-14959 will fix this asymmetry where everything will go to a staging bucket first.

## Directories

The output directory, `/var/www/buildcache` on buildcache, contains:

- `release/`: the released files, as they are published on S3
- `repo/`: the community APT and YUM repositories
- `release-data/`: the release data, read by the downloads page and cf-remote
- `.lock`: held while writing
- `.tmp-*`: temporary files while writing

The build directory is a `build-in-container output`.
E.g. `/var/www/buildcache/packages/build-in-container/<build>`.

## Requirements

- The `contact@northern.tech` gpg key, to sign the packages and repositories.
- `gpg`, `rpm`, `rpmsign`, `debsigs`, `apt-ftparchive`, `createrepo_c` and `aws`.
- AWS credentials for both buckets.

## Making a release

Community and enterprise are always released together.
Every command takes `--dry-run`, to see what it would do first.
It's safe to run a failed command again.

### Feature release

A feature release is one new version, e.g. `3.31.0`.

1. Set the variables:

```bash
VERSION=3.31.0 # Change to the version you are releasing
BUILD=/var/www/buildcache/packages/build-in-container/<build> # Change to its build
OUTPUT=/var/www/buildcache
```

2. Release both projects, and add the community release to the repositories:

```bash
cfengine dev release --project community --version $VERSION --build $BUILD --output $OUTPUT
cfengine dev release --project enterprise --version $VERSION --build $BUILD --output $OUTPUT
cfengine dev update-repo --version $VERSION --build $BUILD --output $OUTPUT
```

3. Upload the repositories to the test bucket, and check that installing from
them works:

```bash
cfengine dev publish --output $OUTPUT --bucket test
```

4. When the release is announced, upload everything to production:

```bash
cfengine dev publish --output $OUTPUT --bucket prod
```

### Patch release

A patch release is made on each supported LTS branch at the same time.
E.g. `3.33.1` and `3.30.4`. Each version has its own build.

1. Set the variables:

```bash
A_VERSION=3.33.1 # Change to the version on one LTS branch
A_BUILD=/var/www/buildcache/packages/build-in-container/<build> # Change to its build
B_VERSION=3.30.4 # Change to the version on the other LTS branch
B_BUILD=/var/www/buildcache/packages/build-in-container/<build> # Change to its build
OUTPUT=/var/www/buildcache
```

2. Release both projects of both versions, and add the community releases to the repositories:

```bash
cfengine dev release --project community --version $A_VERSION --build $A_BUILD --output $OUTPUT
cfengine dev release --project enterprise --version $A_VERSION --build $A_BUILD --output $OUTPUT
cfengine dev update-repo --version $A_VERSION --build $A_BUILD --output $OUTPUT
cfengine dev release --project community --version $B_VERSION --build $B_BUILD --output $OUTPUT
cfengine dev release --project enterprise --version $B_VERSION --build $B_BUILD --output $OUTPUT
cfengine dev update-repo --version $B_VERSION --build $B_BUILD --output $OUTPUT
```

3. Upload the repositories to the test bucket, and check that installing from them works.
This uploads both versions at once:

```bash
cfengine dev publish --output $OUTPUT --bucket test
```

4. When the release is announced, upload everything to production:

```bash
cfengine dev publish --output $OUTPUT --bucket prod
```

Use legacy script in infra for versions older that `3.30`.

## Nightlies

When a nightly build finishes, Jenkins puts its output in `/home/jenkins/output/`.
The `sync.path` systemd unit on buildcache notices it and starts `sync.service`, which runs `sync.sh` from the infra repo.
It copies the build to `/var/www/buildcache/packages/`, and releases it with the branch as the version, e.g. `master` or `3.30.x`.

For a community master nightly:

```bash
cfengine dev release --project community --version master --build $BUILD --output /var/www/buildcache
cfengine dev publish --output /var/www/buildcache --bucket prod --release-data-only
```

A nightly copies and signs nothing.
Its release data links to the build on buildcache, so only the release data is uploaded.

## Code

The commands are added in `main.py` and dispatched in `dev.py`.
Each starts in the function of the same name, in the file of the same name:

- `release`: `release()` in `release.py`
- `update-repo`: `update_repo()` in `update_repo.py`
- `publish`: `publish()` in `publish.py`

The files in this directory:

- `args.py`: the command line options.
- `build.py`: reads the `build-in-container` output directory into a `Build`, one `PackageDir` per platform label.
- `checksums.py`: verifies the build against its `sha256sums.txt` files, and hashes files.
- `platforms.py`: what a build label means.
E.g. that `PACKAGES_arm_64_linux_ubuntu_24` is "Ubuntu 24", aarch64, with its classexpr and release directory.
Also decides the order of packages on the downloads page.
- `plan.py`: plans every file to publish as a `PlannedFile`:
where it comes from, where it goes, its URL, and how it is shown in the release data.
Most release rules live here.
- `release.py`: the `release` command. Reads, plans, copies and writes the release data.
- `copy_files.py`: copies the planned files to `release/`, and signs packages.
- `metadata.py`: the release data formats, and the logic around versions:
titles, LTS branches, support dates, and the `latest` flags in `releases.json`.
- `release_data.py`: builds the release data from the plan, and reads and writes the JSON files.
- `update_repo.py`: the `update-repo` command.
Adds packages to the APT and YUM repositories, and regenerates and signs the repository metadata.
- `publish.py`: the `publish` command. Uploads the directories to S3 in a safe order.
- `utils.py`: shared helpers.

The unit tests live in `tests/unit/test_release_<module>.py`.
End-to-end tests live in `tests/release/`.
Empty file.
90 changes: 90 additions & 0 deletions src/cfengine_cli/release/args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import argparse
import re


def release_version(value: str) -> str:
"""argparse type for a release or nightly version."""
if not re.fullmatch(r"\d+\.\d+\.(\d+|x)|master", value):
raise argparse.ArgumentTypeError(
f"'{value}' is not X.Y.Z, or X.Y.x or master for nightlies"
)
return value


def stable_version(value: str) -> str:
"""argparse type for a release version, not a nightly."""
if not re.fullmatch(r"\d+\.\d+\.\d+", value):
raise argparse.ArgumentTypeError(f"'{value}' is not X.Y.Z")
return value


def add_release_args(sp: argparse.ArgumentParser) -> None:
_ = sp.add_argument(
"--project",
required=True,
choices=["enterprise", "community"],
help="Which edition to release",
)
_ = sp.add_argument(
"--version",
required=True,
type=release_version,
help="Version to release, e.g. 3.30.0. Or 3.30.x / master for nightlies",
)
_ = sp.add_argument(
"--build",
required=True,
help="Directory with the build",
)
_ = sp.add_argument(
"--output",
required=True,
help="Root directory to write release/ and release-data/ to",
)
_ = sp.add_argument(
"--dry-run", action="store_true", help="Only print what would be done"
)


def add_publish_args(sp: argparse.ArgumentParser) -> None:
_ = sp.add_argument(
"--output",
required=True,
help="Root directory with release/, repo/ and release-data/",
)
_ = sp.add_argument(
"--bucket",
required=True,
choices=["test", "prod"],
help="test: only the repos, to try them. prod: everything, release data last",
)
_ = sp.add_argument(
"--release-data-only",
action="store_true",
help="Only upload the release data, e.g. for nightlies. Needs --bucket prod",
)
_ = sp.add_argument(
"--dry-run", action="store_true", help="Only list what would be uploaded"
)


def add_update_repo_args(sp: argparse.ArgumentParser) -> None:
_ = sp.add_argument(
"--version",
required=True,
type=stable_version,
help="Community version to add, e.g. 3.30.0",
)
_ = sp.add_argument(
"--build",
required=True,
help="Directory with the build, as given to cfengine dev release",
)
_ = sp.add_argument(
"--output",
required=True,
help="Root directory with release/ and repo/, as given to cfengine dev release",
)
_ = sp.add_argument(
"--dry-run", action="store_true", help="Only print what would be done"
)
Loading
Loading