genything / Dockerfile
burtenshaw
run on 7860
ad317fa
# Use an official Node.js runtime as a parent image
# Using LTS (Long Term Support) version is generally recommended
FROM node:20-alpine AS base
# Set the working directory in the container
WORKDIR /app
# Install dependencies stage
FROM base AS deps
# Copy package.json and package-lock.json (or yarn.lock or pnpm-lock.yaml)
COPY package.json package-lock.json* ./
# Install dependencies
RUN npm ci
# Build stage
FROM base AS builder
# Copy dependencies from the 'deps' stage
COPY --from=deps /app/node_modules ./node_modules
# Copy the rest of the application code
COPY . .
# Build the SvelteKit application, mounting the secret and reading it with cat
# The secret 'HF_TOKEN' must be defined in the Hugging Face Space settings
RUN --mount=type=secret,id=HF_TOKEN \
HF_TOKEN=$(cat /run/secrets/HF_TOKEN) npm run build
# Production stage
FROM base AS production
ENV NODE_ENV=production
# Set the default port for the SvelteKit Node adapter
ENV PORT=7860
# Copy built application output from the 'builder' stage
# The output directory is typically 'build' when using adapter-node
COPY --from=builder /app/build ./build
# Copy production dependencies from the 'deps' stage
COPY --from=deps /app/node_modules ./node_modules
# Copy package.json to run the server
COPY package.json .
# Expose the port the app runs on
# SvelteKit with adapter-node typically defaults to 3000, but can be overridden by PORT env var
EXPOSE 7860
# Set the command to run the application
# This starts the Node.js server built by adapter-node
CMD ["node", "build/index.js"]