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
56 changes: 5 additions & 51 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,56 +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 an admin API key on first run. rustguac decides what "first run"
# means: it opens the database named by db_path in the config and creates
# the admin only if there is none yet. Checking for a database file at a fixed
# path here broke any config that moved db_path: every restart then tried to
# create the admin again and failed on the existing one (#240).
ADMIN_OUT=$(/opt/rustguac/bin/rustguac --config "$CONFIG_PATH" add-admin --name docker-admin --if-none)
echo "$ADMIN_OUT"
case "$ADMIN_OUT" in
*"API Key:"*)
echo ""
echo "==> SAVE THE API KEY ABOVE — it is only shown once! <=="
echo ""
;;
esac

# 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 @@ -246,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"]
49 changes: 49 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/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 an admin API key on first run. rustguac decides what "first run"
# means: it opens the database named by db_path in the config and creates
# the admin only if there is none yet. Checking for a database file at a fixed
# path here broke any config that moved db_path: every restart then tried to
# create the admin again and failed on the existing one (#240).
ADMIN_OUT=$(/opt/rustguac/bin/rustguac --config "$CONFIG_PATH" add-admin --name docker-admin --if-none)
echo "$ADMIN_OUT"
case "$ADMIN_OUT" in
*"API Key:"*)
echo ""
echo "==> SAVE THE API KEY ABOVE — it is only shown once! <=="
echo ""
;;
esac

# 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