Skip to content

A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.

refactor: Build Docker image from built binaries instead of source code.

towfiqi0946da6e8057
diff --git a/.dockerignore b/.dockerignore
index 73eb518..6688898 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,16 +1,17 @@
-# Dependencies
+# Dependencies (exclude all node_modules except in dist/executables)
node_modules/
-**/node_modules/
+# Note: We can't use **/node_modules/ because it would exclude contents inside dist/executables
# Build outputs
-dist/
-**/dist/
build/
-**/build/
+backend/dist/
+frontend/dist/
+frontend/dist-lib/
+# Keep dist/executables for Dockerfile
# Development data
data/
-**/data/
+backend/data/
# Test files
coverage/
diff --git a/.github/workflows/release-assets.yml b/.github/workflows/release-assets.yml
index b8e35d4..ab58d3d 100644
--- a/.github/workflows/release-assets.yml
+++ b/.github/workflows/release-assets.yml
@@ -21,6 +21,9 @@ jobs:
steps:
- uses: actions/checkout@v4
+ - name: Set up QEMU
+ uses: docker/setup-qemu-action@v3
+
- uses: pnpm/action-setup@v2
with:
version: 10.20.0
@@ -46,6 +49,13 @@ jobs:
chmod +x installers/linux/build-appimage.sh
bash installers/linux/build-appimage.sh
+ - name: Upload Executables Artifact
+ uses: actions/upload-artifact@v4
+ with:
+ name: pluton-executables
+ path: dist/executables
+ retention-days: 1
+
- name: Upload Linux Assets
if: ${{ !env.ACT }}
uses: softprops/action-gh-release@v2
@@ -95,10 +105,17 @@ jobs:
docker:
name: Build Docker Image
+ needs: build-linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
+ - name: Download Executables Artifact
+ uses: actions/download-artifact@v4
+ with:
+ name: pluton-executables
+ path: dist/executables
+
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
@@ -124,6 +141,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
+ file: Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ !env.ACT }}
tags: |
diff --git a/Dockerfile b/Dockerfile
index 1fc1855..d79e6a2 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,183 +1,68 @@
-# Build arguments (can be overridden at build time)
-ARG APP_VERSION=0.0.1
-ARG RESTIC_VERSION=0.18.1
-ARG RCLONE_VERSION=1.71.2
-
-# Stage 1: Dependencies
-FROM node:24-alpine AS deps
-
-# Install pnpm
-RUN corepack enable && corepack prepare pnpm@latest --activate
-
-WORKDIR /workspace
-
-# Copy workspace configuration files
-COPY package.json pnpm-workspace.yaml pnpm-lock.yaml turbo.json ./
-COPY frontend/package.json ./frontend/package.json
-COPY backend/package.json ./backend/package.json
-
-# Install all dependencies (needed for building)
-RUN pnpm install --frozen-lockfile
-
-# Stage 2: Frontend Builder
-FROM node:24-alpine AS frontend-builder
-
-# Install pnpm
-RUN corepack enable && corepack prepare pnpm@latest --activate
-
-WORKDIR /workspace
-
-# Copy dependencies from deps stage
-COPY --from=deps /workspace/node_modules ./node_modules
-COPY --from=deps /workspace/package.json ./package.json
-COPY --from=deps /workspace/pnpm-workspace.yaml ./pnpm-workspace.yaml
-COPY --from=deps /workspace/frontend/node_modules ./frontend/node_modules
-COPY --from=deps /workspace/frontend/package.json ./frontend/package.json
-
-# Copy frontend source code
-COPY frontend ./frontend
-
-# Build frontend
-WORKDIR /workspace/frontend
-RUN pnpm run build
-
-# Stage 3: Backend Builder
-FROM node:24-alpine AS backend-builder
-
-# Install pnpm
-RUN corepack enable && corepack prepare pnpm@latest --activate
-
-WORKDIR /workspace
-
-# Copy dependencies from deps stage
-COPY --from=deps /workspace/node_modules ./node_modules
-COPY --from=deps /workspace/package.json ./package.json
-COPY --from=deps /workspace/pnpm-workspace.yaml ./pnpm-workspace.yaml
-COPY --from=deps /workspace/backend/node_modules ./backend/node_modules
-COPY --from=deps /workspace/backend/package.json ./backend/package.json
+# Dockerfile
+# Uses pre-built binaries from scripts/build-executables.js
+# Run "node scripts/build-executables.js" before building this image.
-# Copy backend source code
-COPY backend ./backend
+FROM debian:bookworm-slim
-# Build backend (compile TypeScript)
-WORKDIR /workspace/backend
-RUN pnpm run build:pkg
-
-# Generate database migrations
-RUN npx drizzle-kit generate
-
-# Stage 4: Production Dependencies
-FROM node:24-alpine AS prod-deps
-
-# Install pnpm and build tools for native modules
-RUN corepack enable && corepack prepare pnpm@latest --activate && \
- apk add --no-cache python3 make g++
-
-WORKDIR /workspace
-
-# Copy workspace configuration
-COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
-COPY backend/package.json ./backend/package.json
-
-# Install production dependencies only (allow scripts for better-sqlite3)
-RUN pnpm install --prod --frozen-lockfile
-
-# Remove build tools
-RUN apk del python3 make g++
-
-# Stage 5: Production Image
-FROM node:24-alpine AS production
+ARG TARGETARCH=amd64
+ARG APP_VERSION=0.0.1
-# Install wget for healthcheck
-RUN apk add --no-cache wget
+# Install runtime dependencies
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ ca-certificates \
+ openssl \
+ fuse \
+ wget \
+ && rm -rf /var/lib/apt/lists/*
WORKDIR /app
-# Copy compiled backend from builder
-COPY --from=backend-builder /workspace/backend/dist ./dist
-COPY --from=backend-builder /workspace/backend/drizzle ./drizzle
-COPY --from=backend-builder /workspace/backend/loader.mjs ./loader.mjs
-COPY --from=backend-builder /workspace/backend/package.json ./package.json
-
-# Copy frontend build to public directory
-COPY --from=frontend-builder /workspace/frontend/dist ./public
-
-# Copy production node_modules (pnpm workspace structure)
-# Copy the .pnpm virtual store
-COPY --from=prod-deps /workspace/node_modules/.pnpm ./node_modules/.pnpm
-
-# Create symlinks for each package in node_modules
-# This replicates what pnpm does for workspace packages
-RUN cd node_modules/.pnpm && \
- for dir in *; do \
- if [ -d "$dir/node_modules" ]; then \
- for pkg in $dir/node_modules/*; do \
- pkg_name=$(basename $pkg); \
- if [ ! -e "../$pkg_name" ]; then \
- ln -s ".pnpm/$dir/node_modules/$pkg_name" "../$pkg_name" 2>/dev/null || true; \
- fi; \
- done; \
- fi; \
- done
-
-# Create data directory
-RUN mkdir -p /data /data/logs /data/db /data/config
-
-# Download specific versions of restic and rclone binaries and place in system PATH
-ARG TARGETARCH
-ARG RESTIC_VERSION
-ARG RCLONE_VERSION
-RUN echo "Building for architecture: ${TARGETARCH}" && \
- echo "Installing restic v${RESTIC_VERSION} and rclone v${RCLONE_VERSION}" && \
- # Download restic
- if [ "${TARGETARCH}" = "amd64" ]; then \
- wget -q "https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_linux_amd64.bz2" -O /tmp/restic.bz2; \
- elif [ "${TARGETARCH}" = "arm64" ]; then \
- wget -q "https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_linux_arm64.bz2" -O /tmp/restic.bz2; \
+# Select and install the correct architecture using bind mount to avoid copying all binaries to the image layer
+RUN --mount=type=bind,source=dist/executables,target=/tmp/executables \
+ set -e && \
+ ARCH_SUFFIX=$( [ "$TARGETARCH" = "amd64" ] && echo "x64" || echo "arm64" ) && \
+ SOURCE_DIR="/tmp/executables/pluton-linux-${ARCH_SUFFIX}" && \
+ if [ ! -d "$SOURCE_DIR" ]; then \
+ echo "Error: Directory $SOURCE_DIR not found"; \
+ ls -R /tmp/executables; \
+ exit 1; \
fi && \
- bunzip2 /tmp/restic.bz2 && \
- mv /tmp/restic /usr/local/bin/restic && \
- chmod +x /usr/local/bin/restic && \
- # Download rclone
- if [ "${TARGETARCH}" = "amd64" ]; then \
- wget -q "https://downloads.rclone.org/v${RCLONE_VERSION}/rclone-v${RCLONE_VERSION}-linux-amd64.zip" -O /tmp/rclone.zip; \
- elif [ "${TARGETARCH}" = "arm64" ]; then \
- wget -q "https://downloads.rclone.org/v${RCLONE_VERSION}/rclone-v${RCLONE_VERSION}-linux-arm64.zip" -O /tmp/rclone.zip; \
+ # Copy application files (use /. to copy all contents including hidden files)
+ cp -r "$SOURCE_DIR"/. /app/ && \
+ chmod +x /app/pluton && \
+ # Verify native modules were copied
+ if [ ! -f "/app/node_modules/better-sqlite3/build/Release/better_sqlite3.node" ]; then \
+ echo "Error: better_sqlite3.node not found after copy"; \
+ ls -la /app/; \
+ exit 1; \
fi && \
- apk add --no-cache unzip && \
- unzip -q /tmp/rclone.zip -d /tmp && \
- mv /tmp/rclone-*/rclone /usr/local/bin/rclone && \
- chmod +x /usr/local/bin/rclone && \
- rm -rf /tmp/rclone* && \
- apk del unzip && \
- # Verify installations (unset env vars to avoid conflicts with rclone flags)
- unset RESTIC_VERSION RCLONE_VERSION && \
- restic version && \
- rclone version
-
-# Create Pluton wrapper scripts for rclone and restic
-# These ensure the tools use Pluton's configuration from /data/config
+ # Setup binaries
+ mkdir -p /usr/local/bin && \
+ cp "/app/binaries/linux-${ARCH_SUFFIX}/restic" /usr/local/bin/restic && \
+ cp "/app/binaries/linux-${ARCH_SUFFIX}/rclone" /usr/local/bin/rclone && \
+ chmod +x /usr/local/bin/restic /usr/local/bin/rclone && \
+ # Remove duplicate binaries from app directory (they're now in /usr/local/bin)
+ rm -rf /app/binaries
+
+# Create wrappers
RUN echo '#!/bin/sh' > /usr/local/bin/prclone && \
- echo '# Pluton Wrapper for rclone' >> /usr/local/bin/prclone && \
- echo '# This script ensures that rclone uses Pluton configuration.' >> /usr/local/bin/prclone && \
echo 'exec /usr/local/bin/rclone --config /data/config/rclone.conf "$@"' >> /usr/local/bin/prclone && \
chmod +x /usr/local/bin/prclone && \
echo '#!/bin/sh' > /usr/local/bin/prestic && \
- echo '# Pluton Wrapper for restic' >> /usr/local/bin/prestic && \
- echo '# This script ensures that restic uses Pluton rclone binary and configuration.' >> /usr/local/bin/prestic && \
echo 'export RCLONE_CONFIG=/data/config/rclone.conf' >> /usr/local/bin/prestic && \
echo 'exec /usr/local/bin/restic -o rclone.program=/usr/local/bin/rclone "$@"' >> /usr/local/bin/prestic && \
chmod +x /usr/local/bin/prestic
-# Set environment variables
-ARG APP_VERSION
+# Create data directories
+RUN mkdir -p /data/config /data/db /data/logs /data/backups /data/progress /data/rescue /data/restore /data/stats /data/sync
+
ENV NODE_ENV=production \
IS_DOCKER=true \
SERVER_PORT=5173 \
- APP_VERSION=${APP_VERSION}
+ APP_VERSION=${APP_VERSION} \
+ PLUTON_DATA_DIR=/data \
+ PATH="/usr/local/bin:$PATH"
-# Expose the application port
EXPOSE 5173
-# Start the application with custom loader for extension-less imports
-CMD ["node", "--loader", "./loader.mjs", "dist/index.js"]
\ No newline at end of file
+CMD ["./pluton"]
diff --git a/Dockerfile.source b/Dockerfile.source
new file mode 100644
index 0000000..920a1b5
--- /dev/null
+++ b/Dockerfile.source
@@ -0,0 +1,186 @@
+# Dockerfile
+# Uses Source to Build the docker Image
+
+# Build arguments (can be overridden at build time)
+ARG APP_VERSION=0.0.1
+ARG RESTIC_VERSION=0.18.1
+ARG RCLONE_VERSION=1.71.2
+
+# Stage 1: Dependencies
+FROM node:24-alpine AS deps
+
+# Install pnpm
+RUN corepack enable && corepack prepare pnpm@latest --activate
+
+WORKDIR /workspace
+
+# Copy workspace configuration files
+COPY package.json pnpm-workspace.yaml pnpm-lock.yaml turbo.json ./
+COPY frontend/package.json ./frontend/package.json
+COPY backend/package.json ./backend/package.json
+
+# Install all dependencies (needed for building)
+RUN pnpm install --frozen-lockfile
+
+# Stage 2: Frontend Builder
+FROM node:24-alpine AS frontend-builder
+
+# Install pnpm
+RUN corepack enable && corepack prepare pnpm@latest --activate
+
+WORKDIR /workspace
+
+# Copy dependencies from deps stage
+COPY --from=deps /workspace/node_modules ./node_modules
+COPY --from=deps /workspace/package.json ./package.json
+COPY --from=deps /workspace/pnpm-workspace.yaml ./pnpm-workspace.yaml
+COPY --from=deps /workspace/frontend/node_modules ./frontend/node_modules
+COPY --from=deps /workspace/frontend/package.json ./frontend/package.json
+
+# Copy frontend source code
+COPY frontend ./frontend
+
+# Build frontend
+WORKDIR /workspace/frontend
+RUN pnpm run build
+
+# Stage 3: Backend Builder
+FROM node:24-alpine AS backend-builder
+
+# Install pnpm
+RUN corepack enable && corepack prepare pnpm@latest --activate
+
+WORKDIR /workspace
+
+# Copy dependencies from deps stage
+COPY --from=deps /workspace/node_modules ./node_modules
+COPY --from=deps /workspace/package.json ./package.json
+COPY --from=deps /workspace/pnpm-workspace.yaml ./pnpm-workspace.yaml
+COPY --from=deps /workspace/backend/node_modules ./backend/node_modules
+COPY --from=deps /workspace/backend/package.json ./backend/package.json
+
+# Copy backend source code
+COPY backend ./backend
+
+# Build backend (compile TypeScript)
+WORKDIR /workspace/backend
+RUN pnpm run build:pkg
+
+# Generate database migrations
+RUN npx drizzle-kit generate
+
+# Stage 4: Production Dependencies
+FROM node:24-alpine AS prod-deps
+
+# Install pnpm and build tools for native modules
+RUN corepack enable && corepack prepare pnpm@latest --activate && \
+ apk add --no-cache python3 make g++
+
+WORKDIR /workspace
+
+# Copy workspace configuration
+COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
+COPY backend/package.json ./backend/package.json
+
+# Install production dependencies only (allow scripts for better-sqlite3)
+RUN pnpm install --prod --frozen-lockfile
+
+# Remove build tools
+RUN apk del python3 make g++
+
+# Stage 5: Production Image
+FROM node:24-alpine AS production
+
+# Install wget for healthcheck
+RUN apk add --no-cache wget
+
+WORKDIR /app
+
+# Copy compiled backend from builder
+COPY --from=backend-builder /workspace/backend/dist ./dist
+COPY --from=backend-builder /workspace/backend/drizzle ./drizzle
+COPY --from=backend-builder /workspace/backend/loader.mjs ./loader.mjs
+COPY --from=backend-builder /workspace/backend/package.json ./package.json
+
+# Copy frontend build to public directory
+COPY --from=frontend-builder /workspace/frontend/dist ./public
+
+# Copy production node_modules (pnpm workspace structure)
+# Copy the .pnpm virtual store
+COPY --from=prod-deps /workspace/node_modules/.pnpm ./node_modules/.pnpm
+
+# Create symlinks for each package in node_modules
+# This replicates what pnpm does for workspace packages
+RUN cd node_modules/.pnpm && \
+ for dir in *; do \
+ if [ -d "$dir/node_modules" ]; then \
+ for pkg in $dir/node_modules/*; do \
+ pkg_name=$(basename $pkg); \
+ if [ ! -e "../$pkg_name" ]; then \
+ ln -s ".pnpm/$dir/node_modules/$pkg_name" "../$pkg_name" 2>/dev/null || true; \
+ fi; \
+ done; \
+ fi; \
+ done
+
+# Create data directory
+RUN mkdir -p /data /data/logs /data/db /data/config
+
+# Download specific versions of restic and rclone binaries and place in system PATH
+ARG TARGETARCH
+ARG RESTIC_VERSION
+ARG RCLONE_VERSION
+RUN echo "Building for architecture: ${TARGETARCH}" && \
+ echo "Installing restic v${RESTIC_VERSION} and rclone v${RCLONE_VERSION}" && \
+ # Download restic
+ if [ "${TARGETARCH}" = "amd64" ]; then \
+ wget -q "https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_linux_amd64.bz2" -O /tmp/restic.bz2; \
+ elif [ "${TARGETARCH}" = "arm64" ]; then \
+ wget -q "https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_linux_arm64.bz2" -O /tmp/restic.bz2; \
+ fi && \
+ bunzip2 /tmp/restic.bz2 && \
+ mv /tmp/restic /usr/local/bin/restic && \
+ chmod +x /usr/local/bin/restic && \
+ # Download rclone
+ if [ "${TARGETARCH}" = "amd64" ]; then \
+ wget -q "https://downloads.rclone.org/v${RCLONE_VERSION}/rclone-v${RCLONE_VERSION}-linux-amd64.zip" -O /tmp/rclone.zip; \
+ elif [ "${TARGETARCH}" = "arm64" ]; then \
+ wget -q "https://downloads.rclone.org/v${RCLONE_VERSION}/rclone-v${RCLONE_VERSION}-linux-arm64.zip" -O /tmp/rclone.zip; \
+ fi && \
+ apk add --no-cache unzip && \
+ unzip -q /tmp/rclone.zip -d /tmp && \
+ mv /tmp/rclone-*/rclone /usr/local/bin/rclone && \
+ chmod +x /usr/local/bin/rclone && \
+ rm -rf /tmp/rclone* && \
+ apk del unzip && \
+ # Verify installations (unset env vars to avoid conflicts with rclone flags)
+ unset RESTIC_VERSION RCLONE_VERSION && \
+ restic version && \
+ rclone version
+
+# Create Pluton wrapper scripts for rclone and restic
+# These ensure the tools use Pluton's configuration from /data/config
+RUN echo '#!/bin/sh' > /usr/local/bin/prclone && \
+ echo '# Pluton Wrapper for rclone' >> /usr/local/bin/prclone && \
+ echo '# This script ensures that rclone uses Pluton configuration.' >> /usr/local/bin/prclone && \
+ echo 'exec /usr/local/bin/rclone --config /data/config/rclone.conf "$@"' >> /usr/local/bin/prclone && \
+ chmod +x /usr/local/bin/prclone && \
+ echo '#!/bin/sh' > /usr/local/bin/prestic && \
+ echo '# Pluton Wrapper for restic' >> /usr/local/bin/prestic && \
+ echo '# This script ensures that restic uses Pluton rclone binary and configuration.' >> /usr/local/bin/prestic && \
+ echo 'export RCLONE_CONFIG=/data/config/rclone.conf' >> /usr/local/bin/prestic && \
+ echo 'exec /usr/local/bin/restic -o rclone.program=/usr/local/bin/rclone "$@"' >> /usr/local/bin/prestic && \
+ chmod +x /usr/local/bin/prestic
+
+# Set environment variables
+ARG APP_VERSION
+ENV NODE_ENV=production \
+ IS_DOCKER=true \
+ SERVER_PORT=5173 \
+ APP_VERSION=${APP_VERSION}
+
+# Expose the application port
+EXPOSE 5173
+
+# Start the application with custom loader for extension-less imports
+CMD ["node", "--loader", "./loader.mjs", "dist/index.js"]
\ No newline at end of file
diff --git a/backend/src/utils/binaryPathResolver.ts b/backend/src/utils/binaryPathResolver.ts
index 1ea5e29..a6a865e 100644
--- a/backend/src/utils/binaryPathResolver.ts
+++ b/backend/src/utils/binaryPathResolver.ts
@@ -27,10 +27,6 @@ export function getBinaryPath(binaryName: 'restic' | 'rclone' | 'rear'): string
if (fs.existsSync(appImageBinaryPath)) {
return appImageBinaryPath;
}
-
- console.warn(
- `[binaryPathResolver] Expected binary at '${appImageBinaryPath}' (AppImage) but not found. Trying fallbacks...`
- );
}
// Priority 2: Check if running as a pkg-packaged executable
@@ -41,10 +37,6 @@ export function getBinaryPath(binaryName: 'restic' | 'rclone' | 'rear'): string
if (fs.existsSync(pkgBinaryPath)) {
return pkgBinaryPath;
}
-
- console.warn(
- `[binaryPathResolver] Expected binary at '${pkgBinaryPath}' but not found. Trying fallbacks...`
- );
}
// Priority 3: Production/installed binary next to executable
@@ -62,6 +54,15 @@ export function getBinaryPath(binaryName: 'restic' | 'rclone' | 'rear'): string
return devPath;
}
+ // Priority 5: Docker/Linux standard binary locations
+ const standardPaths = ['/usr/local/bin', '/usr/bin', '/bin'];
+ for (const standardPath of standardPaths) {
+ const standardBinaryPath = path.join(standardPath, fileName);
+ if (fs.existsSync(standardBinaryPath)) {
+ return standardBinaryPath;
+ }
+ }
+
// Final fallback to system PATH (shouldn't be needed in production)
// This allows development even without the binaries folder being populated
console.warn(
diff --git a/backend/src/utils/rclone/rclone.ts b/backend/src/utils/rclone/rclone.ts
index 487db6a..4099844 100644
--- a/backend/src/utils/rclone/rclone.ts
+++ b/backend/src/utils/rclone/rclone.ts
@@ -10,13 +10,13 @@ export function runRcloneCommand(args: string[], env?: Record<string, string>):
const rcloneConfigPath = getRcloneConfigPath();
const localAppData = process.env.LOCALAPPDATA || os.homedir();
const envVars = {
- // ...process.env,
+ PATH: process.env.PATH, // Needed for docker instances
RCLONE_CONFIG: rcloneConfigPath,
LOCALAPPDATA: localAppData,
RCLONE_CONFIG_PASS: configService.config.ENCRYPTION_KEY,
...env,
};
- console.log('rcloneBinary :', rcloneBinary);
+ // console.log('rcloneBinary :', rcloneBinary);
const rcProcess = spawn(rcloneBinary, args, { env: envVars });
let output = '';
let errorOutput = '';