103 lines
2.4 KiB
Docker
103 lines
2.4 KiB
Docker
# Combined build for single-container deployment
|
|
# For production, use separate frontend/backend containers via docker-compose
|
|
|
|
# Build backend
|
|
FROM golang:1.22-alpine AS backend-builder
|
|
|
|
WORKDIR /app/backend
|
|
|
|
COPY backend/go.mod backend/go.sum* ./
|
|
RUN go mod download
|
|
|
|
COPY backend/ .
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
|
|
|
|
# Build frontend
|
|
FROM node:20-alpine AS frontend-builder
|
|
|
|
WORKDIR /app/frontend
|
|
|
|
COPY frontend/package.json frontend/package-lock.json* ./
|
|
RUN npm ci || npm install
|
|
|
|
COPY frontend/ .
|
|
RUN npm run build
|
|
|
|
# Final stage with nginx to serve frontend and proxy to backend
|
|
FROM nginx:alpine
|
|
|
|
# Install supervisor to run multiple processes
|
|
RUN apk add --no-cache supervisor
|
|
|
|
# Copy backend binary
|
|
COPY --from=backend-builder /app/backend/main /app/backend/main
|
|
|
|
# Copy frontend build
|
|
COPY --from=frontend-builder /app/frontend/.next/standalone /app/frontend/
|
|
COPY --from=frontend-builder /app/frontend/.next/static /app/frontend/.next/static
|
|
COPY --from=frontend-builder /app/frontend/public /app/frontend/public
|
|
|
|
# Nginx config
|
|
RUN rm /etc/nginx/conf.d/default.conf
|
|
COPY <<'EOF' /etc/nginx/conf.d/default.conf
|
|
server {
|
|
listen 8080;
|
|
|
|
location /api {
|
|
proxy_pass http://127.0.0.1:8081;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
}
|
|
|
|
location / {
|
|
proxy_pass http://127.0.0.1:3000;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection 'upgrade';
|
|
}
|
|
}
|
|
EOF
|
|
|
|
# Supervisor config
|
|
COPY <<'EOF' /etc/supervisord.conf
|
|
[supervisord]
|
|
nodaemon=true
|
|
logfile=/dev/null
|
|
logfile_maxbytes=0
|
|
|
|
[program:backend]
|
|
command=/app/backend/main
|
|
autostart=true
|
|
autorestart=true
|
|
stdout_logfile=/dev/stdout
|
|
stdout_logfile_maxbytes=0
|
|
stderr_logfile=/dev/stderr
|
|
stderr_logfile_maxbytes=0
|
|
|
|
[program:frontend]
|
|
command=node /app/frontend/server.js
|
|
environment=PORT="3000",HOSTNAME="0.0.0.0",NODE_ENV="production"
|
|
autostart=true
|
|
autorestart=true
|
|
stdout_logfile=/dev/stdout
|
|
stdout_logfile_maxbytes=0
|
|
stderr_logfile=/dev/stderr
|
|
stderr_logfile_maxbytes=0
|
|
|
|
[program:nginx]
|
|
command=nginx -g 'daemon off;'
|
|
autostart=true
|
|
autorestart=true
|
|
stdout_logfile=/dev/stdout
|
|
stdout_logfile_maxbytes=0
|
|
stderr_logfile=/dev/stderr
|
|
stderr_logfile_maxbytes=0
|
|
EOF
|
|
|
|
EXPOSE 8080
|
|
|
|
CMD ["supervisord", "-c", "/etc/supervisord.conf"]
|