Speed up one-click Docker deployment

This commit is contained in:
Rixuan Shao
2026-05-30 01:56:12 +08:00
parent 706bd6a19f
commit a3b063d2ae
5 changed files with 30 additions and 32 deletions
+1 -9
View File
@@ -31,9 +31,7 @@ RUN set -eux; \
&& sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list \
&& ln -fs /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo ${TZ} > /etc/timezone \
&& apt-get update && apt-get install -y \
cron \
curl \
&& apt-get update && apt-get install -y --no-install-recommends \
fluxbox \
fonts-wqy-zenhei \
fonts-noto-cjk \
@@ -41,12 +39,6 @@ RUN set -eux; \
websockify \
x11vnc \
xfonts-intl-chinese \
&& download() { url="$1"; output="$2"; proxy_url="${HTTPS_PROXY:-${https_proxy:-${HTTP_PROXY:-${http_proxy:-}}}}"; if [ -n "$proxy_url" ]; then curl -fsSL -x "$proxy_url" "$url" -o "$output"; else curl -fsSL "$url" -o "$output"; fi; } \
&& download https://download.docker.com/linux/static/stable/x86_64/docker-25.0.3.tgz docker.tgz \
&& tar xzvf docker.tgz \
&& mv docker/docker /usr/bin/docker \
&& chmod +x /usr/bin/docker \
&& rm -rf docker docker.tgz \
&& rm -rf /var/lib/apt/lists/*
COPY . .
+1 -1
View File
@@ -56,7 +56,7 @@ DEFAULT_APP_SETTINGS = {
"ui_host": "0.0.0.0",
"ui_port": 8787,
"login_poll_interval_seconds": 1,
"ops_log_file": "/var/log/douyin-sparkflow.log",
"ops_log_file": "/app/logs/douyin-sparkflow.log",
"proxy_refresh_script": "/opt/douyin-sparkflow/refresh_proxy.sh",
"local_login_helper_url": "http://127.0.0.1:18765",
"login_desktop_api_url": "http://127.0.0.1:18090",
+16 -17
View File
@@ -88,22 +88,20 @@ def _compose_env_args(extra_env=None):
return " ".join(shlex.quote(part) for part in parts)
def _ops_log_file():
return str(get_app_settings().get("ops_log_file") or "/app/logs/douyin-sparkflow.log")
def build_scheduled_task_command(extra_env=None, trigger_label="scheduled send"):
if running_in_container():
task_command = _with_env_prefix("python main.py --doTask", extra_env)
return (
"/bin/bash -lc 'timestamp=$(date -Iseconds); "
repo_root_quoted = shlex.quote(str(repo_root()))
script = (
"timestamp=$(date -Iseconds); "
f"echo \"[AUTO_TRIGGER] $timestamp {trigger_label} start\"; "
"container=$(docker ps --format \"{{.Names}}\" | "
"grep -E \"^(douyin-web-hostfix|douyin-web)$\" | head -n 1); "
"if [ -z \"$container\" ]; then "
"echo \"[AUTO_TRIGGER] $timestamp no matching container found\"; "
"exit 1; "
"fi; "
"echo \"[AUTO_TRIGGER] $timestamp container=$container\"; "
"docker exec \"$container\" sh -lc "
f"\"cd /app && {task_command}\"'"
f"cd {repo_root_quoted} && {task_command}"
)
return f"/bin/bash -lc {shlex.quote(script)}"
if compose_file_path():
compose_root_quoted = shlex.quote(str(compose_root()))
compose_env_args = _compose_env_args(extra_env)
@@ -240,7 +238,7 @@ def get_task_container_rows():
def run_task_now(*, unsent_only=False):
try:
log_file = Path(get_app_settings().get("ops_log_file") or "/var/log/douyin-sparkflow.log")
log_file = Path(_ops_log_file())
command, cwd = build_task_run_spec()
run_env = {
"SPARKFLOW_MANUAL_RUN": "1",
@@ -285,7 +283,7 @@ def restart_proxy():
def read_log_tail(lines=200):
log_path = Path(get_app_settings().get("ops_log_file") or "/var/log/douyin-sparkflow.log")
log_path = Path(_ops_log_file())
if not log_path.exists():
return ""
content = log_path.read_text(encoding="utf-8", errors="replace").splitlines()
@@ -350,6 +348,7 @@ def replace_douyin_cron_schedule(crontab_text, time_string):
schedule = parse_schedule_string(time_string)
scheduled_command = build_scheduled_task_command()
fallback_command = build_unsent_fallback_task_command()
log_redirect = f" >> {shlex.quote(_ops_log_file())} 2>&1"
updated = []
for raw_line in crontab_text.splitlines():
@@ -361,20 +360,20 @@ def replace_douyin_cron_schedule(crontab_text, time_string):
if schedule["mode"] == "window":
updated.append(
f"*/{schedule['scheduleIntervalMinutes']} {schedule['startHour']}-{schedule['endHour'] - 1} * * * "
f"{scheduled_command} >> /var/log/douyin-sparkflow.log 2>&1"
f"{scheduled_command}{log_redirect}"
)
updated.append(
f"0 {schedule['endHour']} * * * "
f"{scheduled_command} >> /var/log/douyin-sparkflow.log 2>&1"
f"{scheduled_command}{log_redirect}"
)
updated.append(
f"{schedule['scheduleIntervalMinutes']} {schedule['endHour']} * * * "
f"{fallback_command} >> /var/log/douyin-sparkflow.log 2>&1"
f"{fallback_command}{log_redirect}"
)
else:
updated.append(
f"{schedule['minute']} {schedule['hour']} * * * "
f"{scheduled_command} >> /var/log/douyin-sparkflow.log 2>&1"
f"{scheduled_command}{log_redirect}"
)
normalized = "\n".join(line for line in updated if line.strip())