From a48a06e680b5ec64e9bce8f999fb603de09c4e43 Mon Sep 17 00:00:00 2001 From: Kaloyan Danchev Date: Fri, 6 Feb 2026 09:48:30 +0200 Subject: [PATCH] Add Docker deployment for Unraid - Add Dockerfile.unraid with multi-stage build (builds inside container) - Add docker-compose.unraid.yml for easy deployment - Add build-and-push.sh script for building and pushing to Gitea registry - Update root redirect to /unraid dashboard Co-Authored-By: Claude Opus 4.5 --- Dockerfile.unraid | 105 ++++++++++++++++++++++++++++++++++++++ docker-compose.unraid.yml | 34 ++++++++++++ next.config.js | 2 +- scripts/build-and-push.sh | 45 ++++++++++++++++ 4 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 Dockerfile.unraid create mode 100644 docker-compose.unraid.yml create mode 100755 scripts/build-and-push.sh diff --git a/Dockerfile.unraid b/Dockerfile.unraid new file mode 100644 index 000000000..647fedc92 --- /dev/null +++ b/Dockerfile.unraid @@ -0,0 +1,105 @@ +# Multi-stage Dockerfile for Homarr Unraid UI +# Builds entirely inside Docker to avoid native module issues + +# Build stage +FROM node:20.2.0-slim AS builder + +WORKDIR /app + +# Install build dependencies +RUN apt-get update && apt-get install -y \ + python3 \ + make \ + g++ \ + git \ + openssl \ + && rm -rf /var/lib/apt/lists/* + +# Copy package files +COPY package.json yarn.lock ./ +COPY .yarnrc.yml ./ +COPY .yarn ./.yarn + +# Install dependencies +RUN yarn install --immutable + +# Copy source code +COPY . . + +# Build the application +ENV SKIP_ENV_VALIDATION=1 +ENV NEXTAUTH_SECRET=build-time-secret +ENV DATABASE_URL=file:build.sqlite +RUN yarn build + +# Production stage +FROM node:20.2.0-slim + +WORKDIR /app + +# Define node.js environment variables +ARG PORT=7575 + +ENV NEXT_TELEMETRY_DISABLED=1 +ENV NODE_ENV=production +ENV NODE_OPTIONS='--no-experimental-fetch' + +# Copy built application from builder +COPY --from=builder /app/next.config.js ./ +COPY --from=builder /app/public ./public +COPY --from=builder /app/package.json ./temp_package.json +COPY --from=builder /app/yarn.lock ./temp_yarn.lock +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static +COPY --from=builder /app/scripts/run.sh ./scripts/run.sh +COPY --from=builder /app/drizzle ./drizzle +COPY --from=builder /app/drizzle/migrate ./migrate +COPY --from=builder /app/tsconfig.json ./migrate/tsconfig.json +COPY --from=builder /app/cli ./cli + +RUN chmod +x ./scripts/run.sh +RUN mkdir -p /data + +# Install runtime dependencies +RUN apt-get update && apt-get install -y openssl wget && rm -rf /var/lib/apt/lists/* + +# Move node_modules to temp location to avoid overwriting +RUN mv node_modules _node_modules +RUN rm package.json + +# Install dependencies for migration +RUN cp ./migrate/package.json ./package.json +RUN yarn install --production=false + +# Copy better_sqlite3 build for current platform +RUN cp /app/node_modules/better-sqlite3/build/Release/better_sqlite3.node /app/_node_modules/better-sqlite3/build/Release/better_sqlite3.node || true + +# Copy node_modules for migration to migrate folder +RUN mv node_modules ./migrate/node_modules + +# Restore app node_modules +RUN mv _node_modules node_modules + +# Setup CLI +RUN echo '#!/bin/bash\nnode /app/cli/cli.js "$@"' > /usr/bin/homarr +RUN chmod +x /usr/bin/homarr +RUN cd /app/cli && yarn install --production || true + +# Expose the default application port +EXPOSE $PORT +ENV PORT=${PORT} + +# Environment defaults +ENV DATABASE_URL="file:/data/db.sqlite" +ENV AUTH_TRUST_HOST="true" +ENV PORT=7575 +ENV NEXTAUTH_SECRET=NOT_IN_USE_BECAUSE_JWTS_ARE_UNUSED + +# Health check +HEALTHCHECK --interval=10s --timeout=5s --start-period=5s --retries=3 \ + CMD wget --no-verbose --tries=1 --spider http://localhost:${PORT} || exit 1 + +VOLUME [ "/app/data/configs" ] +VOLUME [ "/data" ] + +ENTRYPOINT ["sh", "./scripts/run.sh"] diff --git a/docker-compose.unraid.yml b/docker-compose.unraid.yml new file mode 100644 index 000000000..b4ea4b89b --- /dev/null +++ b/docker-compose.unraid.yml @@ -0,0 +1,34 @@ +version: "3.8" + +services: + homarr-unraid: + image: git.xtrm-lab.org/jazzymc/homarr:latest + container_name: homarr-unraid-ui + restart: unless-stopped + ports: + - "7576:7575" + environment: + # Unraid API Configuration + - UNRAID_HOST=192.168.10.20 + - UNRAID_API_KEY=${UNRAID_API_KEY} + - UNRAID_USE_SSL=false + - UNRAID_PORT=80 + # App Configuration + - TZ=Europe/Sofia + - DATABASE_URL=file:/data/db.sqlite + - AUTH_TRUST_HOST=true + - NEXTAUTH_URL=http://192.168.10.20:7576 + - NEXTAUTH_SECRET=${NEXTAUTH_SECRET:-changeme} + volumes: + - /mnt/user/appdata/homarr-unraid/data:/data + - /mnt/user/appdata/homarr-unraid/configs:/app/data/configs + networks: + - unraid-net + labels: + - "net.unraid.docker.managed=true" + - "net.unraid.docker.icon=https://homarr.dev/img/logo.png" + - "net.unraid.docker.webui=http://[IP]:[PORT:7576]" + +networks: + unraid-net: + driver: bridge diff --git a/next.config.js b/next.config.js index 191310ecf..e4671c700 100644 --- a/next.config.js +++ b/next.config.js @@ -21,7 +21,7 @@ module.exports = withBundleAnalyzer({ redirects: async () => [ { source: '/', - destination: '/board', + destination: '/unraid', permanent: false, }, ], diff --git a/scripts/build-and-push.sh b/scripts/build-and-push.sh new file mode 100755 index 000000000..20922a0c1 --- /dev/null +++ b/scripts/build-and-push.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# Build and push Homarr Unraid UI to Gitea registry +# Uses multi-stage Dockerfile to build inside Docker + +set -e + +REGISTRY="git.xtrm-lab.org" +IMAGE_NAME="jazzymc/homarr" +TAG="${1:-latest}" + +echo "=== Building Homarr Unraid UI ===" +echo "Using multi-stage Docker build (no local dependencies required)" +echo "" + +# Build Docker image using the multi-stage Dockerfile +echo "Building Docker image (this may take 5-10 minutes)..." +docker build -f Dockerfile.unraid -t "${REGISTRY}/${IMAGE_NAME}:${TAG}" . + +# Login to Gitea registry (if not already logged in) +echo "" +echo "Logging into Gitea registry..." +docker login "${REGISTRY}" || echo "Already logged in or use: docker login ${REGISTRY}" + +# Push to registry +echo "" +echo "Pushing to registry..." +docker push "${REGISTRY}/${IMAGE_NAME}:${TAG}" + +echo "" +echo "=== Build Complete ===" +echo "Image: ${REGISTRY}/${IMAGE_NAME}:${TAG}" +echo "" +echo "To deploy on Unraid:" +echo "1. SSH to Unraid: ssh root@192.168.10.20 -p 422" +echo "2. Create directory: mkdir -p /mnt/user/appdata/homarr-unraid/{data,configs}" +echo "3. Pull image: docker pull ${REGISTRY}/${IMAGE_NAME}:${TAG}" +echo "4. Run container:" +echo " docker run -d \\" +echo " --name homarr-unraid-ui \\" +echo " -p 7576:7575 \\" +echo " -e UNRAID_HOST=192.168.10.20 \\" +echo " -e UNRAID_API_KEY=YOUR_API_KEY \\" +echo " -v /mnt/user/appdata/homarr-unraid/data:/data \\" +echo " -v /mnt/user/appdata/homarr-unraid/configs:/app/data/configs \\" +echo " ${REGISTRY}/${IMAGE_NAME}:${TAG}"