Spaces:
Running
Running
File size: 1,559 Bytes
6a75637 de75e72 6a75637 ad317fa 6a75637 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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"] |