mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 10:46:50 +00:00
- Introduced a builder stage to separate build dependencies. - Added a dev stage for runtime dependencies and live reload tools. - Reduced image size by cleaning up unnecessary files in the builder stage. - Improved build efficiency by copying only necessary files to the dev stage.
34 lines
880 B
Docker
34 lines
880 B
Docker
# ----------- Builder Stage -----------
|
|
FROM golang:1.24-alpine AS builder
|
|
WORKDIR /app
|
|
|
|
RUN apk update && apk add --no-cache build-base
|
|
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
COPY . .
|
|
|
|
RUN go build -ldflags="-s -w" -o rentease main.go
|
|
|
|
# Install air and templ for live reload and templating in dev
|
|
RUN go install github.com/air-verse/air@latest \
|
|
&& go install github.com/a-h/templ/cmd/templ@latest \
|
|
&& rm -rf /go/pkg/mod /root/.cache/go-build
|
|
|
|
# ----------- Dev Stage -----------
|
|
FROM golang:1.24-alpine AS dev
|
|
WORKDIR /app
|
|
|
|
# Install runtime dependencies
|
|
RUN apk add --no-cache ca-certificates && apk add --no-cache golangci-lint
|
|
|
|
# Copy only necessary files from builder
|
|
COPY --from=builder /app/rentease ./rentease
|
|
COPY --from=builder /app/assets ./assets
|
|
COPY --from=builder /go/bin/air /go/bin/templ /go/bin/
|
|
COPY . .
|
|
|
|
EXPOSE 8000
|
|
|
|
CMD ["air", "-c", ".air.toml"]
|