Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ZFS subdirs #39

Merged
merged 4 commits into from
Apr 19, 2024
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ file in your home directory under `~/.shark`. A default is provided from the com

```sh
$ shark config
((store (Zfs obuilder-zfs)))
((store (Zfs (() obuilder-zfs false))))
```

## Markdown Support
Expand Down
26 changes: 26 additions & 0 deletions docs/zfs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ZFS Setup

The best store to use as a backend is probably ZFS. A simple setup without
changing your whole system to ZFS might look something like:


```
truncate --size XG zfs.img
sudo zpool create obuilder-zfs $PWD/zfs.img
```

And then you can run shark (from source, in a development mode).

```
sudo env "PATH=$PATH" dune exec -- shark md specs/shark.md --store=zfs:obuilder-zfs --verbose
```

If your system is booted from ZFS, then there might some `<hostname>` ZFS pool, and you will want
the datasets to be stored under a sub-dataset name for example `shark`.

```
sudo env "PATH=$PATH" dune exec -- shark md specs/shark.md --store=zfs:<hostname>:shark --zfs-path-without-pool --verbose
```

The files will be available from `/shark/results/<hash>/rootfs` after this.

2 changes: 1 addition & 1 deletion src/bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(name main)
(public_name shark)
(libraries
eio_main
eio_posix
shark
shark.server
lwt.unix
Expand Down
27 changes: 9 additions & 18 deletions src/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@ let ( / ) = Filename.concat
module Sandbox = Obuilder.Native_sandbox
module Store_spec = Obuilder.Store_spec

let store_of_string = function
| `Rsync path -> `Rsync (path, Obuilder.Rsync_store.Copy)
| (`Zfs _ | `Btrfs _ | `Xfs _ | `Docker _) as v -> v

let config_path =
let _config_path =
match Sys.getenv_opt "SHARK_CONFIG" with
| Some config -> config
| None -> (
match Sys.getenv_opt "HOME" with
| Some home -> Filename.concat home ".shark"
| None -> failwith "No SHARK_CONFIG or HOME environment variables")

let store_or_default v =
match Option.map store_of_string v with
| Some store -> Obuilder.Store_spec.to_store store
| None ->
let config = In_channel.with_open_bin config_path In_channel.input_all in
let config = Shark.Config.t_of_sexp (Sexplib.Sexp.of_string config) in
Obuilder.Store_spec.to_store config.store
(* TODO: Default store config is disabled for now *)
let store_or_default = function store -> store
(* | None ->
let config = In_channel.with_open_bin config_path In_channel.input_all in
let config = Shark.Config.t_of_sexp (Sexplib.Sexp.of_string config) in
Obuilder.Store_spec.to_store config.store *)

let run_eventloop ~clock main =
Lwt_eio.with_event_loop ~clock @@ fun _ -> main ()
Expand Down Expand Up @@ -198,7 +193,7 @@ let template ~clock ~fs () file directory =
Ok ()

let config () =
let config = Shark.Config.{ store = `Zfs "obuilder-zfs" } in
let config = Shark.Config.{ store = `Zfs (None, "obuilder-zfs", false) } in
Fmt.pr "%a" Sexplib.Sexp.pp_hum (Shark.Config.sexp_of_t config);
Ok ()

Expand Down Expand Up @@ -246,11 +241,7 @@ let src_dir =
@@ Arg.info ~doc:"Directory containing the source files." ~docv:"SRC_DIR"
[ "src_dir" ]

let store =
Arg.value
@@ Arg.opt Arg.(some Store_spec.store_t) None
@@ Arg.info ~doc:"Store for shark, defaults to configuration file."
~docv:"STORE" [ "store" ]
let store = Store_spec.cmdliner

let no_run =
Arg.value @@ Arg.flag
Expand Down
2 changes: 1 addition & 1 deletion src/test/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ case "$1" in
sudo mkdir /rsync
sudo chown "$(whoami)" /rsync

sudo "$GITHUB_WORKSPACE/_build/install/default/bin/shark" md specs/shark.md --store=rsync:/rsync --verbose
sudo "$GITHUB_WORKSPACE/_build/install/default/bin/shark" md specs/shark.md --store=rsync:/rsync --rsync-mode=hardlink --verbose

cat ./_shark/gdal.version

Expand Down
Loading