Skip to content

Commit

Permalink
Add container image
Browse files Browse the repository at this point in the history
This change enables running emanote in a container.
  • Loading branch information
TristanCacqueray committed Oct 24, 2024
1 parent 13125a0 commit c4519f0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
13 changes: 13 additions & 0 deletions docs/start/install/container.md
Original file line number Diff line number Diff line change
@@ -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
```
37 changes: 37 additions & 0 deletions nix/modules/flake-parts/container.nix
Original file line number Diff line number Diff line change
@@ -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
'';
};
}

0 comments on commit c4519f0

Please sign in to comment.