Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 5 additions & 46 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
x11-utils \
# Minimal runtime utilities
ca-certificates \
tini \
&& rm -rf /var/lib/apt/lists/*

# Install guacd
Expand Down Expand Up @@ -185,51 +186,7 @@ RUN chown rustguac:rustguac /opt/rustguac && \
/opt/rustguac/tls /opt/rustguac/certs /opt/rustguac/drives \
/opt/rustguac/scripts /opt/rustguac/vdi-homes /opt/rustguac/config.toml.default

# Entrypoint script: starts guacd in background, then rustguac in foreground
RUN cat > /opt/rustguac/entrypoint.sh <<'SCRIPT'
#!/bin/sh
set -e

# Copy default config on first run (if no config file is mounted/present)
CONFIG_PATH="/opt/rustguac/config.toml"
if [ ! -f "$CONFIG_PATH" ]; then
echo "No config.toml found — copying default configuration."
cp /opt/rustguac/config.toml.default "$CONFIG_PATH"
fi

# Create admin API key on first run (if no DB exists yet)
DB_PATH="/opt/rustguac/data/rustguac.db"
if [ ! -f "$DB_PATH" ]; then
echo "First run detected — creating admin API key..."
/opt/rustguac/bin/rustguac --config "$CONFIG_PATH" add-admin --name docker-admin
echo ""
echo "==> SAVE THE API KEY ABOVE — it is only shown once! <=="
echo ""
fi

# Start guacd in background
echo "Starting guacd..."
LD_LIBRARY_PATH=/opt/rustguac/lib FREERDP_ADDIN_PATH=/opt/rustguac/lib/freerdp3 \
/opt/rustguac/sbin/guacd \
-b 127.0.0.1 -l 4822 -L "${GUACD_LOG_LEVEL:-info}" -f \
-C /opt/rustguac/tls/cert.pem -K /opt/rustguac/tls/key.pem &
GUACD_PID=$!

# Wait briefly to confirm guacd started
sleep 0.5
if ! kill -0 "$GUACD_PID" 2>/dev/null; then
echo "ERROR: guacd failed to start"
exit 1
fi
echo "guacd started (pid=$GUACD_PID)"

# Trap signals to shut down both processes
trap 'kill $GUACD_PID 2>/dev/null; wait; exit 0' TERM INT

# Run rustguac in foreground
echo "Starting rustguac..."
exec /opt/rustguac/bin/rustguac --config "$CONFIG_PATH" serve
SCRIPT
COPY entrypoint.sh /opt/rustguac/entrypoint.sh
RUN chmod +x /opt/rustguac/entrypoint.sh

WORKDIR /opt/rustguac
Expand All @@ -241,4 +198,6 @@ ENV GUACD_LOG_LEVEL=info
ENV HOME=/home/rustguac

USER rustguac
ENTRYPOINT ["/opt/rustguac/entrypoint.sh"]
ENV TINI_KILL_PROCESS_GROUP=1
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["/opt/rustguac/entrypoint.sh"]
44 changes: 44 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh
# Entrypoint script: starts guacd in background, then rustguac in background, waiting on both to exit
set -e

# Copy default config on first run (if no config file is mounted/present)
CONFIG_PATH="/opt/rustguac/config.toml"
if [ ! -f "$CONFIG_PATH" ]; then
echo "No config.toml found — copying default configuration."
cp /opt/rustguac/config.toml.default "$CONFIG_PATH"
fi

# Create admin API key on first run (if no DB exists yet)
DB_PATH="/opt/rustguac/data/rustguac.db"
if [ ! -f "$DB_PATH" ]; then
echo "First run detected — creating admin API key..."
/opt/rustguac/bin/rustguac --config "$CONFIG_PATH" add-admin --name docker-admin
echo ""
echo "==> SAVE THE API KEY ABOVE — it is only shown once! <=="
echo ""
fi

# Start guacd in background
echo "Starting guacd..."
LD_LIBRARY_PATH=/opt/rustguac/lib FREERDP_ADDIN_PATH=/opt/rustguac/lib/freerdp3 \
/opt/rustguac/sbin/guacd \
-b 127.0.0.1 -l 4822 -L "${GUACD_LOG_LEVEL:-info}" -f \
-C /opt/rustguac/tls/cert.pem -K /opt/rustguac/tls/key.pem &
GUACD_PID=$!

# Wait briefly to confirm guacd started
sleep 0.5
if ! kill -0 "$GUACD_PID" 2>/dev/null; then
echo "ERROR: guacd failed to start"
exit 1
fi
echo "guacd started (pid=$GUACD_PID)"


# Run rustguac in foreground
echo "Starting rustguac..."
/opt/rustguac/bin/rustguac --config "$CONFIG_PATH" serve &
RUSTGUAC_PID=$!

wait $GUACD_PID $RUSTGUAC_PID
Loading