2024-11-03 16:06:21 -06:00
|
|
|
FROM golang:1.23.2-alpine AS builder
|
2024-05-14 00:00:28 -06:00
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
2024-12-18 23:21:12 -06:00
|
|
|
# Download dependencies and install required tools
|
2024-10-21 21:20:39 -06:00
|
|
|
COPY go.mod go.sum ./
|
2024-12-18 23:21:12 -06:00
|
|
|
RUN go mod download && \
|
|
|
|
go install github.com/swaggo/swag/cmd/swag@latest
|
2024-10-21 21:20:39 -06:00
|
|
|
|
2024-12-18 23:21:12 -06:00
|
|
|
# Copy source code and Makefile
|
2024-10-21 21:20:39 -06:00
|
|
|
COPY . .
|
|
|
|
|
2024-12-18 23:21:12 -06:00
|
|
|
# Install required tools and make scripts executable
|
|
|
|
RUN apk add --no-cache upx make bash && \
|
2025-01-04 22:23:10 -07:00
|
|
|
chmod +x /app/lib/stylegen/gen.sh
|
2024-11-03 16:06:21 -06:00
|
|
|
|
2025-01-04 22:23:10 -07:00
|
|
|
# Create necessary directories
|
|
|
|
RUN mkdir -p /app/public/css
|
2024-12-18 23:21:12 -06:00
|
|
|
|
|
|
|
# Generate assets and build with optimizations
|
|
|
|
SHELL ["/bin/bash", "-c"]
|
|
|
|
RUN cd /app && make generate && \
|
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
2024-11-03 16:06:21 -06:00
|
|
|
-ldflags='-s -w -extldflags "-static"' \
|
|
|
|
-tags netgo,osusergo \
|
|
|
|
-o /go/bin/app
|
2024-05-14 00:00:28 -06:00
|
|
|
|
2024-11-03 16:06:21 -06:00
|
|
|
# Final stage
|
2024-08-09 09:46:54 -06:00
|
|
|
FROM scratch
|
2024-05-14 00:00:28 -06:00
|
|
|
|
2024-12-18 23:21:12 -06:00
|
|
|
# Copy static files and assets
|
|
|
|
COPY --from=builder /app/public/css/styles.css /public/css/styles.css
|
|
|
|
COPY --from=builder /app/docs /docs
|
2024-11-03 16:06:21 -06:00
|
|
|
COPY --from=builder /go/bin/app /app
|
2024-05-14 00:00:28 -06:00
|
|
|
|
2024-10-21 21:20:39 -06:00
|
|
|
ENTRYPOINT ["/app"]
|