atri.dad/Dockerfile
Atridad Lahiji 9bc4df5d18
All checks were successful
Docker Deploy / build-and-push (push) Successful in 1m19s
Oops
2025-03-31 03:50:38 -06:00

43 lines
1.1 KiB
Docker

FROM --platform=$BUILDPLATFORM golang:1.24.0-alpine AS builder
WORKDIR /app
# Download dependencies and install required tools
COPY go.mod go.sum ./
RUN go mod download && \
go install github.com/swaggo/swag/cmd/swag@latest
# Copy source code and Makefile
COPY . .
# Install required tools and make scripts executable
RUN apk add --no-cache upx make bash
# Create necessary directories
RUN mkdir -p /app/public/css
# Generate assets and build with optimizations
SHELL ["/bin/bash", "-c"]
# Platform-specific builds
ARG TARGETPLATFORM
RUN cd /app && make generate && \
case "${TARGETPLATFORM}" in \
"linux/amd64") GOARCH=amd64 ;; \
"linux/arm64") GOARCH=arm64 ;; \
*) GOARCH=amd64 ;; \
esac && \
CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} go build \
-ldflags='-s -w -extldflags "-static"' \
-tags netgo,osusergo \
-o /go/bin/app
# Final stage
FROM --platform=$TARGETPLATFORM scratch
# Copy static files and assets
COPY --from=builder /app/public/css/styles.css /public/css/styles.css
COPY --from=builder /app/docs /docs
COPY --from=builder /go/bin/app /app
ENTRYPOINT ["/app"]