Move closer to release

This commit is contained in:
Zhaofeng Li 2021-11-18 13:15:20 -08:00
parent c271780b63
commit ee8ae7dd21
16 changed files with 301 additions and 53 deletions

View file

@ -5,7 +5,7 @@ on:
branches: branches:
- main - main
jobs: jobs:
deploy: deploy-unstable:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -20,16 +20,36 @@ jobs:
name: colmena name: colmena
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
# == Manual
- name: Build manual - name: Build manual
run: nix build -o out .#manual -L run: nix build -o out .#manual -L
# Ugly hack so it has permission to delete the worktree afterwards # Ugly hack so it has permission to delete the worktree afterwards
- name: Copy website - name: Copy manual
run: cp --no-preserve=mode -r out/ public/ run: cp --no-preserve=mode -r out/ public/
- name: Deploy website - name: Deploy manual
uses: JamesIves/github-pages-deploy-action@4.1.5 uses: JamesIves/github-pages-deploy-action@4.1.5
with: with:
branch: gh-pages branch: gh-pages
folder: public folder: public
target-folder: unstable target-folder: unstable
# == Redirect Farm
# /future_api_version -> /unstable
- name: Check future API version
run: echo "api_version=${nix eval .#colmena.apiVersion}" >> $GITHUB_ENV
- name: Build redirect farm
run: nix build -o out .#manual.redirectFarm -L
# Ugly hack so it has permission to delete the worktree afterwards
- name: Copy redirect farm
run: cp --no-preserve=mode -r out/ redirect-farm/
- name: Deploy redirect farm
uses: JamesIves/github-pages-deploy-action@4.1.5
with:
branch: gh-pages
folder: redirect-farm
target-folder: '${{ env.api_version }}'

View file

