fix: de-docker dev
This commit is contained in:
@@ -6,12 +6,10 @@
|
|||||||
|
|
||||||
# Docker files should not be in the build context
|
# Docker files should not be in the build context
|
||||||
Dockerfile
|
Dockerfile
|
||||||
docker-compose.yml
|
|
||||||
docker-compose.dev.yml
|
|
||||||
|
|
||||||
# Node.js dependencies are installed inside the container
|
# Node.js dependencies are installed inside the container
|
||||||
node_modules
|
node_modules
|
||||||
npm-debug.log
|
npm-debug.log*
|
||||||
|
|
||||||
# Build output is generated inside the container
|
# Build output is generated inside the container
|
||||||
_site
|
_site
|
||||||
|
20
.vscode/launch.json
vendored
20
.vscode/launch.json
vendored
@@ -2,16 +2,20 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Docker: Attach to Node",
|
"name": "Debug Eleventy",
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "attach",
|
"request": "launch",
|
||||||
|
"runtimeExecutable": "npm",
|
||||||
|
"runtimeArgs": [
|
||||||
|
"start"
|
||||||
|
],
|
||||||
"port": 9229,
|
"port": 9229,
|
||||||
"address": "localhost",
|
"console": "integratedTerminal",
|
||||||
"localRoot": "${workspaceFolder}",
|
"serverReadyAction": {
|
||||||
"remoteRoot": "/app",
|
"pattern": "Web Server running at (http://localhost:[0-9]+)",
|
||||||
"restart": false,
|
"uriFormat": "%s",
|
||||||
"preLaunchTask": "docker-compose-up",
|
"action": "openExternally"
|
||||||
"postDebugTask": "docker-compose-down"
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
28
.vscode/tasks.json
vendored
28
.vscode/tasks.json
vendored
@@ -1,34 +1,6 @@
|
|||||||
{
|
{
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
|
||||||
"label": "docker-compose-up",
|
|
||||||
"type": "shell",
|
|
||||||
"command": "docker compose up --build",
|
|
||||||
"isBackground": true,
|
|
||||||
"problemMatcher": [
|
|
||||||
{
|
|
||||||
"pattern": [
|
|
||||||
{
|
|
||||||
"regexp": ".",
|
|
||||||
"file": 1,
|
|
||||||
"location": 2,
|
|
||||||
"message": 3
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"background": {
|
|
||||||
"activeOnStart": true,
|
|
||||||
"beginsPattern": "Attaching to",
|
|
||||||
"endsPattern": "Debugger listening on"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "docker-compose-down",
|
|
||||||
"type": "shell",
|
|
||||||
"command": "docker compose down --volumes"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"label": "Docker: Build and Push Production Image",
|
"label": "Docker: Build and Push Production Image",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
|
21
Dockerfile
21
Dockerfile
@@ -18,17 +18,7 @@ COPY package*.json ./
|
|||||||
# Use `npm ci` for faster, more reliable builds from package-lock.json
|
# Use `npm ci` for faster, more reliable builds from package-lock.json
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
|
|
||||||
# STAGE 2: Development
|
# STAGE 2: Builder
|
||||||
# This stage is for local development. It includes devDependencies and source code.
|
|
||||||
# In docker-compose.dev.yml, the source is mounted for hot-reloading.
|
|
||||||
FROM deps AS development
|
|
||||||
|
|
||||||
# The source code is mounted via docker-compose for development,
|
|
||||||
# so we don't need to COPY it into the image. This keeps the dev image small.
|
|
||||||
# We only need the WORKDIR and the installed node_modules from the 'deps' stage.
|
|
||||||
CMD ["npm", "start"]
|
|
||||||
|
|
||||||
# STAGE 3: Builder
|
|
||||||
# This stage builds the Eleventy site for production.
|
# This stage builds the Eleventy site for production.
|
||||||
FROM deps AS builder
|
FROM deps AS builder
|
||||||
COPY . .
|
COPY . .
|
||||||
@@ -37,7 +27,7 @@ RUN npm run build
|
|||||||
# After building, remove development dependencies to keep the final image small.
|
# After building, remove development dependencies to keep the final image small.
|
||||||
RUN npm prune --omit=dev
|
RUN npm prune --omit=dev
|
||||||
|
|
||||||
# STAGE 4: Production
|
# STAGE 3: Production
|
||||||
# This stage creates a lean, production-ready image.
|
# This stage creates a lean, production-ready image.
|
||||||
FROM node:18-alpine AS production
|
FROM node:18-alpine AS production
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@@ -53,8 +43,11 @@ COPY --from=builder --chown=node:node /app/node_modules ./node_modules
|
|||||||
COPY --from=builder --chown=node:node /app/package.json ./package.json
|
COPY --from=builder --chown=node:node /app/package.json ./package.json
|
||||||
COPY --from=builder --chown=node:node /app/server.js .
|
COPY --from=builder --chown=node:node /app/server.js .
|
||||||
COPY --from=builder --chown=node:node /app/_site ./_site
|
COPY --from=builder --chown=node:node /app/_site ./_site
|
||||||
# The _data directory is handled by the volume, but we copy it so the volume can be pre-populated on first run.
|
|
||||||
COPY --from=builder --chown=node:node /app/src/_data/ ./_data/
|
# Copy the data directory. The server writes view counts here.
|
||||||
|
# This directory should be mounted as a volume
|
||||||
|
# to persist the view count data across container restarts.
|
||||||
|
COPY --from=builder --chown=node:node /app/src/_data ./_data
|
||||||
COPY --chown=node:node healthcheck.js .
|
COPY --chown=node:node healthcheck.js .
|
||||||
|
|
||||||
# Copy and set up the entrypoint script
|
# Copy and set up the entrypoint script
|
||||||
|
@@ -1,60 +0,0 @@
|
|||||||
# docker-compose.dev.yml for development
|
|
||||||
# This setup runs two services:
|
|
||||||
# 1. The Eleventy dev server for live-reloading site changes.
|
|
||||||
# 2. The Express API server for the view counter.
|
|
||||||
#
|
|
||||||
# To start both, run: docker compose -f docker-compose.dev.yml up
|
|
||||||
#
|
|
||||||
# Your site will be available at http://localhost:8080.
|
|
||||||
# API requests are proxied from /api to the API service, so you don't need to access port 3000 directly.
|
|
||||||
services:
|
|
||||||
# This service runs the Eleventy development server.
|
|
||||||
eleventy:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
target: development # Use the 'development' stage from the Dockerfile
|
|
||||||
# Adding `init: true` ensures that the container's main process receives
|
|
||||||
# signals correctly (like SIGINT/SIGTERM) when you stop the container.
|
|
||||||
# This helps the dev server to shut down gracefully.
|
|
||||||
init: true
|
|
||||||
container_name: eleventy_dev
|
|
||||||
ports:
|
|
||||||
- "9229:9229" # Node.js debugger port
|
|
||||||
- "8080:8080" # Eleventy dev server port
|
|
||||||
volumes:
|
|
||||||
# Mount the project directory for live-reloading.
|
|
||||||
# The anonymous volume for node_modules prevents the local one from overwriting the container's.
|
|
||||||
- .:/app
|
|
||||||
- /app/node_modules
|
|
||||||
networks:
|
|
||||||
# Both services need to be on the same network for the Eleventy dev server
|
|
||||||
# to proxy requests to the API container using its service name ('api').
|
|
||||||
- dev_network
|
|
||||||
# This command runs Eleventy's dev server with file watching.
|
|
||||||
command: npm run debug
|
|
||||||
|
|
||||||
# This service runs your Express API server.
|
|
||||||
api:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
target: development # Use the same 'development' stage
|
|
||||||
# Adding `init: true` is especially important for debugging. It ensures
|
|
||||||
# the Node.js process receives shutdown signals, allowing the debugger
|
|
||||||
# to detach cleanly.
|
|
||||||
init: true
|
|
||||||
container_name: api_dev
|
|
||||||
# The API port does not need to be exposed to the host. The 'eleventy'
|
|
||||||
# service proxies requests to it over the internal Docker network.
|
|
||||||
volumes:
|
|
||||||
- .:/app
|
|
||||||
- /app/node_modules
|
|
||||||
networks:
|
|
||||||
- dev_network
|
|
||||||
# Use Node's built-in --watch mode instead of nodemon. It can be more
|
|
||||||
# stable inside Docker and avoids some of nodemon's complexities. The
|
|
||||||
# --inspect flag is attached to the 'eleventy' service for debugging.
|
|
||||||
command: node --watch server.js
|
|
||||||
|
|
||||||
networks:
|
|
||||||
dev_network:
|
|
||||||
driver: bridge
|
|
Reference in New Issue
Block a user