Skip to content

Commit

Permalink
filebrowser: use v2 (#1028)
Browse files Browse the repository at this point in the history
* filebrowser: use v2

* fix paths

* better

* fix script
  • Loading branch information
stavros-k authored Nov 27, 2024
1 parent a75c73c commit d48e290
Show file tree
Hide file tree
Showing 69 changed files with 5,715 additions and 1,464 deletions.
6 changes: 3 additions & 3 deletions ix-dev/community/filebrowser/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ icon: https://media.sys.truenas.net/apps/filebrowser/icons/icon.png
keywords:
- files
- browser
lib_version: 1.1.7
lib_version_hash: d05e43e25b7dc1736be6cc1efa4b9255368aa346e3e7a4350a38440f29b73186
lib_version: 2.0.21
lib_version_hash: e2faccd282b768e411919a7386a03e8491d1a7fda2da586dcf9af0d412733b8a
maintainers:
- email: [email protected]
name: truenas
Expand All @@ -33,4 +33,4 @@ sources:
- https://hub.docker.com/r/filebrowser/filebrowser
title: File Browser
train: community
version: 1.1.15
version: 1.2.0
6 changes: 3 additions & 3 deletions ix-dev/community/filebrowser/ix_values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ images:
tag: v2.31.2

consts:
filebrowser_container_name: filebrowser
init_container_name: init
perms_container_name: permissions
data_path: /data
config_path: /config
ssl_cert_path: /certs/tls.crt
ssl_key_path: /certs/tls.key
filebrowser_container_name: filebrowser
init_container_name: init
perms_container_name: permissions
38 changes: 38 additions & 0 deletions ix-dev/community/filebrowser/questions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ groups:
description: Configure Network for File Browser
- name: Storage Configuration
description: Configure Storage for File Browser
- name: Labels Configuration
description: Configure Labels for File Browser
- name: Resources Configuration
description: Configure Resources for File Browser

Expand Down Expand Up @@ -314,6 +316,42 @@ questions:
description: The domain to use for the SMB share.
schema:
type: string
- variable: labels
label: ""
group: Labels Configuration
schema:
type: list
default: []
items:
- variable: label
label: Label
schema:
type: dict
attrs:
- variable: key
label: Key
schema:
type: string
required: true
- variable: value
label: Value
schema:
type: string
required: true
- variable: containers
label: Containers
description: Containers where the label should be applied
schema:
type: list
items:
- variable: container
label: Container
schema:
type: string
required: true
enum:
- value: filebrowser
description: filebrowser
- variable: resources
label: ""
group: Resources Configuration
Expand Down
178 changes: 56 additions & 122 deletions ix-dev/community/filebrowser/templates/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,134 +1,68 @@
{# Stores storage items that contains info for volumes, vol mounts, perms dirs and perms mounts #}
{% set storage_items = namespace(items=[]) %}
{# Stores the top level volumes #}
{% set volumes = namespace(items={}) %}
{# Stores the container volume mounts #}
{% set volume_mounts = namespace(items=[]) %}
{# Stores the perms container volume mounts #}
{% set perms_mounts = namespace(items=[]) %}
{# Stores the perms container dirs #}
{% set perms_dirs = namespace(items=[]) %}

{% do storage_items.items.append(ix_lib.base.storage.storage_item(data=dict(values.storage.config, **{"mount_path": values.consts.config_path}),
values=values, perm_opts={"mount_path": "/mnt/filebrowser/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"})) %}
{% from "macros/script.sh" import script %}
{% set tpl = ix_lib.base.render.Render(values) %}

{% if not values.storage.additional_storage %}
{% do ix_lib.base.utils.throw_error("Expected atleast 1 [storage.additional_storage] to be set") %}
{% do tpl.funcs.fail("Expected at least 1 [storage.additional_storage] to be set") %}
{% endif %}

{% for store in values.storage.additional_storage %}
{% set mount_path = "%s/%s"|format(values.consts.data_path, store.mount_path)|replace("//", "/") %}
{% do storage_items.items.append(ix_lib.base.storage.storage_item(data=dict(store, **{"mount_path": mount_path}), values=values,
perm_opts={"mount_path": "/mnt/filebrowser/dir_%s"|format(loop.index0), "mode": "check", "uid": values.run_as.user, "gid": values.run_as.group}
)) %}
{% endfor %}
{% set proto = "https" if values.network.certificate_id else "http" %}
{% set c1 = tpl.add_container(values.consts.filebrowser_container_name, "image") %}
{% set init = tpl.add_container(values.consts.init_container_name, "image") %}
{% set perm_container = tpl.deps.perms(values.consts.perms_container_name) %}
{% set perms_config = {"uid": values.run_as.user, "gid": values.run_as.group, "mode": "check"} %}

{# Add each item to the above lists #}
{% for item in storage_items.items %}
{% if item.vol and volumes.items.update(item.vol) %}{% endif %}
{% if item.vol_mount and volume_mounts.items.append(item.vol_mount) %}{% endif %}
{% if item.perms_item and (perms_dirs.items.append(item.perms_item.perm_dir), perms_mounts.items.append(item.perms_item.vol_mount)) %}{% endif %}
{% endfor %}
{% do init.set_user(values.run_as.user, values.run_as.group) %}
{% do init.deploy.resources.set_profile("low") %}
{% do init.remove_devices() %}
{% do init.restart.set_policy("on-failure", 1) %}
{% do init.set_network_mode("none") %}
{% do init.healthcheck.disable() %}
{% do init.configs.add("script.sh", script(values), "/script.sh", "0755") %}
{% do init.set_entrypoint(["/script.sh"]) %}

{% do c1.set_user(values.run_as.user, values.run_as.group) %}
{% do c1.depends.add_dependency(values.consts.init_container_name, "service_completed_successfully") %}
{% set cmd = namespace(x=[
"--config", "%s/filebrowser.json"|format(values.consts.config_path),
"--database", "%s/filebrowser.db"|format(values.consts.config_path),
"--port", "%s"|format(values.network.web_port),
"--address", "0.0.0.0",
"--root", values.consts.data_path,
]) %}

{% if values.network.certificate_id %}
configs:
private:
content: {{ values.ix_certificates[values.network.certificate_id].privatekey | tojson }}
public:
content: {{ values.ix_certificates[values.network.certificate_id].certificate | tojson }}
{% set cert = values.ix_certificates[values.network.certificate_id] %}
{% do c1.configs.add("private", cert.privatekey, values.consts.ssl_key_path) %}
{% do c1.configs.add("public", cert.certificate, values.consts.ssl_cert_path) %}

{% do cmd.x.extend(["--cert", values.consts.ssl_cert_path]) %}
{% do cmd.x.extend(["--key", values.consts.ssl_key_path]) %}
{% endif %}

{# Containers #}
services:
{{ values.consts.init_container_name }}:
image: {{ ix_lib.base.utils.get_image(images=values.images, name="image") }}
user: {{ "%d:%d" | format(values.run_as.user, values.run_as.group) }}
deploy:
resources:
limits:
cpus: "1.0"
memory: 512m
{% if perms_dirs.items %}
depends_on:
{{ values.consts.perms_container_name }}:
condition: service_completed_successfully
{% endif %}
entrypoint:
- sh
- -c
command:
- |
if [ ! -f {{ values.consts.config_path }}/filebrowser.json ]; then
echo "Filebrowser config file does not exist. Creating an empty one..."
echo '{}' > {{ values.consts.config_path }}/filebrowser.json
fi
volumes: {{ volume_mounts.items | tojson }}
{{ values.consts.filebrowser_container_name }}:
user: {{ "%d:%d" | format(values.run_as.user, values.run_as.group) }}
image: {{ ix_lib.base.utils.get_image(images=values.images, name="image") }}
restart: unless-stopped
deploy:
resources: {{ ix_lib.base.resources.resources(values.resources) | tojson }}
devices: {{ ix_lib.base.resources.get_devices(values.resources) | tojson }}
{% if values.network.certificate_id %}
configs:
- source: private
target: {{ values.consts.ssl_key_path }}
- source: public
target: {{ values.consts.ssl_cert_path }}
{% endif %}
depends_on:
{{ values.consts.init_container_name }}:
condition: service_completed_successfully
{% if perms_dirs.items %}
{{ values.consts.perms_container_name }}:
condition: service_completed_successfully
{% endif %}
command:
- --config
- "{{ values.consts.config_path }}/filebrowser.json"
- --database
- "{{ values.consts.config_path }}/filebrowser.db"
- --port
- "{{ values.network.web_port }}"
- --address
- "0.0.0.0"
- --root
- "{{ values.consts.data_path }}"
{% if values.network.certificate_id %}
- --cert
- "{{ values.consts.ssl_cert_path }}"
- --key
- "{{ values.consts.ssl_key_path }}"
{% endif %}
{% if values.network.host_network %}
network_mode: host
{% endif %}
cap_drop: {{ ix_lib.base.security.get_caps().drop | tojson }}
security_opt: {{ ix_lib.base.security.get_sec_opts() | tojson }}
{% if values.network.dns_opts %}
dns_opt: {{ ix_lib.base.network.dns_opts(values.network.dns_opts) | tojson }}
{% endif %}
{% set test = ix_lib.base.healthchecks.curl_test(
port=values.network.web_port, path="/health",
config={"scheme": "https" if values.network.certificate_id else "http"}
) %}
healthcheck: {{ ix_lib.base.healthchecks.check_health(test) | tojson }}
environment: {{ ix_lib.base.environment.envs(app={}, user=values.filebrowser.additional_envs, values=values) | tojson }}
{% if not values.network.host_network %}
ports:
- {{ ix_lib.base.ports.get_port(port={"target": values.network.web_port, "published": values.network.web_port}) | tojson }}
{% endif %}
volumes: {{ volume_mounts.items | tojson }}
{% if perms_dirs.items %}
{{ values.consts.perms_container_name }}: {{ ix_lib.base.permissions.perms_container(items=perms_dirs.items, volumes=perms_mounts.items) | tojson }}
{% endif %}
{% do c1.set_command(cmd.x) %}

{% do c1.healthcheck.set_test("curl", {"port": values.network.web_port, "path": "/health", "scheme": proto}) %}
{% do c1.environment.add_user_envs(values.filebrowser.additional_envs) %}

{% if volumes.items %}
volumes: {{ volumes.items | tojson }}
{% do c1.ports.add_port(values.network.web_port, values.network.web_port) %}

{% do c1.add_storage(values.consts.config_path, values.storage.config) %}
{% do init.add_storage(values.consts.config_path, values.storage.config) %}
{% do perm_container.add_or_skip_action(values.consts.config_path, values.storage.config, perms_config) %}

{% for store in values.storage.additional_storage %}
{% set mount_path = "%s/%s"|format(values.consts.data_path, store.mount_path) %}
{% set mount_path = mount_path.replace("//", "/") %}
{% do c1.add_storage(mount_path, store) %}
{% do perm_container.add_or_skip_action(mount_path, store, perms_config) %}
{% endfor %}

{% if perm_container.has_actions() %}
{% do perm_container.activate() %}
{% do c1.depends.add_dependency(values.consts.perms_container_name, "service_completed_successfully") %}
{% do init.depends.add_dependency(values.consts.perms_container_name, "service_completed_successfully") %}
{% endif %}

x-portals: {{ ix_lib.base.metadata.get_portals([{"port": values.network.web_port, "scheme": "https" if values.network.certificate_id else "http"}]) | tojson }}
x-notes: {{ ix_lib.base.metadata.get_notes("Filebrowser") | tojson }}
{% do tpl.portals.add_portal({"port": values.network.web_port, "scheme": proto}) %}

{{ tpl.render() | tojson }}

This file was deleted.

Loading

0 comments on commit d48e290

Please sign in to comment.