Skip to content

Commit

Permalink
use "temporary" instead of anonymous and update library (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros-k authored Jul 30, 2024
1 parent 66fd6a3 commit 869f32e
Show file tree
Hide file tree
Showing 44 changed files with 240 additions and 67 deletions.
4 changes: 2 additions & 2 deletions ix-dev/community/jellyfin/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ keywords:
- media
- streaming
lib_version: 1.0.0
lib_version_hash: 04058cefffe4eeadb07035ab157987492a31d5708705d6b7153d262beb75a796
lib_version_hash: 8e293d07d49bc9e9d34ec6d9cc12526d7cfdf043092d437885eb4bdbaf4b3ae4
maintainers:
- email: [email protected]
name: truenas
Expand All @@ -35,4 +35,4 @@ sources:
- https://jellyfin.org/
title: Jellyfin
train: community
version: 1.0.0
version: 1.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def migrate_empty_dir_type(empty_dir):
"tmpfs_config": {"size": size},
}

return {"type": "anonymous"}
return {"type": "temporary"}


def migrate_ix_volume_type(ix_volume):
Expand Down
8 changes: 4 additions & 4 deletions ix-dev/community/jellyfin/questions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,19 @@ questions:
description: |
ixVolume: Is dataset created automatically by the system.</br>
Host Path: Is a path that already exists on the system.
Anonymous: Is a temporary directory that will be created on the disk as a docker volume.
Temporary: Is a temporary directory that will be created on the disk as a docker volume.
tmpfs: Is a temporary directory that will be created on the RAM.
schema:
type: string
required: true
default: "anonymous"
default: "temporary"
enum:
- value: "host_path"
description: Host Path (Path that already exists on the system)
- value: "ix_volume"
description: ixVolume (Dataset created automatically by the system)
- value: "anonymous"
description: Anonymous (Temporary directory created on the disk)
- value: "temporary"
description: Temporary (Temporary directory created on the disk)
- value: "tmpfs"
description: tmpfs (Temporary directory created on the RAM)
- variable: tmpfs_config
Expand Down
6 changes: 4 additions & 2 deletions ix-dev/community/jellyfin/templates/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
{% do storage_items.items.append(ix_lib.base.storage.storage_item(data=dict(values.storage.transcodes, **{"mount_path": "/config/transcodes"}),
ix_volumes=values.ix_volumes, perm_opts={"mount_path": "/mnt/jellyfin/transcodes", "mode": "check", "uid": values.run_as.user, "gid": values.run_as.group}
)) %}
{% do storage_items.items.append(ix_lib.base.storage.storage_item(data={"type":"anonymous", "mount_path": "/tmp"})) %}
{% do storage_items.items.append(ix_lib.base.storage.storage_item(data={"type": "temporary", "mount_path": "/tmp"},
perm_opts={"mount_path": "/mnt/jellyfin/tmp", "mode": "check", "uid": values.run_as.user, "gid": values.run_as.group}
)) %}

