atri.dad/Dockerfile

33 lines
680 B
Text
Raw Normal View History

2024-12-18 23:55:58 -06:00
FROM golang:1.23.2-alpine AS builder
2024-05-14 00:00:28 -06:00
WORKDIR /app
2024-12-18 23:55:58 -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:55:58 -06:00
RUN go mod download && \
go install github.com/swaggo/swag/cmd/swag@latest
2024-05-14 00:00:28 -06:00
2025-02-01 17:12:52 -06:00
# Copy source code
2024-10-21 21:20:39 -06:00
COPY . .
2025-02-01 17:12:52 -06:00
# Install tools
RUN apk add --no-cache upx make
2024-12-18 23:55:58 -06:00
# Generate assets and build with optimizations
2025-02-01 17:12:52 -06:00
RUN set -eux; \
cd /app; \
make generate; \
2024-12-18 23:55:58 -06:00
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags='-s -w -extldflags "-static"' \
-tags netgo,osusergo \
-o /go/bin/app
2024-05-14 00:00:28 -06:00
2024-12-18 23:55:58 -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:55:58 -06:00
# Copy static files and assets
COPY --from=builder /app/docs /docs
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"]