[BACKEND] Initialize Go backend structure and dependencies (#23)

This commit is contained in:
2026-02-15 22:50:06 +00:00
parent 7157877f0b
commit c75f976a2d
29 changed files with 1857 additions and 253 deletions

View File

@@ -1,25 +1,28 @@
# ==========================================
# Chat Switchboard Unified Dockerfile
# Option B: Multi-stage build
# ==========================================
# ============================================
# Chat Switchboard - Unified Dockerfile
# ============================================
# Stage 1: Build Go backend
# Stage 2: Build standalone frontend
# Stage 3: Production image (nginx + backend)
#
# nginx serves frontend on :80, proxies /api/ to Go on :8080
# ============================================
# Stage 1: Backend build
# ── Stage 1: Go backend build ────────────────
FROM golang:1.22-bookworm AS backend
WORKDIR /app
COPY server/go.mod ./
COPY server/go.sum ./
RUN go mod download
COPY server/go.mod server/go.sum* ./
RUN go mod download && go mod verify
COPY server/ .
RUN CGO_ENABLED=1 go build -o /backend chat-switchboard-api
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /bin/switchboard .
# Stage 2: Frontend build
# ── Stage 2: Frontend build ──────────────────
FROM alpine:3.19 AS frontend
WORKDIR /app
RUN apk add --no-cache bash coreutils
COPY build.sh ./
@@ -27,24 +30,22 @@ COPY src ./src
RUN chmod +x build.sh && ./build.sh
# Stage 3: Production
FROM nginx:alpine AS production
# ── Stage 3: Production ─────────────────────
FROM nginx:1-alpine
# Copy backend binary
COPY --from=backend /backend /usr/local/bin/
RUN apk add --no-cache bash
# Copy built frontend files
# Copy Go backend
COPY --from=backend /bin/switchboard /usr/local/bin/switchboard
# Copy built frontend
COPY --from=frontend /app/standalone /usr/share/nginx/html
# Copy custom nginx config for reverse proxy
# Copy nginx config
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Create startup script
RUN echo '#!/bin/sh\n\
mkdir -p /app/data\n\
/usr/local/bin/backend serve &\n\
nginx -g "daemon off;"\n' > /start.sh && chmod +x /start.sh
# Startup script: launches Go backend before nginx starts
COPY scripts/docker-entrypoint.sh /docker-entrypoint.d/90-start-backend.sh
RUN chmod +x /docker-entrypoint.d/90-start-backend.sh
EXPOSE 80
CMD ["/start.sh"]