Skip to content

Commit 7bc77fa

Browse files
committed
Split api, ui, cli into standalone components. Add login for CLI flow
1 parent a9d9a00 commit 7bc77fa

78 files changed

Lines changed: 4229 additions & 1301 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ coverage.*
1515
/bin
1616
docs/generators/cli-doc/cli-doc
1717
apiserviceexport.yaml
18-
*.prod
18+
*.prod
19+
20+
# Frontend dependencies and build
21+
web/node_modules/
22+
web/.vite/
23+
web/*.tsbuildinfo

.golangci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ linters:
1515
- errcheck
1616
- errchkjson
1717
- gocritic
18-
- godot
1918
- goprintffuncname
2019
- gosec
2120
- govet

Dockerfile

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,67 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.24.0 AS builder
15+
# Use node:lts-alpine for better compatibility and smaller size
16+
FROM node:20.18.0-alpine3.20 AS ui-build-env
17+
WORKDIR /app
18+
19+
# Install build dependencies needed for native modules
20+
RUN apk add --no-cache python3 make g++
21+
22+
# Copy package files
23+
COPY ./web/package*.json ./
24+
COPY ./web/.npmrc ./
25+
26+
RUN npm install
27+
28+
# Install dependencies with specific flags to handle optional deps and architecture issues
29+
RUN npm ci --prefer-offline --no-audit --no-fund --no-optional
30+
31+
# Copy the Vue app files
32+
COPY ./web .
33+
34+
# Set environment to avoid native dependency issues
35+
ENV NODE_ENV=production
36+
ENV VITE_BUILD_TARGET=docker
37+
38+
# Building UI with Docker-specific config
39+
RUN npm run build
40+
41+
# Build Go binary with embedded UI assets
42+
FROM golang:1.24.0 AS go-build-env
43+
WORKDIR /app
44+
45+
# Accept build arguments for multi-arch support
46+
ARG TARGETARCH
47+
ARG TARGETOS
48+
ARG LDFLAGS
49+
50+
RUN apt-get update && apt-get install -y make jq
51+
52+
# Copy go.mod and go.sum files first for better caching
53+
COPY go.mod .
54+
COPY go.sum .
55+
56+
# Copy the source code
57+
COPY . .
58+
59+
# Copy built UI assets for embedding
60+
COPY --from=ui-build-env /app/dist ./backend/static/web/dist
61+
62+
# Build with embedded assets
63+
RUN if [ -n "$LDFLAGS" ]; then \
64+
echo "Building with LDFLAGS: $LDFLAGS for $TARGETOS/$TARGETARCH"; \
65+
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="$LDFLAGS" -o bin/backend ./cmd/backend; \
66+
else \
67+
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH make build; \
68+
fi
69+
70+
FROM alpine:3.22.1
71+
RUN apk --update add ca-certificates
72+
73+
COPY --from=go-build-env /app/bin/backend /bin
74+
COPY --from=ui-build-env /app/dist /www
75+
76+
77+
78+
ENTRYPOINT ["/bin/backend"]

Dockerfile.konnector

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2022 The Kube Bind Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM golang:1.24.0 AS builder
16+
WORKDIR /app
17+
18+
# Accept build arguments for multi-arch support
19+
ARG TARGETARCH
20+
ARG TARGETOS
21+
ARG LDFLAGS
22+
23+
# Copy the source code (needed for local replacements in go.mod)
24+
COPY . .
25+
RUN go mod download
26+
27+
# Build the konnector binary
28+
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="$LDFLAGS" -o bin/konnector ./cmd/konnector
29+
30+
FROM alpine:3.22.1
31+
RUN apk --update add ca-certificates
32+
33+
COPY --from=builder /app/bin/konnector /bin/konnector
34+
35+
ENTRYPOINT ["/bin/konnector"]

Makefile

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,26 @@ $(KCP):
277277
run-kcp: $(KCP)
278278
$(KCP_CMD) start --bind-address=127.0.0.1
279279

280+
.PHONY: run-kcp-infra
281+
run-kcp-infra: $(KCP) $(DEX) ## Run KCP infrastructure for e2e tests (blocking)
282+
mkdir -p .kcp
283+
$(MAKE) run-dex 2>&1 & DEX_PID=$$!; \
284+
$(MAKE) run-kcp &>.kcp/kcp.log & KCP_PID=$$!; \
285+
trap 'kill -TERM $$DEX_PID $$KCP_PID; rm -rf .kcp' TERM INT EXIT && \
286+
echo "Waiting for kcp to be ready (check .kcp/kcp.log)." && while ! KUBECONFIG=.kcp/admin.kubeconfig kubectl get --raw /readyz &>/dev/null; do sleep 1; echo -n "."; done && echo && \
287+
echo "KCP is ready. Press Ctrl+C to stop." && \
288+
wait $$KCP_PID
289+
290+
.PHONY: test-e2e-only
291+
ifdef USE_GOTESTSUM
292+
test-e2e-only: $(GOTESTSUM)
293+
endif
294+
test-e2e-only: TEST_ARGS ?=
295+
test-e2e-only: WORK_DIR ?= .
296+
test-e2e-only: WHAT ?= ./test/e2e...
297+
test-e2e-only: build ## Run e2e tests against existing KCP infrastructure
298+
KUBECONFIG=$$PWD/.kcp/admin.kubeconfig GOOS=$(OS) GOARCH=$(ARCH) $(GO_TEST) -race -v -count $(COUNT) $(E2E_PARALLELISM_FLAG) $(WHAT) $(TEST_ARGS)
299+
280300
.PHONY: test-e2e
281301
ifdef USE_GOTESTSUM
282302
test-e2e: $(GOTESTSUM)
@@ -289,7 +309,7 @@ test-e2e: $(KCP) $(DEX) build ## Run e2e tests
289309
$(MAKE) run-kcp &>.kcp/kcp.log & KCP_PID=$$!; \
290310
trap 'kill -TERM $$KCP_PID; rm -rf .kcp' TERM INT EXIT && \
291311
echo "Waiting for kcp to be ready (check .kcp/kcp.log)." && while ! KUBECONFIG=.kcp/admin.kubeconfig kubectl get --raw /readyz &>/dev/null; do sleep 1; echo -n "."; done && echo && \
292-
KUBECONFIG=$$PWD/.kcp/admin.kubeconfig GOOS=$(OS) GOARCH=$(ARCH) $(GO_TEST) -race -count $(COUNT) $(E2E_PARALLELISM_FLAG) $(WHAT) $(TEST_ARGS)
312+
KUBECONFIG=$$PWD/.kcp/admin.kubeconfig GOOS=$(OS) GOARCH=$(ARCH) $(GO_TEST) -race -v -count $(COUNT) $(E2E_PARALLELISM_FLAG) $(WHAT) $(TEST_ARGS)
293313

294314
CONTRIBS_E2E := $(patsubst %,test-e2e-contrib-%,$(CONTRIBS))
295315

@@ -298,7 +318,11 @@ test-e2e-contribs: $(CONTRIBS_E2E) ## Run e2e tests for external integrations
298318

299319
test-e2e-contrib-kcp: $(DEX) $(KCP)
300320
$(CONTRIBS_E2E):
301-
cd contrib/$(patsubst test-e2e-contrib-%,%,$@) && $(GO_TEST) -race -count $(COUNT) $(E2E_PARALLELISM_FLAG) ./test/e2e/...
321+
mkdir .kcp
322+
$(MAKE) run-kcp &>.kcp/kcp.log & KCP_PID=$$!; \
323+
trap 'kill -TERM $$KCP_PID; rm -rf .kcp' TERM INT EXIT && \
324+
echo "Waiting for kcp to be ready (check .kcp/kcp.log)." && while ! KUBECONFIG=.kcp/admin.kubeconfig kubectl get --raw /readyz &>/dev/null; do sleep 1; echo -n "."; done && echo && \
325+
cd contrib/$(patsubst test-e2e-contrib-%,%,$@) && KUBECONFIG=$$PWD/../../.kcp/admin.kubeconfig $(GO_TEST) -race -count $(COUNT) $(E2E_PARALLELISM_FLAG) ./test/e2e/...
302326

303327
.PHONY: test
304328
ifdef USE_GOTESTSUM
@@ -375,35 +399,53 @@ deploy-docs: venv ## Deploy docs
375399
. $(VENV)/activate; \
376400
REMOTE=$(REMOTE) BRANCH=$(BRANCH) docs/scripts/deploy-docs.sh
377401

402+
.PHONY: build-web
403+
build-web:
404+
cd web && npm run build
405+
378406
# Example: make IMAGE_REPO=ghcr.io/<username> image-local
407+
# Set PLATFORMS to override default architectures (e.g., make PLATFORMS=linux/amd64,linux/arm64 image-local)
408+
# For local builds, default to current architecture on Linux platform to support --load
409+
PLATFORMS ?= linux/$(ARCH)
379410
.PHONY: image-local
380411
image-local:
381-
@echo "Building images locally with tag $(REV)"
382-
@command -v ko >/dev/null 2>&1 || { echo "ko not found. Install with: go install github.com/google/ko@latest"; exit 1; }
383-
384-
@echo "Building konnector image locally..."
385-
KO_DOCKER_REPO=$(IMAGE_REPO) ko build \
386-
--local \
387-
-B \
388-
-t $(REV) \
389-
./cmd/konnector
390-
391-
@echo "Building backend image locally..."
392-
KO_DOCKER_REPO=$(IMAGE_REPO) ko build \
393-
--local \
394-
-B \
395-
-t $(REV) \
396-
./cmd/backend
397-
398-
@echo "Successfully built local images:"
399-
@echo " $(IMAGE_REPO)/konnector:$(REV)"
400-
@echo " $(IMAGE_REPO)/backend:$(REV)"
412+
@echo "Building multi-arch images locally with tag $(REV) for platforms: $(PLATFORMS)"
413+
@command -v docker >/dev/null 2>&1 || { echo "docker not found. Please install Docker"; exit 1; }
414+
@docker buildx version >/dev/null 2>&1 || { echo "docker buildx not found. Please enable buildx in Docker"; exit 1; }
415+
416+
@# Create buildx builder if it doesn't exist
417+
@docker buildx create --name kube-bind-builder --use 2>/dev/null || docker buildx use kube-bind-builder 2>/dev/null || true
418+
@docker buildx inspect --bootstrap >/dev/null 2>&1
419+
420+
@echo "Building konnector multi-arch image locally..."
421+
docker buildx build \
422+
--platform $(PLATFORMS) \
423+
--build-arg LDFLAGS="$(LDFLAGS)" \
424+
-t $(IMAGE_REPO)/konnector:$(REV) \
425+
-f Dockerfile.konnector \
426+
--load .
427+
428+
@echo "Building backend multi-arch image locally..."
429+
docker buildx build \
430+
--platform $(PLATFORMS) \
431+
--build-arg LDFLAGS="$(LDFLAGS)" \
432+
-t $(IMAGE_REPO)/backend:$(REV) \
433+
-f Dockerfile \
434+
--load .
435+
436+
@echo "Successfully built multi-arch local images:"
437+
@echo " $(IMAGE_REPO)/konnector:$(REV) ($(PLATFORMS))"
438+
@echo " $(IMAGE_REPO)/backend:$(REV) ($(PLATFORMS))"
439+
440+
# Kind cluster configuration
441+
KIND_CLUSTER ?= kube-bind
442+
DOCKER_REPO ?= $(IMAGE_REPO)
401443

402444
.PHONY: kind-load
403445
kind-load:
404446
@echo "Loading images into kind cluster '$(KIND_CLUSTER)'"
405-
kind load docker-image $(KO_DOCKER_REPO)/konnector:$(REV) --name $(KIND_CLUSTER)
406-
kind load docker-image $(KO_DOCKER_REPO)/backend:$(REV) --name $(KIND_CLUSTER)
447+
kind load docker-image $(DOCKER_REPO)/konnector:$(REV) --name $(KIND_CLUSTER)
448+
kind load docker-image $(DOCKER_REPO)/backend:$(REV) --name $(KIND_CLUSTER)
407449
@echo "Successfully loaded images into kind cluster '$(KIND_CLUSTER)'"
408450

409451
.PHONY: helm-build-local

0 commit comments

Comments
 (0)