From be30738dbf716413574684d8bc101090ea94c265 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Thu, 24 Oct 2024 06:15:48 -0400 Subject: [PATCH 01/13] Add container image This change enables running emanote in a container. --- .github/workflows/ci.yaml | 13 ++++++++++ docs/start/install/container.md | 13 ++++++++++ nix/modules/flake-parts/container.nix | 37 +++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 docs/start/install/container.md create mode 100644 nix/modules/flake-parts/container.nix diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e9d0b6fe5..cfc647ae2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -63,3 +63,16 @@ jobs: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 + container: + if: github.ref == 'refs/heads/master' + runs-on: x86_64-linux + steps: + - uses: actions/checkout@v3 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + + - name: Push Image + run: nix run ".#publish-container-release" + env: + GH_USERNAME: ${{ github.actor }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/docs/start/install/container.md b/docs/start/install/container.md new file mode 100644 index 000000000..3819fcb9d --- /dev/null +++ b/docs/start/install/container.md @@ -0,0 +1,13 @@ +# Using Container + +Emanote provides a standalone container. + +Start the live server by mounting your notebook (here `./docs`) to `/site`: +```sh +podman run -it --rm -p 8080:8080 -v ./docs:/site:z ghcr.io/srid/emanote run -p 8080 +``` + +Build the static pages: +```sh +podman run -it --rm -v ./docs:/site:z -v ./output:/output:z ghcr.io/srid/emanote gen /output +``` diff --git a/nix/modules/flake-parts/container.nix b/nix/modules/flake-parts/container.nix new file mode 100644 index 000000000..02fa0094c --- /dev/null +++ b/nix/modules/flake-parts/container.nix @@ -0,0 +1,37 @@ +{ root, ... }: { + perSystem = { pkgs, config, ... }: + let + emanote = config.packages.emanote; + container-name = "ghcr.io/srid/emanote"; + container = pkgs.dockerTools.streamLayeredImage { + name = container-name; + tag = "latest"; + created = "now"; + config.Entrypoint = [ "${emanote}/bin/emanote" ]; + config.WorkingDir = "/site"; + config.Labels = { + "org.opencontainers.image.source" = "https://github.com/srid/emanote"; + }; + }; + in { + # Load the container locally with: `nix build .#container && ./result | podman load` + packages.container = container; + + # Run this script in the CI to publish a new image + apps.publish-container-release = + pkgs.writeShellScriptBin "emanote-release" '' + set -e + export PATH=$PATH:${pkgs.gzip}/bin:${pkgs.skopeo}/bin + IMAGE="docker://${container-name}" + + echo "Logging to registry..." + echo $GH_TOKEN | skopeo login --username $GH_USERNAME --password-stdin ghcr.io + + echo "Building and publishing the image..." + ${container} | gzip --fast | skopeo copy docker-archive:/dev/stdin $IMAGE:${emanote.version} + + echo "Tagging latest" + skopeo copy $IMAGE:${emanote.version} $IMAGE:latest + ''; + }; +} From c9e2b4fd6a913ae1c5b6ea0345d28d70dfd229b9 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Thu, 24 Oct 2024 08:34:59 -0400 Subject: [PATCH 02/13] Our self-hosted runners run NixOS --- .github/workflows/ci.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cfc647ae2..6d30904e9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -67,10 +67,7 @@ jobs: if: github.ref == 'refs/heads/master' runs-on: x86_64-linux steps: - - uses: actions/checkout@v3 - - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main - + - uses: actions/checkout@v4 - name: Push Image run: nix run ".#publish-container-release" env: From ea995cbab8159a9f04f8f18c9e2912128733adad Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Thu, 7 Nov 2024 20:05:42 -0500 Subject: [PATCH 03/13] container on linux only --- nix/modules/flake-parts/container.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nix/modules/flake-parts/container.nix b/nix/modules/flake-parts/container.nix index 02fa0094c..2595984bc 100644 --- a/nix/modules/flake-parts/container.nix +++ b/nix/modules/flake-parts/container.nix @@ -1,5 +1,5 @@ { root, ... }: { - perSystem = { pkgs, config, ... }: + perSystem = { pkgs, config, lib, ... }: let emanote = config.packages.emanote; container-name = "ghcr.io/srid/emanote"; @@ -13,7 +13,7 @@ "org.opencontainers.image.source" = "https://github.com/srid/emanote"; }; }; - in { + in lib.optionalAttrs pkgs.stdenv.isLinux { # Load the container locally with: `nix build .#container && ./result | podman load` packages.container = container; From 0938217c1c8471fa0d42641479559a7432e0b259 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Thu, 7 Nov 2024 20:08:20 -0500 Subject: [PATCH 04/13] Update container.nix --- nix/modules/flake-parts/container.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/nix/modules/flake-parts/container.nix b/nix/modules/flake-parts/container.nix index 2595984bc..65a13210f 100644 --- a/nix/modules/flake-parts/container.nix +++ b/nix/modules/flake-parts/container.nix @@ -13,13 +13,13 @@ "org.opencontainers.image.source" = "https://github.com/srid/emanote"; }; }; - in lib.optionalAttrs pkgs.stdenv.isLinux { + in { # Load the container locally with: `nix build .#container && ./result | podman load` - packages.container = container; + packages = lib.optionalAttrs pkgs.stdenv.isLinux { container = container }; # Run this script in the CI to publish a new image - apps.publish-container-release = - pkgs.writeShellScriptBin "emanote-release" '' + apps = lib.optionalAttrs pkgs.stdenv.isLinux { + publish-container-release = pkgs.writeShellScriptBin "emanote-release" '' set -e export PATH=$PATH:${pkgs.gzip}/bin:${pkgs.skopeo}/bin IMAGE="docker://${container-name}" @@ -33,5 +33,6 @@ echo "Tagging latest" skopeo copy $IMAGE:${emanote.version} $IMAGE:latest ''; + }; }; } From c225a7697ad940d7e3db4c3f94c82cd6e83dc091 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Thu, 7 Nov 2024 20:09:40 -0500 Subject: [PATCH 05/13] Update container.nix --- nix/modules/flake-parts/container.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/modules/flake-parts/container.nix b/nix/modules/flake-parts/container.nix index 65a13210f..896351490 100644 --- a/nix/modules/flake-parts/container.nix +++ b/nix/modules/flake-parts/container.nix @@ -15,7 +15,7 @@ }; in { # Load the container locally with: `nix build .#container && ./result | podman load` - packages = lib.optionalAttrs pkgs.stdenv.isLinux { container = container }; + packages = lib.optionalAttrs pkgs.stdenv.isLinux { container = container; }; # Run this script in the CI to publish a new image apps = lib.optionalAttrs pkgs.stdenv.isLinux { From 03101bd14cd44fd7d475b880d0cbf843cc5aa6d9 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Thu, 7 Nov 2024 20:11:40 -0500 Subject: [PATCH 06/13] Update container.nix --- nix/modules/flake-parts/container.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/modules/flake-parts/container.nix b/nix/modules/flake-parts/container.nix index 896351490..4989e4445 100644 --- a/nix/modules/flake-parts/container.nix +++ b/nix/modules/flake-parts/container.nix @@ -19,7 +19,7 @@ # Run this script in the CI to publish a new image apps = lib.optionalAttrs pkgs.stdenv.isLinux { - publish-container-release = pkgs.writeShellScriptBin "emanote-release" '' + publish-container-release.program = pkgs.writeShellScriptBin "emanote-release" '' set -e export PATH=$PATH:${pkgs.gzip}/bin:${pkgs.skopeo}/bin IMAGE="docker://${container-name}" From 7f7cc8188673e9ed6991c69b9651e31a552584d3 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Thu, 7 Nov 2024 20:13:15 -0500 Subject: [PATCH 07/13] fmt --- nix/modules/flake-parts/container.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nix/modules/flake-parts/container.nix b/nix/modules/flake-parts/container.nix index 4989e4445..8f85fff11 100644 --- a/nix/modules/flake-parts/container.nix +++ b/nix/modules/flake-parts/container.nix @@ -13,12 +13,13 @@ "org.opencontainers.image.source" = "https://github.com/srid/emanote"; }; }; - in { + in + { # Load the container locally with: `nix build .#container && ./result | podman load` packages = lib.optionalAttrs pkgs.stdenv.isLinux { container = container; }; # Run this script in the CI to publish a new image - apps = lib.optionalAttrs pkgs.stdenv.isLinux { + apps = lib.optionalAttrs pkgs.stdenv.isLinux { publish-container-release.program = pkgs.writeShellScriptBin "emanote-release" '' set -e export PATH=$PATH:${pkgs.gzip}/bin:${pkgs.skopeo}/bin From 6e0f0b7919d70a8dc6aeeddd59cfb3f1d927abaa Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Thu, 7 Nov 2024 20:14:22 -0500 Subject: [PATCH 08/13] slug --- docs/start/install/container.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/start/install/container.md b/docs/start/install/container.md index 3819fcb9d..5f200fc32 100644 --- a/docs/start/install/container.md +++ b/docs/start/install/container.md @@ -1,3 +1,7 @@ +--- +slug: container +--- + # Using Container Emanote provides a standalone container. From 04341b9586824bc3877af6adb627b0e7e3dbe4ac Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Thu, 7 Nov 2024 20:14:44 -0500 Subject: [PATCH 09/13] try darwin --- nix/modules/flake-parts/container.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nix/modules/flake-parts/container.nix b/nix/modules/flake-parts/container.nix index 8f85fff11..7431929de 100644 --- a/nix/modules/flake-parts/container.nix +++ b/nix/modules/flake-parts/container.nix @@ -16,10 +16,10 @@ in { # Load the container locally with: `nix build .#container && ./result | podman load` - packages = lib.optionalAttrs pkgs.stdenv.isLinux { container = container; }; + packages = { container = container; }; # Run this script in the CI to publish a new image - apps = lib.optionalAttrs pkgs.stdenv.isLinux { + apps = { publish-container-release.program = pkgs.writeShellScriptBin "emanote-release" '' set -e export PATH=$PATH:${pkgs.gzip}/bin:${pkgs.skopeo}/bin From b6c4fbeb56f6884c8ae5bda2ae5126ca7b336e9d Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Thu, 7 Nov 2024 20:15:46 -0500 Subject: [PATCH 10/13] Test CI --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6d30904e9..357acfde0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -64,7 +64,7 @@ jobs: id: deployment uses: actions/deploy-pages@v4 container: - if: github.ref == 'refs/heads/master' + # if: github.ref == 'refs/heads/master' runs-on: x86_64-linux steps: - uses: actions/checkout@v4 From 93e0619bbcb261284d93197d67aa12eaec1dcca8 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Fri, 8 Nov 2024 17:32:04 -0500 Subject: [PATCH 11/13] XDG_RUNTIME_DIR --- .github/workflows/ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 357acfde0..4c0f5e518 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -68,6 +68,8 @@ jobs: runs-on: x86_64-linux steps: - uses: actions/checkout@v4 + - name: Set XDG_RUNTIME_DIR + run: echo "XDG_RUNTIME_DIR=/run/user/$UID" >> $GITHUB_ENV - name: Push Image run: nix run ".#publish-container-release" env: From 79aa44ba76b51b07ad36196b67a0280aea0bd47f Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Fri, 8 Nov 2024 18:11:27 -0500 Subject: [PATCH 12/13] Update ci.yaml --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4c0f5e518..0cb47ba19 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -69,7 +69,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set XDG_RUNTIME_DIR - run: echo "XDG_RUNTIME_DIR=/run/user/$UID" >> $GITHUB_ENV + run: echo "XDG_RUNTIME_DIR=$HOME/.xdg-runtime" >> $GITHUB_ENV - name: Push Image run: nix run ".#publish-container-release" env: From b6e737e381e839757c76cbd149986bf8579ddd9e Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Fri, 8 Nov 2024 18:23:25 -0500 Subject: [PATCH 13/13] Update ci.yaml --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0cb47ba19..cc1a5b6f0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -69,7 +69,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set XDG_RUNTIME_DIR - run: echo "XDG_RUNTIME_DIR=$HOME/.xdg-runtime" >> $GITHUB_ENV + run: mkdir ~/.xdg-runtime && echo "XDG_RUNTIME_DIR=$HOME/.xdg-runtime" >> $GITHUB_ENV - name: Push Image run: nix run ".#publish-container-release" env: