feat: 使用docker部署

This commit is contained in:
sar
2026-01-14 15:37:35 +08:00
parent 02caa45efc
commit 59f5a87275
2 changed files with 64 additions and 0 deletions

37
backend/Dockerfile Normal file
View File

@@ -0,0 +1,37 @@
# Build stage
FROM golang:1.25-alpine AS builder
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache git
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download all dependencies
RUN go mod download
# Copy the source code
COPY . .
# Build the application
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main ./cmd/main.go
# Final stage
FROM alpine:latest
WORKDIR /app
# Install ca-certificates for HTTPS
RUN apk --no-cache add ca-certificates tzdata
# Copy binary from builder
COPY --from=builder /app/main .
COPY --from=builder /app/.env.example .
# Expose port
EXPOSE 8080
# Command to run
CMD ["./main"]