# Build Stage
FROM 192.168.1.154:31010/docker/alpine:latest AS builder

WORKDIR /app

# Install Go
RUN apk add --no-cache go

# Configure Go proxy for faster downloads
ENV GOPROXY=https://goproxy.cn,direct
ENV GOSUMDB=sum.golang.google.cn

# Copy go mod and sum files
COPY go.mod go.sum ./

# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download

# Copy the source from the current directory to the Working Directory inside the container
COPY . .

# Build the Go app
RUN go build -o server ./cmd/server

# Run Stage
FROM 192.168.1.154:31010/docker/alpine:latest

WORKDIR /app

# Copy the Pre-built binary from the previous stage
COPY --from=builder /app/server .
# Copy web resources
COPY --from=builder /app/web ./web
# Copy docs
COPY --from=builder /app/docs ./docs

# Expose port 8080 to the outside world
EXPOSE 8080

# Command to run the executable
CMD ["./server"]
