Repository navigation
Expand file tree
/
Copy pathDockerfile.worker
More file actions
138 lines (121 loc) · 6.73 KB
/
Copy pathDockerfile.worker
File metadata and controls
138 lines (121 loc) · 6.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Every base is pinned by tag and digest, so two builds of one release use the
# same bytes. Dependabot's docker ecosystem bumps both parts together; uv is a
# FROM stage, not a bare COPY --from, so Dependabot can see it.
FROM ghcr.io/astral-sh/uv:0.13.9@sha256:d3b601f0c7b118bc1753febf7c41cc80981df678445e0254284eecf84db79a7d AS uv
# -- Build stage --
FROM python:3.15-alpine@sha256:0f9552bb28711333da16915ec146f5e6bb44a7fdac9ced15dc17c2e0206346dd AS builder
WORKDIR /build
RUN apk add --no-cache gcc musl-dev libffi-dev
COPY --from=uv /uv /bin/uv
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev --no-install-project \
&& find .venv -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null; \
find .venv -type f -name "*.pyc" -delete 2>/dev/null; \
find .venv -type f -name "*.pyo" -delete 2>/dev/null; \
find .venv -type d -name "tests" -exec rm -rf {} + 2>/dev/null; \
find .venv -type d -name "test" -exec rm -rf {} + 2>/dev/null; true
# -- Runtime stage --
FROM python:3.15-alpine@sha256:0f9552bb28711333da16915ec146f5e6bb44a7fdac9ced15dc17c2e0206346dd
# The release tag this image was built from, so the app can report what it is.
# Both apps used to hardcode "0.1.0" while releases were tag-driven and past
# 1.11, which made UI/worker skew undetectable (CashPilot-l6c). Defaults to dev
# so a local `docker build` says so rather than claiming a release.
ARG CASHPILOT_VERSION=dev
ENV CASHPILOT_VERSION=$CASHPILOT_VERSION
LABEL maintainer="Sergio Fernandez <9169332+GeiserX@users.noreply.github.com>"
LABEL org.opencontainers.image.description="CashPilot Worker - Lightweight Docker container orchestration agent"
LABEL org.opencontainers.image.url="https://github.com/GeiserX/CashPilot"
LABEL org.opencontainers.image.source="https://github.com/GeiserX/CashPilot"
LABEL org.opencontainers.image.licenses="GPL-3.0"
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PATH="/app/.venv/bin:$PATH"
# Both packages: upgrading only ca-certificates-bundle leaves the old hashed
# links in /etc/ssl/certs, which still trust the compromised eMudhra roots.
# nftables, and iptables-legacy with the iptables extensions it loads: the
# one-shot helper the worker starts from its own image writes the LAN fence
# into the host's network namespace with them (app/lan_fence.py). The worker
# process itself never runs them.
RUN apk add --no-cache su-exec nftables iptables iptables-legacy \
&& apk upgrade --no-cache ca-certificates ca-certificates-bundle
RUN adduser -D -u 1000 cashpilot \
&& mkdir -p /data && chown cashpilot:root /data
WORKDIR /app
COPY --from=builder /build/.venv ./.venv
COPY app/__init__.py ./app/
COPY app/constants.py ./app/
COPY app/fleet_key.py ./app/
# The plain-http rule for the key on the heartbeat (CASHPILOT_UI_URL).
COPY app/cleartext.py ./app/
# Keeps secrets in request URLs (httpx logs every one) out of the log.
COPY app/log_redaction.py ./app/
# Egress identity: pure helpers, deliberately free of app-level imports so
# the worker image stays minimal.
COPY app/egress.py ./app/
# Encrypted state export: encryption happens on the WORKER so the UI only
# ever handles ciphertext.
COPY app/state_backup.py ./app/
# Checks the UI's signed password confirmation before an image other than the
# catalog's runs on a service's wallet or identity volume.
COPY app/step_up.py ./app/
# Which earners may run from the box's own IP (CASHPILOT_PROXIED_ONLY, routed services).
COPY app/route_gate.py ./app/
# worker_api imports this to report which release it is; without it the worker
# crashes on import. The two tests that caught the omission compare this list
# against worker_api's actual imports.
COPY app/version.py ./app/
COPY app/worker_api.py ./app/
COPY app/miner_read.py ./app/
COPY app/orchestrator.py ./app/
COPY app/isolation_check.py ./app/
# The security layers this worker can give an earner (system_info.layers, runtime_choice).
COPY app/layers.py ./app/
COPY app/socket_policy.py ./app/
# The one-shot cashpilot-migrate service of the compose files runs it.
COPY app/owner_migrate.py ./app/
# Fences the earners off the LAN by default; the helper imports it too.
COPY app/lan_fence.py ./app/
# Proxied copies: the tunnel sidecar and the earner inside it (docs/proxies.md).
COPY app/proxy_tunnel.py ./app/
# Activity: per-container socket tables and counters, read by a short-lived
# probe in each earner's network namespace (docs/activity.md).
COPY app/activity.py ./app/
COPY app/procnet.py ./app/
# Reads a payout address set inside a container (Mysterium, Anyone).
COPY app/payout_read.py ./app/
# Keeps a catalog seed_file wallet in the node's own volume (Sia), with the
# BIP-39 word list it checks a pasted phrase against.
COPY app/wallet_seed.py app/bip39_english.txt ./app/
# Reads a node's own earnings figures from inside it (Mysterium, issue #488).
COPY app/node_read.py ./app/
# Asks a running node how it is doing from inside it (docker.health_probe);
# catalog.py also validates the declaration with it.
COPY app/health_probe.py ./app/
COPY app/arch.py ./app/
COPY app/catalog.py ./app/
# catalog.py validates each entry's rating block with it (the rules ship in services/).
COPY app/ratings.py ./app/
# catalog.py validates each entry's docker.traffic_stall block with it.
COPY app/traffic_stall.py ./app/
# The GPU grant (docker.gpu): sysfs read, device requests, the NVIDIA void stamp.
COPY app/gpu.py ./app/
COPY services/ ./services/
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
VOLUME /data
EXPOSE 8081
ENTRYPOINT ["/entrypoint.sh"]
# Ask the app whether it can still REPORT IN, not merely whether this port is
# open. A TCP connect succeeds on a worker that has been unable to reach the UI
# for days, so `docker ps` read "healthy" right through a 42-hour outage while
# the fleet page showed the worker offline. /api/health returns 503 only after a
# sustained run of missed heartbeats, so a UI restart does not flap the state,
# or after Docker has failed every call for 10 minutes, so a Docker restart or
# update does not flap it either (worker_api._DOCKER_UNHEALTHY_AFTER).
# http.client, NOT urllib.request: urlopen honors http_proxy/HTTPS_PROXY (which
# Docker injects fleet-wide when the host has a proxies config) and has no
# localhost exemption, so the "loopback" probe would be answered by the proxy —
# unhealthy forever, or worse, healthy on the strength of a different host.
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
CMD ["python", "-c", "import sys,http.client\ntry:\n c = http.client.HTTPConnection('127.0.0.1', 8081, timeout=3)\n c.request('GET', '/api/health')\n sys.exit(0 if c.getresponse().status == 200 else 1)\nexcept Exception:\n sys.exit(1)"]
CMD ["python", "-m", "uvicorn", "app.worker_api:app", "--host", "0.0.0.0", "--port", "8081", "--no-access-log"]