Skip to content

Commit b845da5

Browse files
author
Vladimir Chupin
committed
first commit
0 parents  commit b845da5

30 files changed

Lines changed: 8682 additions & 0 deletions

.containerignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Files excluded from the podman build context (analogous to .dockerignore).
2+
# Keeps the image small and rebuilds fast.
3+
4+
# VCS / editor noise
5+
.git
6+
.gitignore
7+
.gitattributes
8+
.idea
9+
.vscode
10+
.DS_Store
11+
12+
# Python caches and virtualenvs
13+
__pycache__
14+
*.pyc
15+
*.pyo
16+
*.pyd
17+
*.egg-info
18+
.venv
19+
venv
20+
.tox
21+
.pytest_cache
22+
.mypy_cache
23+
.ruff_cache
24+
25+
# Test scratch
26+
tests/__pycache__
27+
backend/tests/__pycache__
28+
**/.coverage*
29+
htmlcov
30+
31+
# Build artifacts
32+
build
33+
dist
34+
out
35+
36+
# Local dev / docs that don't need to ship
37+
README.md
38+
scripts/build.md
39+
docs
40+
41+
# Container build itself
42+
Containerfile
43+
.containerignore

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Override the user's global gitignore which excludes any "backend/" directory.
2+
!backend/
3+
!backend/**
4+
5+
# Local Python noise we still want to keep out.
6+
backend/**/__pycache__/
7+
backend/**/*.pyc
8+
.pytest_cache/
9+
.venv/
10+
.coverage
11+
htmlcov/

Caddyfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Caddyfile (no-auth variant).
2+
#
3+
# Listens on :{$WEBUI_PORT:80}, serves the static SPA from /srv/frontend
4+
# and reverse-proxies /api/* to the FastAPI backend.
5+
6+
{
7+
admin off
8+
auto_https off
9+
persist_config off
10+
}
11+
12+
:{$WEBUI_PORT:80} {
13+
@api path /api/*
14+
handle @api {
15+
# No `encode gzip` here — gzip buffers output and breaks the SSE
16+
# streams emitted by /api/groups/{add,remove}. flush_interval -1
17+
# would otherwise be defeated by the encoder.
18+
reverse_proxy {$BACKEND_HOST:127.0.0.1}:{$BACKEND_PORT:8000} {
19+
flush_interval -1
20+
}
21+
}
22+
23+
handle {
24+
encode gzip
25+
root * /srv/frontend
26+
try_files {path} /index.html
27+
file_server
28+
}
29+
}

Caddyfile.auth

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Caddyfile (basic-auth variant).
2+
#
3+
# Selected by start-caddy.sh when both WEBUI_USER and WEBUI_PASSWORD_HASH are
4+
# set. Generate the hash with:
5+
# podman run --rm caddy:2-alpine caddy hash-password --plaintext '<pwd>'
6+
7+
{
8+
admin off
9+
auto_https off
10+
persist_config off
11+
}
12+
13+
:{$WEBUI_PORT:80} {
14+
basic_auth {
15+
{$WEBUI_USER} {$WEBUI_PASSWORD_HASH}
16+
}
17+
18+
@api path /api/*
19+
handle @api {
20+
# No `encode gzip` here — gzip buffers output and breaks the SSE
21+
# streams emitted by /api/groups/{add,remove}. flush_interval -1
22+
# would otherwise be defeated by the encoder.
23+
reverse_proxy {$BACKEND_HOST:127.0.0.1}:{$BACKEND_PORT:8000} {
24+
flush_interval -1
25+
}
26+
}
27+
28+
handle {
29+
encode gzip
30+
root * /srv/frontend
31+
try_files {path} /index.html
32+
file_server
33+
}
34+
}

Containerfile

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# syntax=docker/dockerfile:1.7
2+
3+
# Stage 1 — builder: same base as runtime so the venv's interpreter symlink
4+
# (/usr/bin/python3) is valid in the runtime stage. We install build deps to
5+
# compile any wheels that lack a musllinux build, then drop them.
6+
#
7+
# Caddy >= 2.8 is required: Caddyfile.auth uses the renamed `basic_auth`
8+
# directive (was `basicauth` in 2.7 and earlier). The `caddy:2-alpine` tag
9+
# tracks the latest 2.x and is well past 2.8 at the time of writing.
10+
FROM --platform=$TARGETPLATFORM caddy:2-alpine AS builder
11+
12+
RUN apk add --no-cache \
13+
python3 \
14+
py3-pip \
15+
&& apk add --no-cache --virtual .build-deps \
16+
gcc \
17+
musl-dev \
18+
libffi-dev \
19+
openssl-dev \
20+
python3-dev \
21+
make
22+
23+
COPY backend/requirements.txt /tmp/requirements.txt
24+
25+
RUN python3 -m venv /opt/venv \
26+
&& /opt/venv/bin/pip install --no-cache-dir --upgrade pip \
27+
&& /opt/venv/bin/pip install --no-cache-dir -r /tmp/requirements.txt
28+
29+
# Stage 2 — runtime. Same base, only python3/py3-pip installed (no compilers).
30+
FROM --platform=$TARGETPLATFORM caddy:2-alpine
31+
32+
RUN apk add --no-cache \
33+
python3 \
34+
supervisor \
35+
ca-certificates \
36+
tini
37+
38+
COPY --from=builder /opt/venv /opt/venv
39+
40+
ENV PATH="/opt/venv/bin:${PATH}" \
41+
PYTHONUNBUFFERED=1 \
42+
PYTHONDONTWRITEBYTECODE=1 \
43+
PYTHONPATH=/app
44+
45+
WORKDIR /app
46+
47+
COPY backend/ /app/backend/
48+
COPY frontend/ /srv/frontend/
49+
COPY Caddyfile /etc/caddy/Caddyfile
50+
COPY Caddyfile.auth /etc/caddy/Caddyfile.auth
51+
COPY supervisord.conf /etc/supervisor/conf.d/mihomo-webui.conf
52+
COPY start-caddy.sh /usr/local/bin/start-caddy.sh
53+
RUN chmod +x /usr/local/bin/start-caddy.sh
54+
55+
ENV WEBUI_PORT=80 \
56+
BACKEND_HOST=127.0.0.1 \
57+
BACKEND_PORT=8000 \
58+
MIKROTIK_HOST="" \
59+
MIKROTIK_USER="" \
60+
MIKROTIK_PASSWORD="" \
61+
MIKROTIK_VERIFY_TLS=false \
62+
MIKROTIK_CONTAINER_COMMENT=MihomoProxyRoS \
63+
MIKROTIK_ENVS_LIST=MihomoProxyRoS \
64+
WEBUI_USER="" \
65+
WEBUI_PASSWORD_HASH=""
66+
67+
EXPOSE 80
68+
69+
ENTRYPOINT ["/sbin/tini", "--"]
70+
CMD ["supervisord", "-c", "/etc/supervisor/conf.d/mihomo-webui.conf", "-n"]

0 commit comments

Comments
 (0)