Skip to content

Commit

Permalink
syncthing
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros-k committed Feb 7, 2025
1 parent c1d22b1 commit 456e338
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 34 deletions.
4 changes: 3 additions & 1 deletion ix-dev/enterprise/syncthing/app.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
annotations:
min_scale_version: '25.04'
app_version: 1.29.2
capabilities:
- description: Syncthing is able to chown files.
Expand Down Expand Up @@ -49,4 +51,4 @@ sources:
- https://hub.docker.com/r/syncthing/syncthing
title: Syncthing
train: enterprise
version: 1.1.9
version: 1.2.0
6 changes: 6 additions & 0 deletions ix-dev/enterprise/syncthing/migrations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
migrations:
- file: ip_port_migration
# from:
# max_version: "FIXME:"
target:
min_version: 1.2.0
33 changes: 33 additions & 0 deletions ix-dev/enterprise/syncthing/migrations/ip_port_migration
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/python3

import os
import sys
import yaml


def migrate(values):
values["network"]["web_port"] = {
"port_number": values["network"]["web_port"],
"bind_mode": "published",
"host_ips": [],
}
values["network"]["tcp_port"] = {
"port_number": values["network"].get("tcp_port", 22000),
"bind_mode": "published",
"host_ips": [],
}
values["network"]["quic_port"] = {
"port_number": values["network"].get("quic_port", 22000),
"bind_mode": "published",
"host_ips": [],
}
return values


if __name__ == "__main__":
if len(sys.argv) != 2:
exit(1)

if os.path.exists(sys.argv[1]):
with open(sys.argv[1], "r") as f:
print(yaml.dump(migrate(yaml.safe_load(f.read()))))
152 changes: 135 additions & 17 deletions ix-dev/enterprise/syncthing/questions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,152 @@ questions:
type: dict
attrs:
- variable: web_port
label: Web UI Port
description: The port for the Syncthing Web UI.
label: WebUI Port
schema:
type: int
default: 8384
required: true
$ref:
- "definitions/port"
type: dict
attrs:
- variable: bind_mode
label: Port Bind Mode
description: |
The port bind mode.</br>
- Publish: The port will be published on the host for external access.</br>
- Expose: The port will be exposed for inter-container communication.</br>
- None: The port will not be exposed or published.</br>
Note: If the Dockerfile defines an EXPOSE directive,
the port will still be exposed for inter-container communication regardless of this setting.
schema:
type: string
default: "published"
enum:
- value: "published"
description: Publish port on the host for external access
- value: "exposed"
description: Expose port for inter-container communication
- value: ""
description: None
- variable: port_number
label: Port Number
schema:
type: int
show_if: [["bind_mode", "!=", ""]]
default: 8384
required: true
$ref:
- definitions/port
- variable: host_ips
label: Host IPs
description: IPs on the host to bind this port
schema:
type: list
default: []
items:
- variable: host_ip
label: Host IP
schema:
type: string
required: true
$ref:
- definitions/node_bind_ip

- variable: tcp_port
label: TCP Port (File Transfers)
description: The TCP port for Syncthing transfers.
schema:
type: int
default: 22000
type: dict
show_if: [["host_network", "=", false]]
required: true
$ref:
- "definitions/port"
attrs:
- variable: bind_mode
label: Port Bind Mode
description: |
The port bind mode.</br>
- Publish: The port will be published on the host for external access.</br>
- Expose: The port will be exposed for inter-container communication.</br>
- None: The port will not be exposed or published.</br>
Note: If the Dockerfile defines an EXPOSE directive,
the port will still be exposed for inter-container communication regardless of this setting.
schema:
type: string
default: "published"
enum:
- value: "published"
description: Publish port on the host for external access
- value: "exposed"
description: Expose port for inter-container communication
- value: ""
description: None
- variable: port_number
label: Port Number
schema:
type: int
show_if: [["bind_mode", "=", "published"]]
default: 22000
required: true
$ref:
- definitions/port
- variable: host_ips
label: Host IPs
description: IPs on the host to bind this port
schema:
type: list
default: []
items:
- variable: host_ip
label: Host IP
schema:
type: string
required: true
$ref:
- definitions/node_bind_ip

