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
74 changes: 74 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# ==========================================
# STAGE 1: The Builder (Heavy, used only for compiling)
# ==========================================
FROM node:20 AS builder

RUN corepack enable
WORKDIR /app

# Install git
RUN apt-get update && \
apt-get install -y --no-install-recommends git && \
rm -rf /var/lib/apt/lists/*

# Git Clone branch and repository
RUN git clone https://github.com/mifi/ezshare.git .

# Copy the source code (enable this if using for development mode - you'll need to have local copy of the code)
#COPY ezshare/ ./

# Install ALL dependencies (including dev tools like TypeScript) and build
RUN yarn install --immutable
RUN yarn build

# ==========================================
# STAGE 2: The Runner (Lightweight, final production image)
# ==========================================
# We use node:20-slim here, which is hundreds of MBs smaller!
FROM node:20-slim AS runner

# Install ffmpeg, xsel, xvfb and immediately clean up the apt cache to save space
RUN apt-get update && \
apt-get install --no-install-recommends -y xvfb ffmpeg xsel dbus && \
rm -rf /var/lib/apt/lists/*

RUN corepack enable
WORKDIR /app

# Copy ONLY the necessary files from the "builder" stage
COPY --from=builder /app/package.json ./
COPY --from=builder /app/yarn.lock ./
COPY --from=builder /app/.yarnrc.yml ./
COPY --from=builder /app/.yarn ./.yarn

# Copy the packages folder (which now contains the built "dist" folders)
COPY --from=builder /app/packages ./packages

# Optional but recommended: Remove the heavy "src" folders since we only need "dist" now
RUN rm -rf packages/*/src

# Install ONLY production dependencies (ignores devDependencies) and clean Yarn cache
RUN yarn workspaces focus --production $(node -p "require('./packages/cli/package.json').name") && yarn cache clean --all

#To have fake display
RUN echo '#!/bin/bash\n\
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &\n\
export DISPLAY=:99\n\
sleep 1\n\
exec dbus-run-session -- "$@"' > /app/entrypoint.sh && chmod +x /app/entrypoint.sh

# Create the shared directory
RUN mkdir /shared

# --- SECURITY CHANGES START ---
# 1. Change ownership of /app and /shared to the 'node' user (UID 1000)
# This ensures the user can write to these locations.
RUN chown -R node:node /app /shared

# 2. Switch to non-root user
USER node
# --- SECURITY CHANGES END ---

# Expose port and start
EXPOSE 3003
CMD ["/app/entrypoint.sh", "node", "packages/cli/dist/index.js", "/shared", "--port", "3003"]
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,59 @@ A simple **file server** that lets you easily share many big files like photos a
npm install -g @ezshare/cli
```

## 🐳 Docker Deployment

You can run `ezshare` easily using Docker. This ensures all dependencies like `ffmpeg` and `xvfb` are pre-installed and configured correctly.

### Prerequisites
* [Docker Desktop](https://www.docker.com/products/docker-desktop/) or Docker Engine installed.

### Option 1: Using Docker Compose (Recommended)
The easiest way to run the application is with Docker Compose. This handles the build, port mapping, and volume creation automatically.

1. **Start the application:**
```bash
docker compose up --build
```

2. **Access the app:**
Open your browser to `http://localhost:3003`.

3. **Shared Files:**
Place files in the `./my-shared-data` folder (created automatically in your project root). These will appear in the application under `/shared`.

### Option 2: Manual Docker CLI
If you prefer to run the `Dockerfile` manually without Compose:

1. **Build the image:**
```bash
docker build -t ezshare .
```

2. **Run the container:**
You must map port `3003` and mount a volume to `/shared` for the application to function properly.
```bash
docker run -p 3003:3003 -v $(pwd)/my-shared-data:/shared ezshare
```

### Configuration Details
* **Port:** The application listens on port `3003` by default.
* **Data Volume:** The application expects a volume mounted at `/shared` to store and retrieve files.
* **Environment:** The container uses `node:20-slim` and includes necessary runtime tools like `ffmpeg` for media processing.

### Volume Permissions (Important)

Since the container now runs as UID 1000 (`node`), the host directory mounted to `/shared` (defined in `docker-compose.yml` as `./my-shared-data`) must be writable by UID 1000.

If you encounter `Permission Denied` errors on Linux/Mac, run the following on the host machine to fix local folder permissions:

```bash
mkdir -p ./my-shared-data
chown -R 1000:1000 ./my-shared-data
```



## Install (standalone)

If you don't want to install Node.js, you can download Electron based executable of `ezshare` from Releases.
Expand Down
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
ezshare:
build:
context: .
dockerfile: Dockerfile
container_name: ezshare-app
restart: unless-stopped

# Map port 3003 on host to 3003 in container
ports:
- "3003:3003"

# Mount a local directory to /shared
volumes:
- ./my-shared/path:/shared

# (Optional) Ensure the container uses the node user explicitly
# though the Dockerfile USER instruction already handles this.
user: "node"