Build and Push Docker Image / build-and-push (push) Successful in 4m39s
Signed-off-by: kaedwen <kaedwen@heinrich.blue>
68 lines
1.5 KiB
Docker
68 lines
1.5 KiB
Docker
# Debug build with shell and tools
|
|
FROM golang:1.26-alpine AS builder
|
|
|
|
WORKDIR /build
|
|
|
|
# Install build dependencies
|
|
RUN apk add --no-cache git
|
|
|
|
# Copy go mod files
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the application (static binary, no CGO, migrations embedded)
|
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
|
-a \
|
|
-installsuffix cgo \
|
|
-ldflags="-w -s -extldflags '-static'" \
|
|
-o aitrade \
|
|
./cmd/aitrade
|
|
|
|
# Build healthcheck utility
|
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
|
-ldflags="-w -s -extldflags '-static'" \
|
|
-o healthcheck \
|
|
./cmd/healthcheck
|
|
|
|
# Debug runtime stage - Alpine with shell and debugging tools
|
|
FROM alpine:latest
|
|
|
|
# Install debugging tools
|
|
RUN apk add --no-cache \
|
|
bash \
|
|
curl \
|
|
wget \
|
|
netcat-openbsd \
|
|
bind-tools \
|
|
busybox-extras \
|
|
ca-certificates \
|
|
sqlite \
|
|
tzdata
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy binary from builder (migrations are embedded in binary)
|
|
COPY --from=builder /build/aitrade /app/aitrade
|
|
COPY --from=builder /build/healthcheck /app/healthcheck
|
|
|
|
# Create non-root user
|
|
RUN addgroup -g 1000 appuser && \
|
|
adduser -D -u 1000 -G appuser appuser && \
|
|
chown -R appuser:appuser /app
|
|
|
|
USER appuser
|
|
|
|
# Expose web port
|
|
EXPOSE 8080
|
|
|
|
# Health check using custom binary
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD ["/app/healthcheck", "localhost", "8080"]
|
|
|
|
# Run application
|
|
ENTRYPOINT ["/app/aitrade"]
|