Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: use /app/data for settings and stack storage (#18)
Kyle Mendellf2f3f1afb653
diff --git a/Dockerfile b/Dockerfileindex 984e80d8b..6c6d0ded2 100644--- a/Dockerfile+++ b/Dockerfile@@ -6,7 +6,8 @@ COPY package*.json ./RUN npm installCOPY . .RUN npm ci-RUN npm run build+# When building, set NODE_ENV to "build" to prevent connection attempts+RUN NODE_ENV=build npm run build# Stage 2: Production imageFROM node:22-alpine@@ -19,6 +20,12 @@ RUN apk add --no-cache su-exec curl shadowWORKDIR /app+# Make sure data directory exists and is writable+RUN mkdir -p /app/data && chmod 755 /app/data++# Copy default settings if starting fresh+COPY app-settings.json /app/data/app-settings.json.default+# Copy entrypoint scriptCOPY scripts/docker/entrypoint.sh /usr/local/bin/entrypoint.shRUN chmod +x /usr/local/bin/entrypoint.shdiff --git a/app-settings.json b/app-settings.jsonindex 16865b410..1698ad104 100644--- a/app-settings.json+++ b/app-settings.json@@ -3,5 +3,5 @@"autoRefresh": true,"refreshInterval": 10,"darkMode": true,- "stacksDirectory": ".arcane/stacks"+ "stacksDirectory": "/app/data/stacks"}diff --git a/scripts/docker/entrypoint.sh b/scripts/docker/entrypoint.shindex de18716c1..3144b04e0 100644--- a/scripts/docker/entrypoint.sh+++ b/scripts/docker/entrypoint.sh@@ -64,15 +64,53 @@ if ! id -nG "$APP_USER" | grep -qw "docker"; thenfi# Fix permissions for the Docker socket if it exists-if [ -e "/var/run/docker.sock" ]; then- echo "Entrypoint: Setting permissions for Docker socket..."- chmod 666 /var/run/docker.sock+if [ -S /var/run/docker.sock ]; then+ # Get the GID of the docker socket+ SOCKET_GID=$(stat -c '%g' /var/run/docker.sock)++ # If we have a different GID than expected, recreate the docker group+ if [ "${SOCKET_GID}" != "${DOCKER_GID}" ]; then+ echo "Docker socket GID (${SOCKET_GID}) doesn't match configured DOCKER_GID (${DOCKER_GID})"+ echo "Updating docker group to match socket GID"++ # Delete existing docker group+ delgroup docker >/dev/null 2>&1 || true++ # Create new docker group with socket GID+ addgroup -g "${SOCKET_GID}" docker++ # Add arcane user to the new docker group+ adduser arcane docker+ fi++ echo "Docker socket accessible at /var/run/docker.sock (GID: ${SOCKET_GID})"+else+ echo "WARNING: Docker socket not found at /var/run/docker.sock"+ echo "Make sure to mount the Docker socket when running this container"fi+# Ensure data directory exists+mkdir -p /app/data++# If settings don't exist, copy the default+if [ ! -f /app/data/app-settings.json ]; then+ if [ -f /app/data/app-settings.json.default ]; then+ cp /app/data/app-settings.json.default /app/data/app-settings.json+ fi+fi++# Ensure permissions+chmod 755 /app/data+chmod 644 /app/data/app-settings.json 2>/dev/null || true+# Change ownership of application directoriesecho "Entrypoint: Ensuring ownership of ${APP_DIR} for ${PUID}:${PGID}..."chown -R "$PUID":"$PGID" "$APP_DIR"+chown -R "$PUID":"$PGID" "$APP_DIR/data"++# Ensure permissions+chown -R arcane:arcane /app/data# Execute the command passed to the script (CMD) as the specified user-echo "Entrypoint: Switching to user ${APP_USER} (${PUID}:${PGID}) and executing command: $@"-exec su-exec "$APP_USER" "$@"+echo "Starting Arcane as user arcane ($(id -u arcane):$(id -g arcane))..."+exec su-exec arcane "$@"diff --git a/src/lib/services/compose.ts b/src/lib/services/compose.tsindex abe90b3c0..f62974ce0 100644--- a/src/lib/services/compose.ts+++ b/src/lib/services/compose.ts@@ -11,8 +11,7 @@ import type {} from "$lib/types/stack";import yaml from "js-yaml";-let STACKS_DIR =- process.env.STACKS_DIR || join(process.cwd(), ".arcane", "stacks");+let STACKS_DIR = process.env.STACKS_DIR || join("/app/data/stacks");/*** Update the stacks directory path@@ -45,8 +44,8 @@ async function ensureStacksDir(): Promise<void> {*/export async function initComposeService(): Promise<void> {try {- // Try to load settings- const settingsPath = join(process.cwd(), "app-settings.json");+ // Update settings path to match the new location+ const settingsPath = join("/app/data/app-settings.json");const settingsData = await fs.readFile(settingsPath, "utf8").catch(() => "{}");diff --git a/src/lib/services/docker-service.ts b/src/lib/services/docker-service.tsindex 11eb92747..81df6efbd 100644--- a/src/lib/services/docker-service.ts+++ b/src/lib/services/docker-service.ts@@ -2,9 +2,8 @@ import Docker from "dockerode";import { getSettings } from "$lib/services/settings-service";import type { DockerConnectionOptions } from "$lib/types/docker";-const initialSettings = await getSettings();-let dockerClient: Docker | null = null;+let dockerHost: string = "unix:///var/run/docker.sock"; // Default value/*** Initialize Docker connection with the given options@@ -16,9 +15,11 @@ export function initializeDocker(options: DockerConnectionOptions): Docker {// Handle different connection types (socket, tcp, etc.)if (options.socketPath) {connectionOpts.socketPath = options.socketPath;+ dockerHost = options.socketPath;} else if (options.host && options.port) {connectionOpts.host = options.host;connectionOpts.port = options.port;+ dockerHost = `${options.host}:${options.port}`;if (options.ca || options.cert || options.key) {connectionOpts.ca = options.ca;@@ -33,45 +34,45 @@ export function initializeDocker(options: DockerConnectionOptions): Docker {/*** Update the Docker connection with a new host string- * @param dockerHost Docker host connection string+ * @param host Docker host connection string*/-export function updateDockerConnection(dockerHost: string): Docker {- // Reset the client- dockerClient = null;+export function updateDockerConnection(host: string): void {+ try {+ // Only create a new connection if we have a valid host+ if (!host) {+ console.warn("No Docker host specified, connection not established");+ return;+ }- // Parse the host string to determine connection type- let connectionOpts: any = {};+ console.log(`Connecting to Docker at ${host}`);+ let connectionOpts: any = {};++ // Parse the host string to determine connection type+ if (host.startsWith("unix://")) {+ // Unix socket connection - remove the unix:// prefix+ connectionOpts.socketPath = host.replace("unix://", "");+ } else if (host.startsWith("tcp://")) {+ // TCP connection (no TLS)+ const url = new URL(host);+ connectionOpts.host = url.hostname;+ connectionOpts.port = parseInt(url.port || "2375", 10);+ } else if (host.startsWith("https://")) {+ // HTTPS connection (TLS)+ const url = new URL(host);+ connectionOpts.host = url.hostname;+ connectionOpts.port = parseInt(url.port || "2376", 10);+ connectionOpts.protocol = "https";+ } else {+ // If it doesn't have a prefix, assume it's a direct socket path+ connectionOpts.socketPath = host;+ }- if (dockerHost.startsWith("unix://")) {- // Unix socket connection- connectionOpts.socketPath = dockerHost.replace("unix://", "");- } else if (dockerHost.startsWith("tcp://")) {- // TCP connection (no TLS)- const url = new URL(dockerHost);- connectionOpts.host = url.hostname;- connectionOpts.port = parseInt(url.port || "2375", 10);- } else if (dockerHost.startsWith("https://")) {- // HTTPS connection (TLS)- const url = new URL(dockerHost);- connectionOpts.host = url.hostname;- connectionOpts.port = parseInt(url.port || "2376", 10);- connectionOpts.protocol = "https";- // Note: For TLS, you would typically need to provide ca, cert, and key- // which should be handled separately- } else {- // Default to socket if format is unknown- const socketPath =- process.platform === "win32"- ? "//./pipe/docker_engine"- : "/var/run/docker.sock";- connectionOpts.socketPath = socketPath;+ dockerClient = new Docker(connectionOpts);+ dockerHost = host;+ console.log("Docker connection updated with options:", connectionOpts);+ } catch (error) {+ console.error("Error connecting to Docker:", error);}-- // Create new Docker client with updated connection- dockerClient = new Docker(connectionOpts);- console.log(`Docker connection updated to: ${dockerHost}`);-- return dockerClient;}/**@@ -79,15 +80,31 @@ export function updateDockerConnection(dockerHost: string): Docker {*/export function getDockerClient(): Docker {if (!dockerClient) {- // Default to socket path for local development- const socketPath =- process.platform === "win32"- ? "//./pipe/docker_engine"- : "/var/run/docker.sock";+ let connectionOpts: any = {};++ // Parse the dockerHost to get the proper connection options+ if (dockerHost.startsWith("unix://")) {+ connectionOpts.socketPath = dockerHost.replace("unix://", "");+ } else if (dockerHost.startsWith("tcp://")) {+ const url = new URL(dockerHost);+ connectionOpts.host = url.hostname;+ connectionOpts.port = parseInt(url.port || "2375", 10);+ } else if (dockerHost.startsWith("https://")) {+ const url = new URL(dockerHost);+ connectionOpts.host = url.hostname;+ connectionOpts.port = parseInt(url.port || "2376", 10);+ connectionOpts.protocol = "https";+ } else {+ // If it doesn't have a prefix, assume it's a direct socket path+ connectionOpts.socketPath = dockerHost;+ }- dockerClient = new Docker({ socketPath });+ dockerClient = new Docker(connectionOpts);+ console.log(+ `Initialized Docker client with host: ${dockerHost}`,+ connectionOpts+ );}-return dockerClient;}@@ -152,7 +169,7 @@ export async function listContainers(all = true): Promise<ServiceContainer[]> {} catch (error: any) {console.error("Docker Service: Error listing containers:", error);throw new Error(- `Failed to list Docker containers using host "${initialSettings.dockerHost}".`+ `Failed to list Docker containers using host "${dockerHost}".`);}}@@ -186,7 +203,7 @@ export async function getContainer(containerId: string) {return null;}throw new Error(- `Failed to get container details for ${containerId} using host "${initialSettings.dockerHost}".`+ `Failed to get container details for ${containerId} using host "${dockerHost}".`);}}@@ -206,9 +223,9 @@ export async function startContainer(containerId: string): Promise<void> {error);throw new Error(- `Failed to start container ${containerId} using host "${- initialSettings.dockerHost- }". ${error.message || ""}`+ `Failed to start container ${containerId} using host "${dockerHost}". ${+ error.message || ""+ }`);}}@@ -228,9 +245,9 @@ export async function stopContainer(containerId: string): Promise<void> {error);throw new Error(- `Failed to stop container ${containerId} using host "${- initialSettings.dockerHost- }". ${error.message || ""}`+ `Failed to stop container ${containerId} using host "${dockerHost}". ${+ error.message || ""+ }`);}}@@ -250,9 +267,9 @@ export async function restartContainer(containerId: string): Promise<void> {error);throw new Error(- `Failed to restart container ${containerId} using host "${- initialSettings.dockerHost- }". ${error.message || ""}`+ `Failed to restart container ${containerId} using host "${dockerHost}". ${+ error.message || ""+ }`);}}@@ -284,9 +301,9 @@ export async function removeContainer();}throw new Error(- `Failed to remove container ${containerId} using host "${- initialSettings.dockerHost- }". ${error.message || ""}`+ `Failed to remove container ${containerId} using host "${dockerHost}". ${+ error.message || ""+ }`);}}@@ -348,9 +365,9 @@ export async function getContainerLogs(error);throw new Error(- `Failed to get logs for container ${containerId} using host "${- initialSettings.dockerHost- }". ${error.message || ""}`+ `Failed to get logs for container ${containerId} using host "${dockerHost}". ${+ error.message || ""+ }`);}}@@ -407,9 +424,7 @@ export async function listImages(): Promise<ServiceImage[]> {});} catch (error: any) {console.error("Docker Service: Error listing images:", error);- throw new Error(- `Failed to list Docker images using host "${initialSettings.dockerHost}".`- );+ throw new Error(`Failed to list Docker images using host "${dockerHost}".`);}}@@ -445,7 +460,7 @@ export async function listNetworks(): Promise<ServiceNetwork[]> {} catch (error: any) {console.error("Docker Service: Error listing networks:", error);throw new Error(- `Failed to list Docker networks using host "${initialSettings.dockerHost}".`+ `Failed to list Docker networks using host "${dockerHost}".`);}}@@ -480,7 +495,7 @@ export async function listVolumes(): Promise<ServiceVolume[]> {} catch (error: any) {console.error("Docker Service: Error listing volumes:", error);throw new Error(- `Failed to list Docker volumes using host "${initialSettings.dockerHost}".`+ `Failed to list Docker volumes using host "${dockerHost}".`);}}diff --git a/src/lib/services/settings-service.ts b/src/lib/services/settings-service.tsindex 5bbc09195..1064e24d9 100644--- a/src/lib/services/settings-service.ts+++ b/src/lib/services/settings-service.ts@@ -4,7 +4,8 @@ import { updateDockerConnection } from "./docker-service";import fs from "fs/promises";import path from "path";-const SETTINGS_FILE = path.resolve("./app-settings.json");+// Update the settings file path to be in /app/data directory+const SETTINGS_FILE = path.resolve("/app/data/app-settings.json");// Default settingsconst DEFAULT_SETTINGS: SettingsData = {@@ -12,34 +13,39 @@ const DEFAULT_SETTINGS: SettingsData = {autoRefresh: true,refreshInterval: 10,darkMode: true,- stacksDirectory: path.resolve(".arcane", "stacks"),+ stacksDirectory: path.resolve("/app/data/stacks"),};// Get settingsexport async function getSettings(): Promise<SettingsData> {try {- const data = await fs.readFile(SETTINGS_FILE, "utf-8");- const parsed = JSON.parse(data);+ const settingsDir = path.dirname(SETTINGS_FILE);+ await fs.mkdir(settingsDir, { recursive: true });- // Ensure all expected properties exist- return {- ...DEFAULT_SETTINGS,- ...parsed,- };- } catch (error: any) {- if (error.code === "ENOENT") {+ const data = await fs.readFile(SETTINGS_FILE, "utf-8").catch(() => {console.log("Settings file not found, using defaults.");- // Automatically save defaults if file doesn't exist- await saveSettings(DEFAULT_SETTINGS);- return DEFAULT_SETTINGS;+ return JSON.stringify(DEFAULT_SETTINGS);+ });++ const settings = { ...DEFAULT_SETTINGS, ...JSON.parse(data) };++ // Don't try to update Docker connection during build time+ if (process.env.NODE_ENV !== "build") {+ await saveSettings(settings, false); // Don't update connections during initialization}++ return settings;+ } catch (error) {console.error("Error loading settings:", error);return DEFAULT_SETTINGS;}}// Save settings-export async function saveSettings(settings: SettingsData): Promise<void> {+export async function saveSettings(+ settings: SettingsData,+ updateConnections = true+): Promise<void> {try {// Ensure directory existsconst settingsDir = path.dirname(SETTINGS_FILE);@@ -54,22 +60,13 @@ export async function saveSettings(settings: SettingsData): Promise<void> {console.log("Settings saved to:", SETTINGS_FILE);- // Apply settings to runtime services- updateDockerConnection(settings.dockerHost);- updateStacksDirectory(settings.stacksDirectory);+ // Apply settings to runtime services - but skip during builds or initial loading+ if (updateConnections && process.env.NODE_ENV !== "build") {+ updateDockerConnection(settings.dockerHost);+ updateStacksDirectory(settings.stacksDirectory);+ }} catch (error) {console.error("Error saving settings:", error);throw new Error("Failed to save settings.");}}--// Initialize settings on server start-export async function initializeSettings(): Promise<SettingsData> {- const settings = await getSettings();-- // Apply settings to services- updateDockerConnection(settings.dockerHost);- updateStacksDirectory(settings.stacksDirectory);-- return settings;-}diff --git a/src/routes/settings/+page.server.ts b/src/routes/settings/+page.server.tsindex 03206b90c..33c1620eb 100644--- a/src/routes/settings/+page.server.ts+++ b/src/routes/settings/+page.server.ts@@ -3,9 +3,16 @@ import { fail } from "@sveltejs/kit";import { getSettings, saveSettings } from "$lib/services/settings-service";import type { SettingsData } from "$lib/types/settings";-export const load: PageServerLoad = async () => {+export const load: PageServerLoad = async ({ locals }) => {const settings = await getSettings();- return { settings };++ // Generate a CSRF token+ const csrf = crypto.randomUUID();++ return {+ settings,+ csrf,+ };};export const actions: Actions = {diff --git a/src/routes/settings/+page.svelte b/src/routes/settings/+page.svelteindex 45e22eaf8..bfefc8e13 100644--- a/src/routes/settings/+page.svelte+++ b/src/routes/settings/+page.svelte@@ -108,6 +108,7 @@<!-- Settings Form --><formmethod="POST"+ action="?"id="settings-form"class="space-y-6"use:enhance={() => {@@ -118,6 +119,9 @@};}}>+ <!-- Add a hidden input with a CSRF token -->+ <input type="hidden" name="csrf_token" value={data.csrf} />+<div class="grid grid-cols-1 lg:grid-cols-2 gap-6"><!-- Docker Connection Card --><Card.Root class="border shadow-sm">@@ -165,13 +169,14 @@id="stacksDirectory"name="stacksDirectory"bind:value={stacksDirectory}- placeholder=".arcane/stacks"+ placeholder="/app/data/stacks"required/><p class="text-xs text-muted-foreground">- Directory where Docker Compose stacks will be stored+ Directory where Docker Compose stacks will be stored inside the+ container.</p>- <p class="text-xs text-destructive">+ <p class="text-xs font-bold text-destructive">Changing this setting will not move existing stacks!</p></div>diff --git a/svelte.config.js b/svelte.config.jsindex 197c453f8..760c6b1c0 100644--- a/svelte.config.js+++ b/svelte.config.js@@ -4,14 +4,14 @@ import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";const config = {preprocess: vitePreprocess(),kit: {- // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.- // If your environment is not supported, or you settled on a specific environment, switch out the adapter.- // See https://kit.svelte.dev/docs/adapters for more information about adapters.adapter: adapter({out: "build",precompress: false,polyfill: true,}),+ csrf: {+ checkOrigin: process.env.NODE_ENV === "production",+ },},};