notebooks/workspaces/backend/Dockerfile

41 lines
1.0 KiB
Docker

# Use the golang image to build the application
FROM golang:1.22 AS builder
ARG TARGETOS
ARG TARGETARCH
WORKDIR /workspace
# Copy the Go Modules manifests
COPY backend/go.mod backend/go.sum ./
# Copy controller directory
COPY controller /workspace/controller
# Rewrite the go.mod to update the replace directive and download dependencies
RUN go mod edit -replace=github.com/kubeflow/notebooks/workspaces/controller=./controller && \
go mod download
# Copy the go source files
COPY backend/cmd/ cmd/
COPY backend/api/ api/
COPY backend/internal/ internal/
COPY backend/openapi/ openapi/
# Build the Go application
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o backend ./cmd/main.go
# Use distroless as minimal base image to package the application binary
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/backend ./
USER 65532:65532
# Expose port 4000
EXPOSE 4000
# Define environment variables
ENV PORT=4000
ENV ENV=development
ENTRYPOINT ["/backend"]