
FROM golang:1.25 AS build

WORKDIR /app
COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /bin/app ./cmd/server

FROM alpine:3.18

RUN apk add --no-cache nginx bash curl

# Copy Go binary
COPY --from=build /bin/app /app

# Copy web/static files
COPY web /web
COPY uploads /uploads
VOLUME ["/uploads"]

# Copy Nginx configs
COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY nginx/app.conf /etc/nginx/conf.d/default.conf

# Set environment
ENV APP_ADDR=:8080
ENV UPLOAD_DIR=/uploads

# Expose ports
EXPOSE 8080 80

# Startup script to run both Go app + Nginx
CMD ["sh", "-c", "/app & nginx -g 'daemon off;'"]