{% for store in values.storage.additional_storage %}
{% do storage_items.items.append(ix_lib.base.storage.storage_item(data=store, ix_volumes=values.ix_volumes,
perm_opts={"mount_path": "/mnt/jellyfin/dir_%s"|format(loop.index0), "mode": "check", "uid": values.run_as.user, "gid": values.run_as.group}
perm_opts={"mount_path": "/mnt/jellyfin/dir_%s"|format(loop.index0), "mode": "check", "uid": values.run_as.user, "gid": values.run_as.group}
)) %}
{% endfor %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def get_portals(portals: list):
{
"name": name,
"scheme": scheme,
# TODO: Default to something else?
"host": portal.get("host", "0.0.0.0"),
"port": portal["port"],
"path": path,
Expand Down
26 changes: 23 additions & 3 deletions ix-dev/community/jellyfin/templates/library/base_v1_0_0/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@


BIND_TYPES = ["host_path", "ix_volume"]
VOL_TYPES = ["volume", "nfs", "cifs"]
VOL_TYPES = ["volume", "nfs", "cifs", "temporary"]
ALL_TYPES = BIND_TYPES + VOL_TYPES + ["tmpfs", "anonymous"]
PROPAGATION_TYPES = ["shared", "slave", "private", "rshared", "rslave", "rprivate"]


def _get_name_for_temporary(data):
if not data.get("mount_path"):
utils.throw_error("Expected [mount_path] to be set for temporary volume")

return (
data["mount_path"]
.lstrip("/")
.lower()
.replace("/", "_")
.replace(".", "_")
.replace(" ", "_")
)


# Returns a volume mount object (Used in container's "volumes" level)
def vol_mount(data, ix_volumes=None):
ix_volumes = ix_volumes or []
Expand All @@ -25,6 +39,9 @@ def vol_mount(data, ix_volumes=None):
volume.update(_get_volume_vol_config(data))
elif vol_type == "tmpfs":
volume.update(_get_tmpfs_vol_config(data))
elif vol_type == "temporary":
volume["type"] = "volume"
volume.update(_get_volume_vol_config(data))
elif vol_type == "anonymous":
volume["type"] = "volume"
volume.update(_get_anonymous_vol_config(data))
Expand All @@ -35,6 +52,8 @@ def vol_mount(data, ix_volumes=None):
def storage_item(data, ix_volumes=None, perm_opts=None):
ix_volumes = ix_volumes or []
perm_opts = perm_opts or {}
if data.get("type") == "temporary":
data.update({"volume_name": _get_name_for_temporary(data)})
return {
"vol_mount": vol_mount(data, ix_volumes),
"vol": vol(data),
Expand All @@ -44,7 +63,7 @@ def storage_item(data, ix_volumes=None, perm_opts=None):

def perms_item(data, ix_volumes, opts=None):
opts = opts or {}
if not data.get("auto_permissions"):
if not data.get("auto_permissions") and not data.get("type") == "temporary":
return {}

if data.get("type") == "host_path":
Expand Down Expand Up @@ -74,7 +93,8 @@ def perms_item(data, ix_volumes, opts=None):
"mode": opts["mode"],
"uid": opts["uid"],
"gid": opts["gid"],
"chmod": opts.get("chmod", ""),
"chmod": opts.get("chmod", "false"),
"is_temporary": data["type"] == "temporary",
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ command:
- |
{{- process_dir_func() | indent(4) }}
{%- for item in items %}
process_dir {{ item.dir }} {{ item.mode }} {{ item.uid }} {{ item.gid }} {{ item.chmod }}
process_dir {{ item.dir }} {{ item.mode }} {{ item.uid }} {{ item.gid }} {{ item.chmod }} {{ item.is_temporary|lower }}
{%- endfor %}
{% endmacro %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function process_dir() {
local uid=$$3
local gid=$$4
local chmod=$$5
local is_temporary=$$6

local fix_owner="false"
local fix_perms="false"
Expand All @@ -19,6 +20,11 @@ function process_dir() {
exit 0
fi

if [ "$$is_temporary" = "true" ]; then
echo "Path [$$dir] is a temporary directory, ensuring it is empty..."
rm -rf "$$dir/{*,.*}"
fi

echo "Current Ownership and Permissions on [$$dir]:"
echo "chown: $$(stat -c "%u %g" "$$dir")"
echo "chmod: $$(stat -c "%a" "$$dir")"
Expand All @@ -37,7 +43,9 @@ function process_dir() {
fix_owner="true"
fi

if [ -n "$$chmod" ]; then
if [ "$$chmod" = "false" ]; then
echo "Skipping permissions check, chmod is false"
elif [ -n "$$chmod" ]; then
if [ $$(stat -c %a "$$dir") -eq $$chmod ]; then
echo "Permissions are correct. Skipping..."
fix_perms="false"
Expand All @@ -47,6 +55,7 @@ function process_dir() {
fi
fi
fi

if [ "$$fix_owner" = "true" ]; then
echo "Changing ownership to $$uid:$$gid on: [$$dir]"
chown -R "$$uid:$$gid" "$$dir"
Expand Down
4 changes: 2 additions & 2 deletions ix-dev/community/qbittorrent/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords:
- torrent
- download
lib_version: 1.0.0
lib_version_hash: 04058cefffe4eeadb07035ab157987492a31d5708705d6b7153d262beb75a796
lib_version_hash: 8e293d07d49bc9e9d34ec6d9cc12526d7cfdf043092d437885eb4bdbaf4b3ae4
maintainers:
- email: [email protected]
name: truenas
Expand All @@ -31,4 +31,4 @@ sources:
- https://www.qbittorrent.org/
title: qBittorrent
train: community
version: 1.0.0
version: 1.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def migrate_empty_dir_type(empty_dir):
"tmpfs_config": {"size": size},
}

return {"type": "anonymous"}
return {"type": "temporary"}


def migrate_ix_volume_type(ix_volume):
Expand Down
7 changes: 4 additions & 3 deletions ix-dev/community/qbittorrent/templates/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
{% do storage_items.items.append(ix_lib.base.storage.storage_item(data=dict(values.storage.config, **{"mount_path": "/downloads"}),
ix_volumes=values.ix_volumes, perm_opts={"mount_path": "/mnt/qbittorrent/config", "mode": "check", "uid": values.run_as.user, "gid": values.run_as.group}
)) %}
{% do storage_items.items.append(ix_lib.base.storage.storage_item(data={"type":"anonymous", "mount_path": "/tmp"})) %}

{% do storage_items.items.append(ix_lib.base.storage.storage_item(data={"type": "temporary", "mount_path": "/tmp"},
perm_opts={"mount_path": "/mnt/qbittorrent/tmp", "mode": "check", "uid": values.run_as.user, "gid": values.run_as.group}
)) %}
{% for store in values.storage.additional_storage %}
{% do storage_items.items.append(ix_lib.base.storage.storage_item(data=store, ix_volumes=values.ix_volumes,
perm_opts={"mount_path": "/mnt/qbittorrent/dir_%s"|format(loop.index0), "mode": "check", "uid": values.run_as.user, "gid": values.run_as.group}
perm_opts={"mount_path": "/mnt/qbittorrent/dir_%s"|format(loop.index0), "mode": "check", "uid": values.run_as.user, "gid": values.run_as.group}
)) %}
{% endfor %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def get_portals(portals: list):
{
"name": name,
"scheme": scheme,
# TODO: Default to something else?
"host": portal.get("host", "0.0.0.0"),
"port": portal["port"],
"path": path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@


BIND_TYPES = ["host_path", "ix_volume"]
VOL_TYPES = ["volume", "nfs", "cifs"]
VOL_TYPES = ["volume", "nfs", "cifs", "temporary"]
ALL_TYPES = BIND_TYPES + VOL_TYPES + ["tmpfs", "anonymous"]
PROPAGATION_TYPES = ["shared", "slave", "private", "rshared", "rslave", "rprivate"]


def _get_name_for_temporary(data):
if not data.get("mount_path"):
utils.throw_error("Expected [mount_path] to be set for temporary volume")

return (
data["mount_path"]
.lstrip("/")
.lower()
.replace("/", "_")
.replace(".", "_")
.replace(" ", "_")
)


# Returns a volume mount object (Used in container's "volumes" level)
def vol_mount(data, ix_volumes=None):
ix_volumes = ix_volumes or []
Expand All @@ -25,6 +39,9 @@ def vol_mount(data, ix_volumes=None):
volume.update(_get_volume_vol_config(data))
elif vol_type == "tmpfs":
volume.update(_get_tmpfs_vol_config(data))
elif vol_type == "temporary":
volume["type"] = "volume"
volume.update(_get_volume_vol_config(data))
elif vol_type == "anonymous":
volume["type"] = "volume"
volume.update(_get_anonymous_vol_config(data))
Expand All @@ -35,6 +52,8 @@ def vol_mount(data, ix_volumes=None):
def storage_item(data, ix_volumes=None, perm_opts=None):
ix_volumes = ix_volumes or []
perm_opts = perm_opts or {}
if data.get("type") == "temporary":
data.update({"volume_name": _get_name_for_temporary(data)})
return {
"vol_mount": vol_mount(data, ix_volumes),
"vol": vol(data),
Expand All @@ -44,7 +63,7 @@ def storage_item(data, ix_volumes=None, perm_opts=None):

def perms_item(data, ix_volumes, opts=None):
opts = opts or {}
if not data.get("auto_permissions"):
if not data.get("auto_permissions") and not data.get("type") == "temporary":
return {}

if data.get("type") == "host_path":
Expand Down Expand Up @@ -74,7 +93,8 @@ def perms_item(data, ix_volumes, opts=None):
"mode": opts["mode"],
"uid": opts["uid"],
"gid": opts["gid"],
"chmod": opts.get("chmod", ""),
"chmod": opts.get("chmod", "false"),
"is_temporary": data["type"] == "temporary",
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ command:
- |
{{- process_dir_func() | indent(4) }}
{%- for item in items %}
process_dir {{ item.dir }} {{ item.mode }} {{ item.uid }} {{ item.gid }} {{ item.chmod }}
process_dir {{ item.dir }} {{ item.mode }} {{ item.uid }} {{ item.gid }} {{ item.chmod }} {{ item.is_temporary|lower }}
{%- endfor %}
{% endmacro %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function process_dir() {
local uid=$$3
local gid=$$4
local chmod=$$5
local is_temporary=$$6

local fix_owner="false"
local fix_perms="false"
Expand All @@ -19,6 +20,11 @@ function process_dir() {
exit 0
fi

if [ "$$is_temporary" = "true" ]; then
echo "Path [$$dir] is a temporary directory, ensuring it is empty..."
rm -rf "$$dir/{*,.*}"
fi

echo "Current Ownership and Permissions on [$$dir]:"
echo "chown: $$(stat -c "%u %g" "$$dir")"
echo "chmod: $$(stat -c "%a" "$$dir")"
Expand All @@ -37,7 +43,9 @@ function process_dir() {
fix_owner="true"
fi

if [ -n "$$chmod" ]; then
if [ "$$chmod" = "false" ]; then
echo "Skipping permissions check, chmod is false"
elif [ -n "$$chmod" ]; then
if [ $$(stat -c %a "$$dir") -eq $$chmod ]; then
echo "Permissions are correct. Skipping..."
fix_perms="false"
Expand All @@ -47,6 +55,7 @@ function process_dir() {
fi
fi
fi

if [ "$$fix_owner" = "true" ]; then
echo "Changing ownership to $$uid:$$gid on: [$$dir]"
chown -R "$$uid:$$gid" "$$dir"
Expand Down
4 changes: 2 additions & 2 deletions ix-dev/community/radarr/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords:
- media
- movies
lib_version: 1.0.0
lib_version_hash: 04058cefffe4eeadb07035ab157987492a31d5708705d6b7153d262beb75a796
lib_version_hash: 8e293d07d49bc9e9d34ec6d9cc12526d7cfdf043092d437885eb4bdbaf4b3ae4
maintainers:
- email: [email protected]
name: truenas
Expand All @@ -32,4 +32,4 @@ sources:
- https://github.com/Radarr/Radarr
title: Radarr
train: community
version: 1.0.0
version: 1.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def migrate_empty_dir_type(empty_dir):
"tmpfs_config": {"size": size},
}

return {"type": "anonymous"}
return {"type": "temporary"}


def migrate_ix_volume_type(ix_volume):
Expand Down
4 changes: 3 additions & 1 deletion ix-dev/community/radarr/templates/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
{% do storage_items.items.append(ix_lib.base.storage.storage_item(data=dict(values.storage.config, **{"mount_path": "/config"}),
ix_volumes=values.ix_volumes, perm_opts={"mount_path": "/mnt/radarr/config", "mode": "check", "uid": values.run_as.user, "gid": values.run_as.group}
)) %}
{% do storage_items.items.append(ix_lib.base.storage.storage_item(data={"type":"anonymous", "mount_path": "/tmp"})) %}
{% do storage_items.items.append(ix_lib.base.storage.storage_item(data={"type": "temporary", "mount_path": "/tmp"},
perm_opts={"mount_path": "/mnt/radarr/tmp", "mode": "check", "uid": values.run_as.user, "gid": values.run_as.group}
)) %}

{% for store in values.storage.additional_storage %}
{% do storage_items.items.append(ix_lib.base.storage.storage_item(data=store, ix_volumes=values.ix_volumes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def get_portals(portals: list):
{
"name": name,
"scheme": scheme,
# TODO: Default to something else?
"host": portal.get("host", "0.0.0.0"),
"port": portal["port"],
"path": path,
Expand Down
Loading

0 comments on commit 869f32e

Please sign in to comment.