Skip to content
Merged
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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ dist

kube.yml

docker-compose-dev.yaml

example-fragment.js
23 changes: 23 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Development image for ByteStash
FROM node:22-alpine AS base


FROM base AS client
# Install the dependencies from client
WORKDIR /client
COPY client/package.json ./
RUN npm install
EXPOSE 3000
CMD ["npm", "run", "start", "--", "--host"]


FROM base AS server
# Install the dependencies from server
WORKDIR /server
COPY server/package.json ./
RUN apk add --no-cache --virtual .build-deps python3 make g++ gcc
RUN npm install
# Create directory for snippets
RUN mkdir -p /data/snippets
EXPOSE 5000
CMD ["npx", "nodemon", "--watch", "src", "src/app.js"]
2 changes: 1 addition & 1 deletion client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default defineConfig({
allowedHosts: allowedHosts,
proxy: {
'/api': {
target: 'http://localhost:5000',
target: process.env.BACKEND_API_TARGET || 'http://localhost:5000',
changeOrigin: true,
},
},
Expand Down
70 changes: 70 additions & 0 deletions docker-compose-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
services:
client:
build:
context: .
target: client
dockerfile: Dockerfile.dev
ports:
- "3000:3000"
environment:
# Backend API taget: Points to the ExpressJS container running the REST APIs
- BACKEND_API_TARGET=http://server:5000
volumes:
- "./client:/client"
- "/client/node_modules"
server:
build:
context: .
target: server
dockerfile: Dockerfile.dev
ports:
- "5000:5000"
environment:
# e.g. write /bytestash for a domain such as my.domain/bytestash, leave blank in every other case
- BASE_PATH=
# optionally include additional allowed hosts for reverse proxies
# e.g. localhost,my.domain.com,my.domain.net
- ALLOWED_HOSTS=
# Either provide JWT_SECRET directly or use JWT_SECRET_FILE for Docker secrets
#- JWT_SECRET_FILE=/run/secrets/jwt
- JWT_SECRET=your-secret
# how long the token lasts, examples: "2 days", "10h", "7d", "1m", "60s"
- TOKEN_EXPIRY=24h
# is this bytestash instance open to new accounts being created?
- ALLOW_NEW_ACCOUNTS=true
# Should debug mode be enabled? Essentially enables logging, in most cases leave this as false
- DEBUG=false
# Should we use accounts at all? When enabled, it will be like starting a fresh account so export your snippets, no login required
- DISABLE_ACCOUNTS=false
# Should internal accounts be disabled?
- DISABLE_INTERNAL_ACCOUNTS=false
# Allow password changes (false by default)
- ALLOW_PASSWORD_CHANGES=true

# Optional: Enable OIDC for Single Sign On
- OIDC_ENABLED=true
# Optional: Display name for users signing in with SSO, will default to Single Sign-on
- OIDC_DISPLAY_NAME=
# Your OIDC issuer url, e.g. https://authentik.mydomain.com/application/o/bytestash/ for authentik
- OIDC_ISSUER_URL=
# Your OIDC client ID, you can find it in your app provider
- OIDC_CLIENT_ID=
# Your OIDC client secret, again, found in the app provider
- OIDC_CLIENT_SECRET=
# The OIDC scopes to request, e.g. "openid profile email groups"
- OIDC_SCOPES=
# Optional: Comma-separated list of usernames that should have admin privileges
# e.g. "admin,jordan" - these users will have access to the admin panel
- ADMIN_USERNAMES=admin
volumes:
- "./server:/server"
- "/server/node_modules"
- ./data:/data/snippets

# Uncomment to use docker secrets
# secrets:
# - jwt

#secrets:
# jwt:
# file: ./secrets/jwt.txt
165 changes: 165 additions & 0 deletions start-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#!/usr/bin/env bash
set -euo pipefail

# ──────────────────────────────────────────────
# ByteStash Dev Environment Setup & Launch
# ──────────────────────────────────────────────

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

info() { echo -e "${GREEN}[INFO]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }

# ──────────────────────────────────────────────
# 1. OS Detection
# ──────────────────────────────────────────────
detect_os() {
case "$(uname -s)" in
Linux*) OS="linux" ;;
Darwin*) OS="macos" ;;
CYGWIN*|MINGW*|MSYS*)
error "Windows is not supported. Please use WSL (Windows Subsystem for Linux)." ;;
*)
error "Unsupported operating system: $(uname -s)" ;;
esac
info "Detected OS: $OS"
}

