feat: added docker to the project
This commit is contained in:
parent
d8c71f5874
commit
43257b422c
4 changed files with 78 additions and 0 deletions
10
.dockerignore
Normal file
10
.dockerignore
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
node_modules
|
||||
dist
|
||||
.git
|
||||
.gitignore
|
||||
/.vscode
|
||||
/.DS_Store
|
||||
pnpm-lock.yaml
|
||||
npm-debug.log
|
||||
Dockerfile
|
||||
docker-compose.yml
|
||||
28
Dockerfile
Normal file
28
Dockerfile
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# Build stage
|
||||
FROM node:20-alpine AS builder
|
||||
WORKDIR /app
|
||||
|
||||
# Install build dependencies and pnpm (via corepack)
|
||||
RUN apk add --no-cache python3 make g++ && \
|
||||
corepack enable && corepack prepare pnpm@latest --activate
|
||||
|
||||
# Copy package manifests first for better caching
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
|
||||
# Copy the rest of the project
|
||||
COPY . .
|
||||
|
||||
# Install deps and build
|
||||
RUN pnpm install --frozen-lockfile
|
||||
RUN pnpm build
|
||||
|
||||
# Production image
|
||||
FROM nginx:stable-alpine
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
|
||||
# Add custom nginx config for SPA routing
|
||||
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
22
docker-compose.yml
Normal file
22
docker-compose.yml
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
version: '3.8'
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
image: campaign-web:latest
|
||||
ports:
|
||||
- "5173:80"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
restart: unless-stopped
|
||||
|
||||
dev:
|
||||
image: node:20
|
||||
working_dir: /app
|
||||
volumes:
|
||||
- ./:/app:cached
|
||||
- /app/node_modules
|
||||
command: sh -c "corepack enable && corepack prepare pnpm@latest --activate && pnpm install && pnpm dev --host 0.0.0.0"
|
||||
ports:
|
||||
- "5173:5173"
|
||||
environment:
|
||||
- CHOKIDAR_USEPOLLING=true
|
||||
18
docker/nginx.conf
Normal file
18
docker/nginx.conf
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# Optional: cache static assets
|
||||
location ~* \.(?:js|css|png|jpg|jpeg|gif|ico|svg)$ {
|
||||
try_files $uri =404;
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, max-age=2592000, immutable";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue