Add GUI application to docker
This commit is contained in:
parent
f9089a339a
commit
6b7cb29e2e
14
Dockerfile
14
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 "<!DOCTYPE html><html><head><meta http-equiv=\"Refresh\" content=\"0; u
|
||||
RUN mkdir /data /config /config/logs /default-config
|
||||
|
||||
# Copy release
|
||||
COPY --from=build /src/out /app
|
||||
COPY --from=build /src/outcli /app/cli
|
||||
COPY --from=build /src/outgui /app/gui
|
||||
|
||||
# Copy default configuration files
|
||||
COPY --from=build /src/config.conf /default-config
|
||||
@ -64,5 +68,5 @@ ENV DEBIAN_FRONTEND="noninteractive" \
|
||||
|
||||
EXPOSE 8080
|
||||
WORKDIR /config
|
||||
ENTRYPOINT ["/usr/bin/tini", "--"]
|
||||
CMD ["/app/entrypoint.sh"]
|
||||
ENTRYPOINT ["/usr/bin/tini", "--", "/app/entrypoint.sh"]
|
||||
CMD []
|
||||
|
||||
@ -21,6 +21,13 @@ public static class Program
|
||||
|
||||
Log.Information("Starting OF DL GUI");
|
||||
|
||||
// Check if running in Docker and print message
|
||||
string? ofdlDocker = Environment.GetEnvironmentVariable("OFDL_DOCKER");
|
||||
if (string.Equals(ofdlDocker, "true", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Console.WriteLine("In your web browser, navigate to the port forwarded from your docker container. For instance, if your docker run command included \"-p 8080:8080\", open your web browser to \"http://localhost:8080\".");
|
||||
}
|
||||
|
||||
BuildAvaloniaApp()
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
}
|
||||
|
||||
@ -26,6 +26,14 @@ public partial class MainWindow : Window
|
||||
{
|
||||
InitializeComponent();
|
||||
Icon = new WindowIcon(AssetLoader.Open(new Uri("avares://OF DL.Gui/Assets/icon.ico")));
|
||||
|
||||
// Start maximized if running in Docker
|
||||
string? ofdlDocker = Environment.GetEnvironmentVariable("OFDL_DOCKER");
|
||||
if (string.Equals(ofdlDocker, "true", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
WindowState = WindowState.Maximized;
|
||||
}
|
||||
|
||||
Opened += OnOpened;
|
||||
Closed += OnClosed;
|
||||
}
|
||||
|
||||
@ -12,15 +12,45 @@ if [ ! -f /config/rules.json ]; then
|
||||
cp /default-config/rules.json /config/rules.json
|
||||
fi
|
||||
|
||||
{
|
||||
supervisord -c /etc/supervisor/conf.d/supervisord.conf &
|
||||
} &> /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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user