mirror of
https://github.com/halfwaystudent/douyin-sparkflow.git
synced 2026-06-29 19:31:25 +08:00
Speed up one-click Docker deployment
This commit is contained in:
@@ -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 . .
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -20,6 +20,9 @@ run_root() {
|
||||
}
|
||||
|
||||
install_base_tools() {
|
||||
if command -v curl >/dev/null 2>&1 && command -v git >/dev/null 2>&1 && command -v gpg >/dev/null 2>&1; then
|
||||
return
|
||||
fi
|
||||
if command -v apt-get >/dev/null 2>&1; then
|
||||
run_root apt-get update
|
||||
run_root apt-get install -y ca-certificates curl git gnupg
|
||||
@@ -61,9 +64,10 @@ ensure_docker() {
|
||||
prepare_repo() {
|
||||
run_root mkdir -p "$(dirname "$APP_ROOT")"
|
||||
if [ -d "$APP_ROOT/.git" ]; then
|
||||
run_root git -C "$APP_ROOT" reset --hard
|
||||
run_root git -C "$APP_ROOT" fetch origin "$BRANCH"
|
||||
run_root git -C "$APP_ROOT" checkout "$BRANCH"
|
||||
run_root git -C "$APP_ROOT" pull --ff-only origin "$BRANCH"
|
||||
run_root git -C "$APP_ROOT" checkout -B "$BRANCH" "origin/$BRANCH"
|
||||
run_root git -C "$APP_ROOT" reset --hard "origin/$BRANCH"
|
||||
else
|
||||
run_root git clone --branch "$BRANCH" "$REPO_URL" "$APP_ROOT"
|
||||
fi
|
||||
@@ -124,7 +128,7 @@ main() {
|
||||
prepare_runtime_files
|
||||
cd "$APP_ROOT"
|
||||
run_root bash "$APP_ROOT/refresh_proxy.sh"
|
||||
run_root docker compose up -d --build
|
||||
run_root env DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose up -d --build
|
||||
|
||||
local web_port login_port host_ip
|
||||
web_port="$(grep '^WEB_PORT=' "$APP_ROOT/.env" | sed 's/^WEB_PORT=//')"
|
||||
|
||||
@@ -50,7 +50,6 @@ services:
|
||||
- ./DouYinSparkFlow:/app
|
||||
- ./DouYinSparkFlow/logs:/app/logs
|
||||
- ./state/cron:/host-spool-cron
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- .:/opt/douyin-sparkflow
|
||||
|
||||
login-desktop:
|
||||
@@ -85,12 +84,15 @@ services:
|
||||
environment:
|
||||
TZ: ${TZ:-Asia/Shanghai}
|
||||
PYTHONUNBUFFERED: "1"
|
||||
HTTP_PROXY: http://proxy:7890
|
||||
HTTPS_PROXY: http://proxy:7890
|
||||
ALL_PROXY: socks5://proxy:7890
|
||||
NO_PROXY: localhost,127.0.0.1,douyin.com,amemv.com,snssdk.com,bytedance.com,pstatp.com,volccdn.com,bytescm.com,byted.net,douyinstatic.com,bytecdn.cn,byteimg.com,bytegoofy.com,toutiaostatic.com
|
||||
command: python /app/scripts/cron_runner.py /host-spool-cron/root
|
||||
volumes:
|
||||
- ./DouYinSparkFlow:/app
|
||||
- ./DouYinSparkFlow/logs:/app/logs
|
||||
- ./state/cron:/host-spool-cron
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
|
||||
task:
|
||||
image: douyin-sparkflow:local
|
||||
@@ -99,6 +101,7 @@ services:
|
||||
- proxy
|
||||
environment:
|
||||
TZ: ${TZ:-Asia/Shanghai}
|
||||
PYTHONUNBUFFERED: "1"
|
||||
HTTP_PROXY: http://proxy:7890
|
||||
HTTPS_PROXY: http://proxy:7890
|
||||
ALL_PROXY: socks5://proxy:7890
|
||||
|
||||
Reference in New Issue
Block a user