fix: update Dockerfile and docker-compose for improved development setup
This commit is contained in:
27
Dockerfile
27
Dockerfile
@@ -1,5 +1,7 @@
|
||||
# STAGE 1: Build the Eleventy site
|
||||
FROM node:18-alpine AS builder
|
||||
# STAGE 1: Development
|
||||
# This stage installs all dependencies (including devDependencies) and copies the source code.
|
||||
# It's used as a base for the 'builder' stage and for the development environment via docker-compose.
|
||||
FROM node:18-alpine AS development
|
||||
WORKDIR /app
|
||||
|
||||
# Copy project files and install dependencies
|
||||
@@ -7,12 +9,15 @@ COPY package*.json ./
|
||||
RUN npm install
|
||||
COPY . .
|
||||
|
||||
# Build the Eleventy site
|
||||
# STAGE 2: Builder
|
||||
# This stage builds the Eleventy site for production.
|
||||
FROM development AS builder
|
||||
# The output will be in the default `_site` directory
|
||||
RUN npx @11ty/eleventy
|
||||
|
||||
# STAGE 2: Setup the production server
|
||||
FROM node:18-alpine
|
||||
# STAGE 3: Production
|
||||
# This stage creates a lean, production-ready image.
|
||||
FROM node:18-alpine AS production
|
||||
WORKDIR /app
|
||||
|
||||
# Copy server dependencies from the builder stage
|
||||
@@ -21,13 +26,15 @@ COPY --from=builder /app/package*.json ./
|
||||
# Install only production dependencies for the server
|
||||
RUN npm install --omit=dev
|
||||
|
||||
# Copy the server file and the built Eleventy site
|
||||
COPY --from=builder /app/server.js .
|
||||
# Copy the server, the built Eleventy site, and the data file for the view counter.
|
||||
# Note: The paths here are relative to the WORKDIR inside the 'builder' stage (/app).
|
||||
COPY --from=builder /app/src/server.js .
|
||||
COPY --from=builder /app/_site ./_site
|
||||
COPY --from=builder /app/data ./data
|
||||
# The server expects the _data directory in /app/_data, and your config places it in src/_data.
|
||||
COPY --from=builder /app/src/_data ./_data
|
||||
|
||||
# Expose the port the server runs on
|
||||
EXPOSE 8080
|
||||
EXPOSE 3000
|
||||
|
||||
# The command to start the server
|
||||
CMD [ "npm", "start" ]
|
||||
CMD [ "node", "server.js" ]
|
||||
|
Reference in New Issue
Block a user