271 lines
8.4 KiB
YAML
271 lines
8.4 KiB
YAML
# Apply: kubectl apply -f manifests/media/jdownloader.yaml
|
|
# Delete: kubectl delete -f manifests/media/jdownloader.yaml
|
|
# Description: JDownloader deployment with Ingress at jdownloader.home.arpa.
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
name: jdownloader
|
|
namespace: downloads
|
|
spec:
|
|
replicas: 1
|
|
strategy:
|
|
type: Recreate
|
|
selector:
|
|
matchLabels:
|
|
app: jdownloader
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: jdownloader
|
|
spec:
|
|
nodeSelector:
|
|
node-role: storage
|
|
containers:
|
|
- name: gluetun
|
|
image: qmcgaw/gluetun:v3.41
|
|
securityContext:
|
|
capabilities:
|
|
add:
|
|
- NET_ADMIN
|
|
env:
|
|
- name: VPN_SERVICE_PROVIDER
|
|
value: private internet access
|
|
- name: VPN_TYPE
|
|
value: openvpn
|
|
- name: SERVER_REGIONS
|
|
value: JP Tokyo,Taiwan,Hong Kong
|
|
# value: US Seattle,US Oregon,US Silicon Valley
|
|
- name: OPENVPN_USER
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: pia-credentials
|
|
key: OPENVPN_USER
|
|
- name: OPENVPN_PASSWORD
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: pia-credentials
|
|
key: OPENVPN_PASSWORD
|
|
- name: FIREWALL_OUTBOUND_SUBNETS
|
|
value: "10.42.0.0/16,10.43.0.0/16,192.168.7.0/24"
|
|
- name: BLOCK_IPV6
|
|
value: "on"
|
|
startupProbe:
|
|
exec:
|
|
command:
|
|
- /gluetun-entrypoint
|
|
- healthcheck
|
|
periodSeconds: 10
|
|
failureThreshold: 60
|
|
livenessProbe:
|
|
exec:
|
|
command:
|
|
- /gluetun-entrypoint
|
|
- healthcheck
|
|
periodSeconds: 30
|
|
failureThreshold: 3
|
|
readinessProbe:
|
|
exec:
|
|
command:
|
|
- /gluetun-entrypoint
|
|
- healthcheck
|
|
periodSeconds: 10
|
|
failureThreshold: 3
|
|
volumeMounts:
|
|
- name: tun
|
|
mountPath: /dev/net/tun
|
|
- name: jdownloader
|
|
image: jlesage/jdownloader-2:latest
|
|
ports:
|
|
- containerPort: 5800
|
|
env:
|
|
- name: USER_ID
|
|
value: "1000"
|
|
- name: GROUP_ID
|
|
value: "1000"
|
|
- name: TZ
|
|
value: "Asia/Tokyo"
|
|
readinessProbe:
|
|
httpGet:
|
|
path: /
|
|
port: 5800
|
|
initialDelaySeconds: 15
|
|
periodSeconds: 15
|
|
livenessProbe:
|
|
httpGet:
|
|
path: /
|
|
port: 5800
|
|
initialDelaySeconds: 30
|
|
periodSeconds: 30
|
|
resources:
|
|
requests:
|
|
cpu: 200m
|
|
memory: 512Mi
|
|
limits:
|
|
cpu: 1000m
|
|
memory: 1Gi
|
|
volumeMounts:
|
|
- name: config
|
|
mountPath: /config
|
|
- name: dl
|
|
mountPath: /output
|
|
- name: cnl-bridge
|
|
image: python:3.12-alpine
|
|
ports:
|
|
- containerPort: 9667
|
|
resources:
|
|
requests:
|
|
cpu: 5m
|
|
memory: 16Mi
|
|
limits:
|
|
cpu: 50m
|
|
memory: 64Mi
|
|
volumeMounts:
|
|
- name: config
|
|
mountPath: /config
|
|
- name: dl
|
|
mountPath: /output
|
|
command:
|
|
- python3
|
|
- -c
|
|
- |
|
|
import http.server, urllib.parse, urllib.request, os, time
|
|
|
|
WATCH_DIR = '/config/folderwatch'
|
|
TORRENT_DIR = '/output'
|
|
os.makedirs(WATCH_DIR, exist_ok=True)
|
|
|
|
class Handler(http.server.BaseHTTPRequestHandler):
|
|
def do_POST(self):
|
|
if self.path != '/add':
|
|
self.send_response(404); self.end_headers(); return
|
|
length = int(self.headers.get('Content-Length', 0))
|
|
body = self.rfile.read(length).decode()
|
|
params = urllib.parse.parse_qs(body)
|
|
urls = params.get('urls', [])
|
|
if not urls:
|
|
self.send_response(400); self.end_headers(); return
|
|
url = urls[0]
|
|
basename = urllib.parse.unquote(urllib.parse.urlparse(url).path.rsplit('/', 1)[-1])
|
|
|
|
# .torrent files aren't handled by JDownloader's crawler (no BT
|
|
# plugin), so fetch the raw file ourselves instead of writing a
|
|
# crawljob. This container shares gluetun's netns, so the fetch
|
|
# is still VPN-routed same as JDownloader's own downloads.
|
|
if basename.lower().endswith('.torrent'):
|
|
safe_name = basename.replace('/', '_').replace('\\', '_')
|
|
try:
|
|
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
|
|
with urllib.request.urlopen(req, timeout=30) as resp:
|
|
data = resp.read()
|
|
with open(f'{TORRENT_DIR}/{safe_name}', 'wb') as f:
|
|
f.write(data)
|
|
except Exception as e:
|
|
self.send_response(502); self.end_headers()
|
|
self.wfile.write(str(e).encode())
|
|
return
|
|
self.send_response(200); self.end_headers()
|
|
self.wfile.write(b'Ok.')
|
|
return
|
|
|
|
package_name = basename.split('.', 1)[0] or 'subyshare'
|
|
fname = f'{WATCH_DIR}/{int(time.time()*1000)}.crawljob'
|
|
lines = [f'text={url}', 'autoStart=TRUE', 'autoConfirm=TRUE', f'packageName={package_name}']
|
|
password = params.get('password', [''])[0]
|
|
if password:
|
|
# crawljob format requires literal backslashes doubled
|
|
escaped_pw = password.replace('\\', '\\\\')
|
|
lines.append(f'downloadPassword={escaped_pw}')
|
|
with open(fname, 'w') as f:
|
|
f.write('\n'.join(lines) + '\n')
|
|
self.send_response(200); self.end_headers()
|
|
self.wfile.write(b'Ok.')
|
|
def log_message(self, *a): pass
|
|
|
|
http.server.HTTPServer(('0.0.0.0', 9667), Handler).serve_forever()
|
|
volumes:
|
|
- name: tun
|
|
hostPath:
|
|
path: /dev/net/tun
|
|
type: CharDevice
|
|
- name: config
|
|
hostPath:
|
|
path: /data/jdownloader
|
|
type: DirectoryOrCreate
|
|
- name: dl
|
|
hostPath:
|
|
path: /mnt/storage/dl
|
|
type: Directory
|
|
---
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: jdownloader
|
|
namespace: downloads
|
|
spec:
|
|
selector:
|
|
app: jdownloader
|
|
ports:
|
|
- name: web
|
|
port: 80
|
|
targetPort: 5800
|
|
- name: cnl-bridge
|
|
port: 9666
|
|
targetPort: 9667
|
|
---
|
|
apiVersion: networking.k8s.io/v1
|
|
kind: Ingress
|
|
metadata:
|
|
name: jdownloader
|
|
namespace: downloads
|
|
annotations:
|
|
traefik.ingress.kubernetes.io/router.entrypoints: websecure
|
|
traefik.ingress.kubernetes.io/router.tls: "true"
|
|
cert-manager.io/cluster-issuer: internal-ca-issuer
|
|
spec:
|
|
ingressClassName: traefik
|
|
tls:
|
|
- secretName: jdownloader-tls
|
|
hosts:
|
|
- jdownloader.home.arpa
|
|
rules:
|
|
- host: jdownloader.home.arpa
|
|
http:
|
|
paths:
|
|
- path: /
|
|
pathType: Prefix
|
|
backend:
|
|
service:
|
|
name: jdownloader
|
|
port:
|
|
number: 80
|
|
---
|
|
apiVersion: cert-manager.io/v1
|
|
kind: Certificate
|
|
metadata:
|
|
name: jdownloader-cnl-tls
|
|
namespace: downloads
|
|
spec:
|
|
secretName: jdownloader-cnl-tls
|
|
issuerRef:
|
|
name: internal-ca-issuer
|
|
kind: ClusterIssuer
|
|
dnsNames:
|
|
- jdownloader.home.arpa
|
|
---
|
|
apiVersion: traefik.io/v1alpha1
|
|
kind: IngressRoute
|
|
metadata:
|
|
name: jdownloader-cnl
|
|
namespace: downloads
|
|
spec:
|
|
entryPoints:
|
|
- websecure
|
|
routes:
|
|
- match: Host(`jdownloader.home.arpa`) && PathPrefix(`/add`)
|
|
kind: Rule
|
|
services:
|
|
- name: jdownloader
|
|
port: 9666
|
|
tls:
|
|
secretName: jdownloader-cnl-tls
|