Skip to content

Commit

Permalink
Rework the driver:
Browse files Browse the repository at this point in the history
- the driver now takes care of mounting and unmounting datasets
- datasets now use mountpoint=legacy which means we don't need to rely on zfs-mount.service to mount the datasets initially
- remove some features i don't use to make my life easier
- update dependencies and fix tests

Why? relying on zfs-mount.service means it's harder to correctly order shutdown. This should no longer matter since as long as the docker-zfs-plugin service is correctly ordered in relation to the zfs pool that houses the data shutdown should be cleaner.
  • Loading branch information
ReneHollander committed Dec 22, 2024
1 parent bc70514 commit a44d837
Show file tree
Hide file tree
Showing 16 changed files with 373 additions and 536 deletions.
1 change: 0 additions & 1 deletion .envrc.sample

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/lint.yml

This file was deleted.

51 changes: 31 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,22 @@

Docker volume plugin for creating persistent volumes as dedicated zfs datasets.

This is a fork of [TrilliumIT/docker-zfs-plugin](https://github.com/TrilliumIT/docker-zfs-plugin)
This is a fork of [ZentriaMC/docker-zfs-plugin](https://github.com/ZentriaMC/docker-zfs-plugin), which is a fork of [TrilliumIT/docker-zfs-plugin](https://github.com/TrilliumIT/docker-zfs-plugin).

## Installation

Assuming you use NixOS

```nix
{
imports = [
(import "${builtins.fetchTarball "https://github.com/ZentriaMC/docker-zfs-plugin/archive/master.tar.gz"}/nixos")
];
services.docker-zfs-plugin = {
enable = true;
datasets = [ "dpool" ];
};
}
Create a dataset with `mountpoint=legacy` which is used as the root for all other datasets created by this driver:
```sh
zfs create -p -o mountpoint=legacy pool/my/root/dataset/for/docker
```

Or with Nix Flakes:
Assuming you use NixOS:

```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
docker-zfs-plugin.url = "github:ZentriaMC/docker-zfs-plugin";
docker-zfs-plugin.url = "github:ReneHollander/docker-zfs-plugin";
docker-zfs-plugin.inputs.nixpkgs.follows = "nixpkgs";
};
Expand All @@ -43,10 +33,31 @@ Or with Nix Flakes:
}
```

## Usage
Configure the service:

After the plugin is running, you can interact with it through normal `docker volume` commands. Driver name is `zfs`
```nix
{
services.docker-zfs-plugin = {
enable = true;
datasets = [ "pool/my/root/dataset/for/docker" ];
mountDir = "/tmp/docker-volumes/zfs";
};
}
```

You can pass in ZFS attributes from the `docker volume create` command:
## Usage

`docker volume create -d zfs -o compression=lz4 -o dedup=on --name=tank/docker-volumes/data`
Example docker-compose.yml

```yml
services:
mycontainer:
# ...
volumes:
- myvolume:/workingdir
# ...
volumes:
myvolume:
driver: zfs
name: "pool/my/root/dataset/for/docker/myvolume"
```
10 changes: 4 additions & 6 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{ lib, buildGoModule }:
buildGoModule rec {
buildGoModule {
pname = "docker-zfs-plugin";
version = "2.0.0";
version = "3.0.0";

src = lib.cleanSource ./.;

vendorHash = "sha256-/oAk/gFNlS4zRBMrp1KWeyeunDKgV+p6C+jP+OwcfGg=";
vendorHash = "sha256-9bIVchjrNqXDYdLLS634QVqXmpR4NQ4ANeiwkkLEi+E=";
subPackages = [ "." ];

meta = with lib; {
supportedPlatforms = platforms.linux;
};
meta = with lib; { supportedPlatforms = platforms.linux; };
}
40 changes: 3 additions & 37 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 15 additions & 37 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,23 @@
description = "docker-zfs-plugin";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils }:
let
supportedSystems = [
"aarch64-linux"
"x86_64-linux"
];

allSystems = supportedSystems ++ [
"aarch64-darwin"
"x86_64-darwin"
];
in
(flake-utils.lib.eachSystem supportedSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
rec {
packages.docker-zfs-plugin = pkgs.callPackage ./. { };
defaultPackage = packages.docker-zfs-plugin;

checks.vm = pkgs.callPackage ./test/vm.nix {
inherit system;
dockerZfsPluginModule = self.nixosModule;
};
})) // (flake-utils.lib.eachSystem allSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShell = pkgs.mkShell {
buildInputs = with pkgs; [ go golangci-lint gopls ];
};
}
)) // {
outputs = { self, nixpkgs, ... }:
let forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ];
in {
overlays.docker-zfs-plugin = import ./nixos/overlay.nix;
overlay = self.overlays.docker-zfs-plugin;
nixosModules.docker-zfs-plugin = import ./nixos/module.nix;
nixosModule = self.nixosModules.docker-zfs-plugin;
checks = forAllSystems (system:
let
checkArgs = {
# reference to nixpkgs for the current system
pkgs = nixpkgs.legacyPackages.${system};
# this gives us a reference to our flake but also all flake inputs
inherit self;
};
in {
# import our test
vm = import ./tests/vm.nix checkArgs;
});
};
}
32 changes: 17 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
module github.com/ZentriaMC/docker-zfs-plugin
module github.com/ReneHollander/docker-zfs-plugin

go 1.16
go 1.23

require (
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8
github.com/clinta/go-zfs v0.0.0-20181025145938-e5fe14d9dcb7
github.com/coreos/go-systemd/v22 v22.5.0
github.com/docker/go-plugins-helpers v0.0.0-20240701071450-45e2431495c8
github.com/flytam/filenamify v1.2.0
github.com/urfave/cli/v2 v2.27.5
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
)

require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/coreos/go-systemd/v22 v22.3.2
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-plugins-helpers v0.0.0-20211224144127-6eecb7beb651
github.com/pkg/errors v0.9.1 // indirect
github.com/urfave/cli/v2 v2.4.5
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/sys v0.28.0 // indirect
)

replace github.com/docker/go-plugins-helpers => github.com/clinta/go-plugins-helpers v0.0.0-20200221140445-4667bb9f0ed5 // for shutdown
Loading

0 comments on commit a44d837

Please sign in to comment.