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..6f8076233 --- /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 -p 8080:8080 -v ./docs:/site:z ghcr.io/srid/emanote run -p 8080 +``` + +Build the static pages: +```sh +podman run -it -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 + ''; + }; +}