Enhance docker logging for debugging (Python unbuffered, GORM logger, yt-dlp debug wrapper)
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled

This commit is contained in:
AI Assistant
2026-03-12 14:14:51 +09:00
parent d030e737cb
commit 49ceb0159d
4 changed files with 29 additions and 2 deletions

View File

@@ -11,6 +11,9 @@ RUN cd backend && CGO_ENABLED=1 go build -o /app/main main.go
# 2. Final Minimal Image (Python + Go binary + Frontend)
FROM python:3.10-slim
# 파이썬 출력 버퍼링을 비활성화하여 도커 로그에 즉각 표시되도록 설정합니다.
ENV PYTHONUNBUFFERED=1
# Install system dependencies (ffmpeg is required for yt-dlp)
RUN apt-get update && apt-get install -y \
ffmpeg \

View File

@@ -106,10 +106,13 @@ func DownloadMedia(c *fiber.Ctx) error {
}
cmd := exec.Command("python", args...)
fmt.Printf("[DEBUG Go Exec] Command: %v\n", cmd.String())
output, err := cmd.CombinedOutput()
fmt.Printf("[DEBUG Go Exec] Output:\n%s\n", string(output))
if err != nil {
fmt.Println("Download error:", string(output))
fmt.Printf("[DEBUG Go Exec] Download error: %v\n", string(output))
BroadcastProgress("Error: " + err.Error())
models.DB.Create(&models.MediaHistory{
SourceURL: req.URL,

View File

@@ -2,9 +2,11 @@ package models
import (
"log"
"os"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
var DB *gorm.DB
@@ -19,8 +21,20 @@ type MediaHistory struct {
func InitDB(dbPath string) {
var err error
// 도커 로그 디버깅을 위해 SQL 쿼리를 디테일하게 출력하는 로거 설정
newLogger := logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags),
logger.Config{
LogLevel: logger.Info,
Colorful: true,
},
)
log.Println("Connecting to SQLite at:", dbPath)
DB, err = gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
DB, err = gorm.Open(sqlite.Open(dbPath), &gorm.Config{
Logger: newLogger,
})
if err != nil {
log.Fatal("Failed to connect to database:", err)
}

View File

@@ -3,13 +3,16 @@ import json
import subprocess
import os
import argparse
import traceback
def download_and_crop(url, output_dir, start_time=None, end_time=None):
print(f"[DEBUG Worker] Starting download job for URL={url}, start={start_time}, end={end_time}", file=sys.stderr)
try:
os.makedirs(output_dir, exist_ok=True)
# Get video info
info_cmd = ["yt-dlp", "-J", url]
print(f"[DEBUG Worker] Running info command: {' '.join(info_cmd)}", file=sys.stderr)
result = subprocess.run(info_cmd, capture_output=True, text=True, check=True)
info = json.loads(result.stdout)
@@ -53,14 +56,18 @@ def download_and_crop(url, output_dir, start_time=None, end_time=None):
]
# Execute
print(f"[DEBUG Worker] Executing download command: {' '.join(download_args)}", file=sys.stderr)
subprocess.run(download_args, check=True)
print(json.dumps({"status": "success", "filepath": filepath, "title": title}))
return True
except subprocess.CalledProcessError as e:
print(f"[DEBUG Worker] Command Error Output: {e.stderr or e.output}", file=sys.stderr)
print(json.dumps({"status": "error", "message": f"Command failed: {e.stderr or e.output}"}))
return False
except Exception as e:
print(f"[DEBUG Worker] Unexpected Exception:", file=sys.stderr)
traceback.print_exc()
print(json.dumps({"status": "error", "message": str(e)}))
return False