diff --git a/workspaces/.dockerignore b/workspaces/.dockerignore new file mode 100644 index 00000000..ae48c79b --- /dev/null +++ b/workspaces/.dockerignore @@ -0,0 +1,7 @@ +# NOTE: This file is used when building Docker images with context `..` +# Primarily intended for backend/Dockerfile builds + +# Exclude frontend code, node_modules, and unnecessary binaries +frontend/ +controller/bin/ +backend/bin/ \ No newline at end of file diff --git a/workspaces/backend/Dockerfile b/workspaces/backend/Dockerfile index a091f293..53d3ad94 100644 --- a/workspaces/backend/Dockerfile +++ b/workspaces/backend/Dockerfile @@ -6,17 +6,20 @@ ARG TARGETARCH WORKDIR /workspace # Copy the Go Modules manifests -COPY go.mod go.sum ./ +COPY backend/go.mod backend/go.sum ./ -# Download dependencies -RUN go mod download +# 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 cmd/ cmd/ -COPY api/ api/ -COPY config/ config/ -COPY data/ data/ -COPY integrations/ integrations/ +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 @@ -31,7 +34,7 @@ USER 65532:65532 EXPOSE 4000 # Define environment variables -ENV PORT 4000 -ENV ENV development +ENV PORT=4000 +ENV ENV=development ENTRYPOINT ["/backend"] diff --git a/workspaces/backend/Makefile b/workspaces/backend/Makefile index fc0869b9..55925977 100644 --- a/workspaces/backend/Makefile +++ b/workspaces/backend/Makefile @@ -91,7 +91,8 @@ run: fmt vet swag ## Run a backend from your host. # More info: https://docs.docker.com/develop/develop-images/build_enhancements/ .PHONY: docker-build docker-build: ## Build docker image with the backend. - $(CONTAINER_TOOL) build -t ${IMG} . + $(CONTAINER_TOOL) build -f Dockerfile -t $(IMG) .. + .PHONY: docker-push docker-push: ## Push docker image with the backend. @@ -107,10 +108,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le .PHONY: docker-buildx docker-buildx: ## Build and push docker image for the manager for cross-platform support # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile - sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross + sed '1,// s/^FROM/FROM --platform=$${BUILDPLATFORM}/' Dockerfile > Dockerfile.cross - $(CONTAINER_TOOL) buildx create --name project-v3-builder $(CONTAINER_TOOL) buildx use project-v3-builder - - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . + - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .. - $(CONTAINER_TOOL) buildx rm project-v3-builder rm Dockerfile.cross