Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions workspaces/.dockerignore
Original file line number Diff line number Diff line change
@@ -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/
23 changes: 13 additions & 10 deletions workspaces/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to changes in this PR - but I'm confused by the use case of specifying TARGETARCH here...

Our Makefile never sets this build argument... so do we even need it? Under what circumstance would it need to be defined?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, we need the TARGETOS and TARGETARCH for the make docker-buildx command.
When you use docker buildx build --platform=..., Docker automatically sets build-time environment variables like TARGETARCH and TARGETOS for each platform you're building for.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thank you for highlighting this! TIL 💯

However, from my preliminary research - just sharing for awareness - no changes needed/required on this PR - it seems that podman does NOT automatically set these variables... so while we have a CONTAINER_TOOL "abstraction" in our Makefile to "support" running with podman - it won't actually be comparable to what docker does (without user intervention)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the comment, I checked it too, and I saw that in podman we don't have the buildx command at all, so we will need to change that too (but let's leave it to another ticket for replacing podman with docker)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - definitely a follow up item we can/should discuss more how to handle!

Expand All @@ -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"]
7 changes: 4 additions & 3 deletions workspaces/backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down