Signed-off-by: kaedwen <kaedwen@heinrich.blue>
This commit is contained in:
@@ -3,11 +3,6 @@ FROM golang:1.26-alpine AS builder
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
# 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)
|
||||
|
||||
+10
-17
@@ -3,27 +3,19 @@ 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'" \
|
||||
-trimpath \
|
||||
-ldflags="-w -s" \
|
||||
-o aitrade \
|
||||
./cmd/aitrade
|
||||
|
||||
# Build healthcheck utility
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
||||
-ldflags="-w -s -extldflags '-static'" \
|
||||
-trimpath \
|
||||
-ldflags="-w -s" \
|
||||
-o healthcheck \
|
||||
./cmd/healthcheck
|
||||
|
||||
@@ -49,12 +41,13 @@ WORKDIR /app
|
||||
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
|
||||
# Create non-root user with same UID as distroless (65532)
|
||||
RUN addgroup -g 65532 nonroot && \
|
||||
adduser -D -u 65532 -G nonroot nonroot && \
|
||||
mkdir -p /app/data && \
|
||||
chown -R nonroot:nonroot /app
|
||||
|
||||
USER appuser
|
||||
USER nonroot
|
||||
|
||||
# Expose web port
|
||||
EXPOSE 8080
|
||||
|
||||
Reference in New Issue
Block a user