# ──────────────────────────────────────────────
# 2. Docker Check
# ──────────────────────────────────────────────
check_docker() {
if ! command -v docker &>/dev/null; then
error "Docker is not installed. Please install Docker first: https://docs.docker.com/get-docker/"
fi

if ! docker info &>/dev/null; then
error "Docker daemon is not running. Please start Docker and try again."
fi

info "Docker is installed and running."
}

# ──────────────────────────────────────────────
# 3. NVM + Node Check
# ──────────────────────────────────────────────
check_nvm_and_node() {
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"

if [[ -s "$NVM_DIR/nvm.sh" ]]; then
source "$NVM_DIR/nvm.sh"
fi

if ! command -v nvm &>/dev/null; then
error "nvm is not installed. Install it from: https://github.com/nvm-sh/nvm#installing-and-updating"
fi

info "nvm is installed."

if ! node --version &>/dev/null; then
warn "No active Node.js version found. Installing Node 22 via nvm..."
nvm install 22
fi

NODE_MAJOR=$(node --version | sed 's/v\([0-9]*\).*/\1/')
if [[ "$NODE_MAJOR" -ne 22 ]]; then
warn "Node.js $(node --version) detected. Switching to Node 22 to match the dev container..."
nvm install 22
nvm use 22
fi

info "Node.js $(node --version) is active."
}

# ──────────────────────────────────────────────
# 4. Build Dependencies Check (native modules)
# ──────────────────────────────────────────────
check_build_deps() {
local missing=()

for cmd in python3 make gcc g++; do
if ! command -v "$cmd" &>/dev/null; then
missing+=("$cmd")
fi
done

if [[ ${#missing[@]} -gt 0 ]]; then
warn "Missing build dependencies: ${missing[*]}"
echo ""
if [[ "$OS" == "macos" ]]; then
echo " Install Xcode CLI tools: xcode-select --install"
echo " Install Python 3: brew install python3"
elif [[ "$OS" == "linux" ]]; then
echo " Debian/Ubuntu: sudo apt install build-essential python3"
echo " Fedora/RHEL: sudo dnf install gcc gcc-c++ make python3"
echo " Arch: sudo pacman -S base-devel python"
fi
echo ""
error "Please install the missing dependencies and re-run this script."
fi

info "Build dependencies are available."
}

# ──────────────────────────────────────────────
# 5. Docker Compose Variant Detection
# ──────────────────────────────────────────────
detect_compose() {
if docker compose version &>/dev/null; then
COMPOSE="docker compose"
elif command -v docker-compose &>/dev/null; then
COMPOSE="docker-compose"
else
error "Neither 'docker compose' nor 'docker-compose' is available. Please install Docker Compose."
fi

info "Using compose command: $COMPOSE"
}

# ──────────────────────────────────────────────
# 6. Install Dependencies & Launch
# ──────────────────────────────────────────────
install_and_launch() {
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"

if [[ ! -f "docker-compose-dev.yaml" ]]; then
error "docker-compose-dev.yaml not found. Run this script from the ByteStash project root."
fi

info "Installing client dependencies..."
npm install --prefix client

info "Installing server dependencies..."
npm install --prefix server

info "Cleaning old containers and volumes..."
$COMPOSE -f docker-compose-dev.yaml down -v

info "Starting dev containers..."
$COMPOSE -f docker-compose-dev.yaml up --build
}

# ──────────────────────────────────────────────
# Main
# ──────────────────────────────────────────────
main() {
echo ""
echo "========================================="
echo " ByteStash Dev Environment Setup"
echo "========================================="
echo ""

detect_os
check_docker
check_nvm_and_node
check_build_deps
detect_compose
install_and_launch
}

main
Loading