fix(ws): backend dockerfile (#386)

* feat(ws): Properly containerize backend component #323

Signed-off-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com>

* feat(ws): Properly containerize backend component #323

Signed-off-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com>

* feat(ws): Properly containerize backend component #323

Signed-off-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com>

* mathew: revert typo

Signed-off-by: Mathew Wicks <5735406+thesuperzapper@users.noreply.github.com>

---------

Signed-off-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com>
Signed-off-by: Mathew Wicks <5735406+thesuperzapper@users.noreply.github.com>
Co-authored-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com>
Co-authored-by: Mathew Wicks <5735406+thesuperzapper@users.noreply.github.com>
This commit is contained in:
Liav Weiss 2025-06-27 00:47:17 +03:00 committed by Bhakti Narvekar
parent b6e664ccff
commit eae9e23a58
3 changed files with 24 additions and 13 deletions

7
workspaces/.dockerignore Normal file
View File

@ -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/

View File

@ -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"]

View File

@ -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