diff --git a/Dockerfile b/Dockerfile index f94f831..87247d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,14 +6,16 @@ ARG VERSION COPY ["OF DL.sln", "/src/OF DL.sln"] COPY ["OF DL", "/src/OF DL"] COPY ["OF DL.Core", "/src/OF DL.Core"] +COPY ["OF DL.Gui", "/src/OF DL.Gui"] WORKDIR "/src" # Build release -RUN dotnet publish "OF DL/OF DL.csproj" -p:WarningLevel=0 -p:Version=$VERSION -c Release -o out +RUN dotnet publish "OF DL.Gui/OF DL.Gui.csproj" -p:WarningLevel=0 -p:Version=$VERSION -c Release -o outgui +RUN dotnet publish "OF DL/OF DL.csproj" -p:WarningLevel=0 -p:Version=$VERSION -c Release -o outcli # Generate default config.conf files -RUN /src/out/OF\ DL --non-interactive || true && \ +RUN /src/outcli/OF\ DL --non-interactive || true && \ # Set download path in default config.conf to /data sed -e 's/DownloadPath = ""/DownloadPath = "\/data"/' /src/config.conf > /src/updated_config.conf && \ mv /src/updated_config.conf /src/config.conf @@ -31,6 +33,7 @@ RUN apt-get update \ x11vnc \ novnc \ npm \ + openbox \ && rm -rf /var/lib/apt/lists/* RUN npx playwright install-deps @@ -45,7 +48,8 @@ RUN echo "
/dev/null +# Check if --cli flag was passed +if [[ " $@ " =~ " --cli " ]]; then + # CLI mode - no need for X server + # Remove --cli from arguments + args=("$@") + filtered_args=() + for arg in "${args[@]}"; do + if [ "$arg" != "--cli" ]; then + filtered_args+=("$arg") + fi + done -# Wait for the 3 supervisor programs to start: X11 (Xvfb), X11vnc, and noVNC -NUM_RUNNING_SERVICES=$(supervisorctl -c /etc/supervisor/conf.d/supervisord.conf status | grep RUNNING | wc -l) -while [ $NUM_RUNNING_SERVICES != "3" ]; do - sleep 1 + /app/cli/OF\ DL "${filtered_args[@]}" +else + # GUI mode - start X server and window manager + { + supervisord -c /etc/supervisor/conf.d/supervisord.conf & + } &> /dev/null + + # Wait for the 4 supervisor programs to start: X11 (Xvfb), openbox, X11vnc, and noVNC NUM_RUNNING_SERVICES=$(supervisorctl -c /etc/supervisor/conf.d/supervisord.conf status | grep RUNNING | wc -l) -done + while [ $NUM_RUNNING_SERVICES != "4" ]; do + sleep 1 + NUM_RUNNING_SERVICES=$(supervisorctl -c /etc/supervisor/conf.d/supervisord.conf status | grep RUNNING | wc -l) + done -/app/OF\ DL + # Wait for X server to be ready to accept connections + echo "Waiting for X server to be ready..." + timeout=30 + elapsed=0 + until xdpyinfo -display "$DISPLAY" >/dev/null 2>&1; do + if [ $elapsed -ge $timeout ]; then + echo "Timeout waiting for X server" + exit 1 + fi + sleep 1 + elapsed=$((elapsed + 1)) + done + echo "X server is ready" + + /app/gui/OF\ DL.Gui "$@" +fi diff --git a/docker/supervisord.conf b/docker/supervisord.conf index f8f7cd6..5d66a42 100644 --- a/docker/supervisord.conf +++ b/docker/supervisord.conf @@ -16,6 +16,11 @@ serverurl=unix:///tmp/supervisor.sock command=Xvfb :0 -screen 0 "%(ENV_DISPLAY_WIDTH)s"x"%(ENV_DISPLAY_HEIGHT)s"x24 autorestart=true +[program:openbox] +command=openbox +environment=DISPLAY=":0" +autorestart=true + [program:x11vnc] command=/usr/bin/x11vnc autorestart=true