mirror of
https://github.com/R0m1k3/podcastic.git
synced 2026-10-19 21:18:03 +02:00
fix: add proper Dockerfiles for backend and frontend, simplify docker-compose
This commit is contained in:
1 parent
547de27eed
commit
a8787857b5
3 files changed
+26
-83
No files matched your search
+4
-36
@@ -1,47 +1,15 @@
|
||||
# Build stage
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package*.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci
|
||||
|
||||
# Copy source code
|
||||
COPY tsconfig.json ./
|
||||
COPY src ./src
|
||||
|
||||
# Build TypeScript
|
||||
RUN npm run build
|
||||
|
||||
# Production stage
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install dumb-init for proper signal handling
|
||||
RUN apk add --no-cache dumb-init
|
||||
|
||||
# Copy package files
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
|
||||
# Install production dependencies only
|
||||
RUN npm ci --only=production
|
||||
COPY tsconfig.json ./
|
||||
COPY src ./src
|
||||
|
||||
# Copy built app from builder
|
||||
COPY --from=builder /app/dist ./dist
|
||||
RUN npm run build
|
||||
|
||||
# Expose port
|
||||
EXPOSE 5000
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
||||
CMD node -e "require('http').get('http://localhost:5000/health', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})"
|
||||
|
||||
# Use dumb-init to handle signals properly
|
||||
ENTRYPOINT ["dumb-init", "--"]
|
||||
|
||||
# Start application
|
||||
CMD ["node", "dist/index.js"]
|
||||
+6
-16
@@ -5,8 +5,6 @@ services:
|
||||
image: mongo:latest
|
||||
container_name: podcastic-mongodb
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "27017:27017"
|
||||
volumes:
|
||||
- mongodb_data:/data/db
|
||||
networks:
|
||||
@@ -16,18 +14,17 @@ services:
|
||||
image: redis:7-alpine
|
||||
container_name: podcastic-redis
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "6379:6379"
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
networks:
|
||||
- podcastic
|
||||
|
||||
backend:
|
||||
image: node:20-alpine
|
||||
build:
|
||||
context: ./backend
|
||||
dockerfile: Dockerfile
|
||||
container_name: podcastic-backend
|
||||
restart: unless-stopped
|
||||
working_dir: /app
|
||||
ports:
|
||||
- "5000:5000"
|
||||
environment:
|
||||
@@ -39,9 +36,6 @@ services:
|
||||
JWT_REFRESH_EXPIRES_IN: 30d
|
||||
PODCAST_INDEX_API_KEY: ${PODCAST_INDEX_API_KEY:-}
|
||||
PODCAST_INDEX_API_SECRET: ${PODCAST_INDEX_API_SECRET:-}
|
||||
volumes:
|
||||
- ./backend:/app
|
||||
command: sh -c "npm install && npm run build && node dist/index.js"
|
||||
depends_on:
|
||||
- mongodb
|
||||
- redis
|
||||
@@ -49,17 +43,13 @@ services:
|
||||
- podcastic
|
||||
|
||||
frontend:
|
||||
image: node:20-alpine
|
||||
build:
|
||||
context: ./frontend
|
||||
dockerfile: Dockerfile
|
||||
container_name: podcastic-frontend
|
||||
restart: unless-stopped
|
||||
working_dir: /app
|
||||
ports:
|
||||
- "3579:3579"
|
||||
environment:
|
||||
VITE_API_URL: http://localhost:5000/api
|
||||
volumes:
|
||||
- ./frontend:/app
|
||||
command: sh -c "npm install && npm run build && npm install -g serve && serve -s dist -l 3579"
|
||||
depends_on:
|
||||
- backend
|
||||
networks:
|
||||
|
||||
+16
-31
@@ -1,49 +1,34 @@
|
||||
# Build stage
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package*.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build the app
|
||||
RUN npm run build
|
||||
|
||||
# Production stage - use nginx for serving
|
||||
FROM nginx:alpine
|
||||
|
||||
# Copy nginx config
|
||||
RUN echo 'server {\n\
|
||||
listen 3000;\n\
|
||||
server_name _;\n\
|
||||
root /usr/share/nginx/html;\n\
|
||||
index index.html;\n\
|
||||
\n\
|
||||
location / {\n\
|
||||
try_files $uri $uri/ /index.html;\n\
|
||||
}\n\
|
||||
\n\
|
||||
location ~* \\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {\n\
|
||||
expires 1y;\n\
|
||||
add_header Cache-Control "public, immutable";\n\
|
||||
}\n\
|
||||
}' > /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Copy built app from builder
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
|
||||
# Expose port
|
||||
EXPOSE 3000
|
||||
COPY <<'EOF' /etc/nginx/conf.d/default.conf
|
||||
server {
|
||||
listen 3579;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
||||
CMD wget --quiet --tries=1 --spider http://localhost:3000/ || exit 1
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /api {
|
||||
proxy_pass http://backend:5000;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
EXPOSE 3579
|
||||
|
||||
# Start nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
Reference in new issue
Block a user