@ -1,6 +1,6 @@
# Colmena # Colmena
[![Manual](https://img.shields.io/badge/Manual-Pages-informational)](https://zhaofengli.github.io/colmena) [![Manual](https://img.shields.io/badge/Manual-Unstable-informational)](https://zhaofengli.github.io/colmena/unstable)
[![Build](https://github.com/zhaofengli/colmena/workflows/Build/badge.svg)](https://github.com/zhaofengli/colmena/actions/workflows/build.yml) [![Build](https://github.com/zhaofengli/colmena/workflows/Build/badge.svg)](https://github.com/zhaofengli/colmena/actions/workflows/build.yml)
Colmena is a simple, stateless [NixOS](https://nixos.org) deployment tool modeled after [NixOps](https://github.com/NixOS/nixops) and [morph](https://github.com/DBCDK/morph), written in Rust. Colmena is a simple, stateless [NixOS](https://nixos.org) deployment tool modeled after [NixOps](https://github.com/NixOS/nixops) and [morph](https://github.com/DBCDK/morph), written in Rust.
@ -22,20 +22,25 @@ $ <b>colmena apply --on @tag-a</b>
<b>kappa</b> ✅ 2s Activation successful <b>kappa</b> ✅ 2s Activation successful
</pre> </pre>
Colmena is still an early prototype.
## Installation ## Installation
Colmena doesn't have a stable release yet. Colmena doesn't have a stable release yet.
To install the latest development version to the user profile, use `default.nix`: To install the latest development version to the user profile, use the following command:
```bash
nix-env -if https://github.com/zhaofengli/colmena/tarball/main
``` ```
Alternatively, if you have a local clone of the repo:
```bash
nix-env -if default.nix nix-env -if default.nix
``` ```
### Binary Cache ### Unstable Binary Cache
A public binary cache is available at https://colmena.cachix.org, courtesy of Cachix. A public binary cache is available at https://colmena.cachix.org, courtesy of Cachix.
This binary cache contains unstable versions of Colmena built by [GitHub Actions](https://github.com/zhaofengli/colmena/actions).
## Tutorial ## Tutorial
@ -179,11 +184,11 @@ Run `colmena build` in the same directory to build the configuration, or do `col
Read [the Colmena Manual](https://zhaofengli.github.io/colmena). Read [the Colmena Manual](https://zhaofengli.github.io/colmena).
## Environment variables ## Environment Variables
- `SSH_CONFIG_FILE`: Path to a `ssh_config` file - `SSH_CONFIG_FILE`: Path to a `ssh_config` file
## Current limitations ## Current Limitations
- It's required to use SSH keys to log into the remote hosts, and interactive authentication will not work. - It's required to use SSH keys to log into the remote hosts, and interactive authentication will not work.
- Error reporting is lacking. - Error reporting is lacking.

View file

@ -10,16 +10,19 @@ in {
lib = pkgs.lib; lib = pkgs.lib;
stdenv = pkgs.stdenv; stdenv = pkgs.stdenv;
rustPlatform = pkgs.rustPlatform; rustPlatform = pkgs.rustPlatform;
in rustPlatform.buildRustPackage { in rustPlatform.buildRustPackage rec {
name = "colmena"; pname = "colmena";
version = "0.2.0-pre"; version = "0.2.0-pre";
# We guarantee CLI and Nix API stability for the same minor version
apiVersion = builtins.concatStringsSep "." (lib.take 2 (lib.splitString "." version));
src = lib.cleanSourceWith { src = lib.cleanSourceWith {
filter = name: type: !(type == "directory" && builtins.elem (baseNameOf name) [ "target" "manual" ]); filter = name: type: !(type == "directory" && builtins.elem (baseNameOf name) [ "target" "manual" ]);
src = lib.cleanSource ./.; src = lib.cleanSource ./.;
}; };
cargoSha256 = "sha256-cpxvhP9TVEaIaiIZ+X22bDREqALpgWtW6koucVfMLwY="; cargoSha256 = "sha256-IiAJ+sQasimcn4nSv4ACBwP1NLGNArtcIbwzkx0v/7w=";
postInstall = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) '' postInstall = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
mkdir completions mkdir completions

View file

@ -21,6 +21,7 @@
packages = rec { packages = rec {
colmena = import ./default.nix { inherit pkgs; }; colmena = import ./default.nix { inherit pkgs; };
# Full user manual
manual = let manual = let
colmena = self.packages.${system}.colmena; colmena = self.packages.${system}.colmena;
evalNix = import ./src/nix/eval.nix { evalNix = import ./src/nix/eval.nix {
@ -36,7 +37,11 @@
inherit colmena deploymentOptionsMd metaOptionsMd; inherit colmena deploymentOptionsMd metaOptionsMd;
}; };
# User manual without the CLI reference
manualFast = manual.override { colmena = null; }; manualFast = manual.override { colmena = null; };
# User manual with the version treated as stable
manualForceStable = manual.override { unstable = false; };
}; };
defaultApp = self.apps.${system}.colmena; defaultApp = self.apps.${system}.colmena;
@ -47,7 +52,7 @@
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
inputsFrom = [ defaultPackage ]; inputsFrom = [ defaultPackage ];
nativeBuildInputs = with pkgs; [ mdbook ]; nativeBuildInputs = with pkgs; [ mdbook python3 ];
shellHook = '' shellHook = ''
export NIX_PATH=nixpkgs=${pkgs.path} export NIX_PATH=nixpkgs=${pkgs.path}
''; '';

View file

@ -7,3 +7,27 @@ You can read the rendered version [here](https://zhaofengli.github.io/colmena).
The manual is rendered using [mdBook](https://github.com/rust-lang/mdBook). The manual is rendered using [mdBook](https://github.com/rust-lang/mdBook).
To build the manual, do `nix build .#manual`. To build the manual, do `nix build .#manual`.
You can also do `nix build .#manualFast` for a version without the CLI usage reference. You can also do `nix build .#manualFast` for a version without the CLI usage reference.
## Marking Text for Specific Versions
You can mark text to be only visible in the unstable version of the manual:
```
<!-- UNSTABLE_BEGIN -->
You are currently reading the unstable version of the Colmena Manual.
Features described here will eventually become a part of version @apiVersion@.
<!-- UNSTABLE_END -->
```
The opposite can be done with the `STABLE_{BEGIN,END}` markers:
```
<!-- STABLE_BEGIN -->
You are currently reading the version @apiVersion@ of the Colmena Manual.
<!-- STABLE_END -->
```
## Substitutions
- `@version@` - Full version string
- `@apiVersion@` - Stable API version string (major.minor)

View file

@ -3,9 +3,13 @@ authors = ["Zhaofeng Li"]
language = "en" language = "en"
multilingual = false multilingual = false
src = "src" src = "src"
title = "Colmena RELEASE" title = "Colmena @apiVersion@"
[output.html] [output.html]
site-url = "/colmena/RELEASE/" site-url = "/colmena/@apiVersion@/"
git-repository-url = "https://github.com/zhaofengli/colmena" git-repository-url = "https://github.com/zhaofengli/colmena"
edit-url-template = "https://github.com/zhaofengli/colmena/edit/main/manual/{path}" edit-url-template = "https://github.com/zhaofengli/colmena/edit/main/manual/{path}"
[preprocessor.colmena]
command = "python3 preprocess.py"
renderer = [ "html", "epub" ]

View file

@ -9,3 +9,7 @@ title = "Colmena (Unstable)"
site-url = "/colmena/unstable/" site-url = "/colmena/unstable/"
git-repository-url = "https://github.com/zhaofengli/colmena" git-repository-url = "https://github.com/zhaofengli/colmena"
edit-url-template = "https://github.com/zhaofengli/colmena/edit/main/manual/{path}" edit-url-template = "https://github.com/zhaofengli/colmena/edit/main/manual/{path}"
[preprocessor.colmena]
command = "python3 preprocess.py"
renderer = [ "html", "epub" ]

View file

@ -2,33 +2,66 @@ let
notFound = typ: "<span style=\"color: red;\">Error: No ${typ} passed to the builder</span>"; notFound = typ: "<span style=\"color: red;\">Error: No ${typ} passed to the builder</span>";
in in
{ stdenv, nix-gitignore, mdbook { lib, stdenv, nix-gitignore, mdbook, python3, writeScript
, release ? null
, deploymentOptionsMd ? notFound "deployment options text" , deploymentOptionsMd ? notFound "deployment options text"
, metaOptionsMd ? notFound "meta options text" , metaOptionsMd ? notFound "meta options text"
, colmena ? null , colmena ? null
, version ? null # Full version (default: detected from colmena)
, unstable ? null # Whether this build is unstable (default: detected from version)
}: }:
stdenv.mkDerivation { let
inherit colmena deploymentOptionsMd metaOptionsMd release; versionComp =
if version == null then
if colmena != null then colmena.version else "unstable"
else version;
name = if release == null then "colmena-manual-dev" else "colmena-manual-${release}"; unstableComp =
if unstable == null then versionComp == "unstable" || lib.hasInfix "-" versionComp
else unstable;
apiVersion = builtins.concatStringsSep "." (lib.take 2 (lib.splitString "." versionComp));
redirectTemplate = lib.escapeShellArg ''
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Redirecting</title>
<meta http-equiv="refresh" content="0; URL=https://zhaofengli.github.io/colmena@path@">
</head>
<body>
Redirecting to <a href="https://zhaofengli.github.io/colmena@path@">https://zhaofengli.github.io/colmena@path@</a>
</body>
</html>
'';
in stdenv.mkDerivation {
inherit deploymentOptionsMd metaOptionsMd;
pname = "colmena-manual" + (if unstableComp then "-unstable" else "");
version = versionComp;
src = nix-gitignore.gitignoreSource [] ./.; src = nix-gitignore.gitignoreSource [] ./.;
nativeBuildInputs = [ mdbook ]; nativeBuildInputs = [ mdbook python3 ];
outputs = [ "out" "redirectFarm" ];
COLMENA_VERSION = versionComp;
COLMENA_UNSTABLE = unstableComp;
patchPhase = '' patchPhase = ''
if [ -n "$release" ]; then if [ -z "${toString unstableComp}" ]; then
find . -name '*.md' -exec sed -i "/REMOVE_FOR_RELEASE/d" {} \; sed "s|@apiVersion@|${apiVersion}|g" book.stable.toml > book.toml
sed "s/RELEASE/$release/g" book.release.toml > book.toml
fi fi
''; '';
buildPhase = '' buildPhase = ''
if [ -n "$colmena" ]; then if [ -n "${colmena}" ]; then
echo "Generating CLI help text" echo "Generating CLI help text"
$colmena/bin/colmena gen-help-markdown >> src/reference/cli.md ${colmena}/bin/colmena gen-help-markdown >> src/reference/cli.md
else else
echo "Error: No colmena executable passed to the builder" >> src/reference/cli.md echo "Error: No colmena executable passed to the builder" >> src/reference/cli.md
fi fi
@ -37,6 +70,26 @@ stdenv.mkDerivation {
echo "$metaOptionsMd" >> src/reference/meta.md echo "$metaOptionsMd" >> src/reference/meta.md
mdbook build -d $out mdbook build -d $out
# Build the redirect farm
# GitHub Pages doesn't play well with directory symlinks. Default
# pages (index.html) don't work when a symlink is traversed.
mkdir -p $redirectFarm
subdir="/unstable"
if [ -z "${toString unstableComp}" ]; then
subdir="/${apiVersion}"
fi
pushd $redirectFarm
(cd $out; find . -name "*.html") | while read -r page; do
strippedPage=''${page#.}
target="$subdir$strippedPage"
mkdir -p $(dirname $page)
echo ${redirectTemplate} | sed "s|@path@|$target|g" > $page
done
popd
''; '';
installPhase = "true"; installPhase = "true";

72
manual/preprocess.py Normal file
View file

@ -0,0 +1,72 @@
# Markdown preprocessor
#
# 1. Removes marked blocks from markdown files
# (unstable-only text from stable versions and vice versa)
# 2. Substitutes @version@ in text with the full version
# 3. Substitutes @apiVersion@ in text with major.minor
#
# Environment:
# - COLMENA_VERSION=${fullVersion}
# - COLMENA_UNSTABLE="1" or unset
import json
import os
import pprint
import re
import sys
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def process(book, version, unstable):
marker_to_remove = "STABLE" if unstable else "UNSTABLE"
api_version = re.match("^[0-9]+\.[0-9]+(?=$|\.[0-9]+(.*)?$)", version)
if api_version:
api_version = api_version.group()
else:
api_version = version
version_debug = f"{version} (apiVersion={api_version}, unstable={str(unstable)})"
def replace_version_markers(s):
s = s.replace("@version@", version)
s = s.replace("@apiVersion@", api_version)
return s
def process_item(item):
chapter = item["Chapter"]
for sub_item in chapter["sub_items"]:
process_item(sub_item)
regex = r".*\b{marker}_BEGIN\b(.|\n|\r)*?\b{marker}_END\b.*".format(marker=marker_to_remove)
chapter["content"] = f"<!-- Generated from version {version_debug} -->\n" + chapter["content"]
chapter["content"] = re.sub(regex, "", chapter["content"])
chapter["content"] = replace_version_markers(chapter["content"])
#eprint(f"Processed {chapter['name']}")
eprint(f"Version is {version_debug}")
for section in book['sections']:
process_item(section)
if __name__ == "__main__":
if len(sys.argv) > 1:
if sys.argv[1] == "supports":
#eprint("mdbook asked about support for", sys.argv[2])
sys.exit(0)
version = os.environ.get("COLMENA_VERSION", "unstable")
unstable = bool(os.environ.get("COLMENA_UNSTABLE", ""))
if version in [ "" "unstable" ]:
unstable = True
context, book = json.load(sys.stdin)
process(book, version, unstable)
print(json.dumps(book))

View file

@ -18,7 +18,14 @@ Interested? Get started [here](tutorial)!
<b>kappa</b> ✅ 2s Activation successful <b>kappa</b> ✅ 2s Activation successful
</div></pre> </div></pre>
You are currently reading **the unstable version** of the Colmena Manual, built against the tip of [the development branch](https://github.com/zhaofengli/colmena).<!-- REMOVE_FOR_RELEASE --> <!-- UNSTABLE_BEGIN -->
You are currently reading **the unstable version** of the Colmena Manual, built against the tip of [the development branch](https://github.com/zhaofengli/colmena).
Features described here will eventually become a part of **version @apiVersion@**.
<!-- UNSTABLE_END -->
<!-- STABLE_BEGIN -->
You are currently reading **version @apiVersion@** of the Colmena Manual, built against version @version@.
<!-- STABLE_END -->
## Links ## Links

View file

@ -1,7 +1,16 @@
# Command Line Arguments # Command Line Arguments
You are currently reading **the unstable version** of the Colmena Manual, built against the tip of [the development branch](https://github.com/zhaofengli/colmena). <!-- REMOVE_FOR_RELEASE --> <!-- UNSTABLE_BEGIN -->
You are currently reading **the unstable version** of the Colmena Manual, built against the tip of [the development branch](https://github.com/zhaofengli/colmena).
<!-- UNSTABLE_END -->
The following are the auto-generated help messages that are printed when you invoke any sub-command with `--help`: The following are the help messages that will be printed when you invoke any sub-command with `--help`:
<!-- The following is injected by the build system --> <!--
The following is injected by the build system
Looking to improve the help messages? They are located in:
- src/cli.rs
- src/command/<subcommand>.rs
-->

View file

@ -1,7 +1,13 @@
# Deployment Options # Deployment Options
You are currently reading **the unstable version** of the Colmena Manual, built against the tip of [the development branch](https://github.com/zhaofengli/colmena). <!-- REMOVE_FOR_RELEASE --> <!-- UNSTABLE_BEGIN -->
You are currently reading **the unstable version** of the Colmena Manual, built against the tip of [the development branch](https://github.com/zhaofengli/colmena).
<!-- UNSTABLE_END -->
Colmena adds a set of extra options that can be used in your NixOS configurations under the `deployment` prefix. Colmena adds a set of extra options that can be used in your NixOS configurations under the `deployment` prefix.
<!-- The following is injected by the build system --> <!--
The following is injected by the build system
Looking to improve the description? Head to `src/nix/eval.nix` in the repo :)
-->

View file

@ -1,6 +1,8 @@
# Reference # Reference
You are currently reading **the unstable version** of the Colmena Manual, built against the tip of [the development branch](https://github.com/zhaofengli/colmena). Go back to [the home page](../introduction.md) for links to other versions of the manual. <!-- REMOVE_FOR_RELEASE --> <!-- UNSTABLE_BEGIN -->
You are currently reading **the unstable version** of the Colmena Manual, built against the tip of [the development branch](https://github.com/zhaofengli/colmena).
<!-- UNSTABLE_END -->
This section contains detailed listings of options and parameters accepted by Colmena: This section contains detailed listings of options and parameters accepted by Colmena:

View file

@ -1,10 +1,16 @@
# Meta Options # Meta Options
You are currently reading **the unstable version** of the Colmena Manual, built against the tip of [the development branch](https://github.com/zhaofengli/colmena). <!-- REMOVE_FOR_RELEASE --> <!-- UNSTABLE_BEGIN -->
You are currently reading **the unstable version** of the Colmena Manual, built against the tip of [the development branch](https://github.com/zhaofengli/colmena).
<!-- UNSTABLE_END -->
The following is a list of options that can be added to the `meta` attribute set. The following is a list of options that can be added to the `meta` attribute set.
For compatibility with NixOps, you may name it `network` instead of `meta`. For compatibility with NixOps, you may name it `network` instead of `meta`.
However, you cannot specify both at the same time. However, you cannot specify both at the same time.
<!-- The following is injected by the build system --> <!--
The following is injected by the build system
Looking to improve the descriptions? Head to `src/nix/eval.nix` in the repo :)
-->

View file

@ -2,21 +2,35 @@
## Installation ## Installation
<!-- STABLE_BEGIN -->
Colmena doesn't have a stable release yet. Colmena doesn't have a stable release yet.
To quickly try Colmena out, use the following command to enter an ephemeral environment with `colmena`:
```console If you are interested in trying out the bleeding-edge version of Colmena, Read [the unstable version](https://zhaofengli.github.io/colmena/unstable) of the Manual for instructions.
$ nix shell github:zhaofengli/colmena <!-- STABLE_END -->
<!-- UNSTABLE_BEGIN -->
<!-- To install the latest stable version, read [the corresponding Manual](https://zhaofengli.github.io/colmena/stable) for instructions. -->
To quickly try Colmena out, use the following command to enter an ephemeral environment with the latest development version of `colmena`:
```bash
nix shell github:zhaofengli/colmena
``` ```
To install the latest development version to the user profile, use the following command: To install Colmena to the user profile, use the following command:
```console ```bash
$ nix-env -if https://github.com/zhaofengli/colmena/tarball/main nix-env -if https://github.com/zhaofengli/colmena/tarball/main
``` ```
You can also add `github:zhaofengli/colmena` as an input in your Flake and add the `colmena` package to your `devShell`. You can also add `github:zhaofengli/colmena` as an input in your Flake and add the `colmena` package to your `devShell`.
### Unstable Binary Cache
A public binary cache is available at [https://colmena.cachix.org](https://colmena.cachix.org), courtesy of Cachix.
This binary cache contains unstable versions of Colmena built by [GitHub Actions](https://github.com/zhaofengli/colmena/actions).
<!-- UNSTABLE_END -->
## Basic Configuration ## Basic Configuration
Colmena reads the `colmena` output in your Flake. Colmena reads the `colmena` output in your Flake.
@ -55,18 +69,18 @@ Here is a short example:
``` ```
The full set of `deployment` options can be found [here](../reference/deployment.md). The full set of `deployment` options can be found [here](../reference/deployment.md).
For some inspiration, you can check out the short example in [the main tutorial](index.md). You can also check out the example in [the main tutorial](index.md) for some inspiration.
Now you are ready to use Colmena! To build the configuration: Now you are ready to use Colmena! To build the configuration:
```console ```bash
$ colmena build colmena build
``` ```
To build and deploy to all nodes: To build and deploy to all nodes:
```console ```bash
$ colmena apply colmena apply
``` ```
## Next Steps ## Next Steps

View file

@ -2,13 +2,27 @@
## Installation ## Installation
<!-- STABLE_BEGIN -->
Colmena doesn't have a stable release yet. Colmena doesn't have a stable release yet.
If you are interested in trying out the bleeding-edge version of Colmena, Read [the unstable version](https://zhaofengli.github.io/colmena/unstable) of the Manual for instructions.
<!-- STABLE_END -->
<!-- UNSTABLE_BEGIN -->
<!-- To install the latest stable version, read [the corresponding Manual](https://zhaofengli.github.io/colmena/stable) for instructions. -->
To install the latest development version to the user profile, use the following command: To install the latest development version to the user profile, use the following command:
```console ```bash
$ nix-env -if https://github.com/zhaofengli/colmena/tarball/main nix-env -if https://github.com/zhaofengli/colmena/tarball/main
``` ```
### Unstable Binary Cache
A public binary cache is available at [https://colmena.cachix.org](https://colmena.cachix.org), courtesy of Cachix.
This binary cache contains unstable versions of Colmena built by [GitHub Actions](https://github.com/zhaofengli/colmena/actions).
<!-- UNSTABLE_END -->
## Basic Configuration ## Basic Configuration
*If you use Nix Flakes, follow the Flake version [here](flakes.md).* *If you use Nix Flakes, follow the Flake version [here](flakes.md).*
@ -108,14 +122,14 @@ The full set of `deployment` options can be found [here](../reference/deployment
Now you are ready to use Colmena! To build the configuration: Now you are ready to use Colmena! To build the configuration:
```console ```bash
$ colmena build colmena build
``` ```
To build and deploy to all nodes: To build and deploy to all nodes:
```console ```bash
$ colmena apply colmena apply
``` ```
## Next Steps ## Next Steps