- variable: quic_port
label: QUIC (UDP) Port (File Transfers)
description: The QUIC (UDP) port for Syncthing transfers.
schema:
type: int
default: 22000
type: dict
show_if: [["host_network", "=", false]]
required: true
$ref:
- "definitions/port"
attrs:
- variable: bind_mode
label: Port Bind Mode
description: |
The port bind mode.</br>
- Publish: The port will be published on the host for external access.</br>
- Expose: The port will be exposed for inter-container communication.</br>
- None: The port will not be exposed or published.</br>
Note: If the Dockerfile defines an EXPOSE directive,
the port will still be exposed for inter-container communication regardless of this setting.
schema:
type: string
default: "published"
enum:
- value: "published"
description: Publish port on the host for external access
- value: "exposed"
description: Expose port for inter-container communication
- value: ""
description: None
- variable: port_number
label: Port Number
schema:
type: int
show_if: [["bind_mode", "=", "published"]]
default: 22000
required: true
$ref:
- definitions/port
- variable: host_ips
label: Host IPs
description: IPs on the host to bind this port
schema:
type: list
default: []
items:
- variable: host_ip
label: Host IP
schema:
type: string
required: true
$ref:
- definitions/node_bind_ip
- variable: host_network
label: Host Network
description: |
Expand Down
14 changes: 7 additions & 7 deletions ix-dev/enterprise/syncthing/templates/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
{% do c1.add_caps(caps) %}
{% do config.add_caps(caps + ["KILL"]) %}

{% do c1.healthcheck.set_test("wget", {"port": values.network.web_port, "path": "/rest/noauth/health"}) %}
{% do c1.healthcheck.set_test("wget", {"port": values.network.web_port.port_number, "path": "/rest/noauth/health"}) %}
{% do config.healthcheck.disable() %}

{% set envs = {
"PCAP": ["cap_sys_admin", "cap_chown", "cap_dac_override", "cap_fowner"]|join(",") + "+ep",
"STNOUPGRADE": true,
"STGUIADDRESS": "0.0.0.0:%d" | format(values.network.web_port),
"STGUIADDRESS": "0.0.0.0:%d" | format(values.network.web_port.port_number),
"STGUIASSETS": "/var/truenas/assets/gui",
} %}

Expand All @@ -70,12 +70,12 @@
{% do config.configs.add("public", cert.certificate, "%s/config/https-cert.pem" | format(values.consts.home_path)) %}
{% endif %}

{% do c1.ports.add_port(values.network.web_port, values.network.web_port) %}
{% do c1.add_port(values.network.web_port) %}
{% if not values.network.host_network %}
{% do c1.ports.add_port(values.network.tcp_port, 22000) %}
{% do c1.ports.add_port(values.network.quic_port, 22000, {"protocol": "udp"}) %}
{% do c1.add_port(values.network.tcp_port, {"container_port": 22000}) %}
{% do c1.add_port(values.network.quic_port, {"container_port": 22000, "protocol": "udp"}) %}
{% if values.consts.settings.local_discovery %}
{% do c1.ports.add_port(values.network.local_discover_port, 27017, {"protocol": "udp"}) %}
{% do c1.add_port(values.network.local_discover_port, {"container_port": 27017, "protocol": "udp"}) %}
{% endif %}
{% endif %}

Expand All @@ -95,6 +95,6 @@
{% endfor %}

{% set proto = "https" if values.network.certificate_id else "http" %}
{% do tpl.portals.add_portal({"port": values.network.web_port, "scheme": proto})%}
{% do tpl.portals.add_portal({"port": values.network.web_port.port_number, "scheme": proto})%}

{{ tpl.render() | tojson }}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ echo "Syncthing started with PID [$SYNCTHING_PID]"
echo "Waiting for Syncthing to be ready..."

try_for 15 2 "[ -f '{{ config_dir }}/config.xml' ]" || { echo "Syncthing did not become ready in time. Exiting..."; exit 1; }
try_for 15 2 "curl --silent --output /dev/null http://127.0.0.1:{{ values.network.web_port }}/rest/noauth/health" || { echo "Syncthing did not become ready in time. Exiting..."; exit 1; }
try_for 15 2 "curl --silent --output /dev/null http://127.0.0.1:{{ values.network.web_port.port_number }}/rest/noauth/health" || { echo "Syncthing did not become ready in time. Exiting..."; exit 1; }
echo "Syncthing is ready."

{%- for cfg in settings %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ syncthing:
additional_envs: []

network:
web_port: 9000
tcp_port: 22000
quic_port: 22000
local_discover_port: 27017
web_port:
bind_mode: published
port_number: 8080
tcp_port:
bind_mode: published
port_number: 22000
quic_port:
bind_mode: published
port_number: 22000
local_discover_port:
bind_mode: published
port_number: 27017
certificate_id: null
host_network: false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ syncthing:
additional_envs: []

network:
web_port: 9000
tcp_port: 22000
quic_port: 22000
local_discover_port: 27017
web_port:
bind_mode: published
port_number: 8080
tcp_port:
bind_mode: published
port_number: 22000
quic_port:
bind_mode: published
port_number: 22000
local_discover_port:
bind_mode: published
port_number: 27017
certificate_id: "1"
host_network: false

Expand Down

0 comments on commit 456e338

Please sign in to comment.