Skip to content

Commit 5fe3d18

Browse files
committed
Refactor backend to be API first, with dedicated frontend
1 parent fadb9ed commit 5fe3d18

37 files changed

Lines changed: 6663 additions & 56 deletions

.github/workflows/image.yaml

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,25 @@ jobs:
2121
with:
2222
go-version: v1.24.0
2323
check-latest: true
24+
25+
- name: Set up Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: '20'
29+
cache: 'npm'
30+
cache-dependency-path: web/package-lock.json
31+
2432
# We need this to remove local tags that are not semver so goreleaser doesn't get confused.
2533
- name: Delete non-semver tags
2634
run: 'git tag -d $(git tag -l | grep -v "^v")'
35+
36+
# Set up Docker Buildx for multi-platform builds
37+
- name: Set up Docker Buildx
38+
uses: docker/setup-buildx-action@v3
39+
2740
# If you notice signing errors, you may need to update the cosign version.
2841
- uses: sigstore/cosign-installer@v3.7.0
42+
2943
- name: Install ko
3044
run: go install github.com/google/ko@latest
3145

@@ -37,6 +51,14 @@ jobs:
3751
- name: Set LDFLAGS
3852
run: echo LDFLAGS="$(make ldflags)" | tee -a >> $GITHUB_ENV
3953

54+
# Login to GitHub Container Registry (used by both ko and Docker)
55+
- name: Login to GitHub Container Registry
56+
uses: docker/login-action@v3
57+
with:
58+
registry: ghcr.io
59+
username: ${{ github.actor }}
60+
password: ${{ secrets.GITHUB_TOKEN }}
61+
4062
# Build ko from HEAD, build and push an image tagged with the commit SHA,
4163
# then keylessly sign it with cosign.
4264
- name: Publish and sign konnector image
@@ -54,14 +76,39 @@ jobs:
5476
-a run_id=${{ github.run_id }} \
5577
-a run_attempt=${{ github.run_attempt }}
5678
57-
- name: Publish and sign backend image
79+
# Build and push backend image using Dockerfile (includes frontend)
80+
# Note: Backend image uses Dockerfile to include both Go backend + Vue.js frontend
81+
# while konnector continues to use ko for Go-only builds
82+
- name: Build and push backend image
83+
uses: docker/build-push-action@v5
84+
id: build
85+
with:
86+
context: .
87+
file: ./Dockerfile
88+
platforms: linux/amd64,linux/arm64
89+
push: true
90+
tags: |
91+
ghcr.io/${{ github.repository_owner }}/backend:latest
92+
ghcr.io/${{ github.repository_owner }}/backend:${{ github.sha }}
93+
ghcr.io/${{ github.repository_owner }}/backend:${{ github.ref_name }}
94+
cache-from: type=gha
95+
cache-to: type=gha,mode=max
96+
build-args: |
97+
LDFLAGS=${{ env.LDFLAGS }}
98+
labels: |
99+
org.opencontainers.image.title=Kube Bind Backend
100+
org.opencontainers.image.description=Kube Bind backend with integrated Vue.js frontend
101+
org.opencontainers.image.source=https://github.com/${{ github.repository }}
102+
org.opencontainers.image.revision=${{ github.sha }}
103+
org.opencontainers.image.version=${{ github.ref_name }}
104+
105+
# Sign the backend image
106+
- name: Sign backend image
58107
env:
59-
KO_DOCKER_REPO: ghcr.io/${{ github.repository_owner }}/backend
60108
COSIGN_EXPERIMENTAL: 'true'
61109
run: |
62-
echo "${{ github.token }}" | ko login ghcr.io --username "${{ github.actor }}" --password-stdin
63-
img=$(ko build --bare --platform=all -t latest -t ${{ github.sha }} -t ${{github.ref_name}} ./cmd/backend)
64-
echo "built ${img}"
110+
img="ghcr.io/${{ github.repository_owner }}/backend@${{ steps.build.outputs.digest }}"
111+
echo "signing ${img}"
65112
cosign sign ${img} \
66113
--yes \
67114
-a sha=${{ github.sha }} \

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@ 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/dist/
23+
web/.vite/
24+
web/*.tsbuildinfo

Dockerfile

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,61 @@
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+
FROM golang:1.24.0 AS go-build-env
16+
WORKDIR /app
17+
18+
# Accept build arguments
19+
ARG LDFLAGS
20+
21+
RUN apt-get update && apt-get install -y make jq
22+
23+
# <- COPY go.mod and go.sum files to the workspace
24+
COPY go.mod .
25+
COPY go.sum .
26+
27+
# COPY the source code as the last step
28+
COPY . .
29+
30+
# Build with custom LDFLAGS if provided, otherwise use make build
31+
RUN if [ -n "$LDFLAGS" ]; then \
32+
echo "Building with LDFLAGS: $LDFLAGS"; \
33+
go build -ldflags="$LDFLAGS" -o bin/backend ./cmd/backend; \
34+
else \
35+
make build; \
36+
fi
37+
38+
# Use node:lts-alpine for better compatibility and smaller size
39+
FROM node:20.18.0-alpine3.20 AS ui-build-env
40+
WORKDIR /app
41+
42+
# Install build dependencies needed for native modules
43+
RUN apk add --no-cache python3 make g++
44+
45+
# Copy package files
46+
COPY ./web/package*.json ./
47+
COPY ./web/.npmrc ./
48+
49+
RUN npm install
50+
51+
# Install dependencies with specific flags to handle optional deps and architecture issues
52+
RUN npm ci --prefer-offline --no-audit --no-fund --no-optional
53+
54+
# Copy the Vue app files
55+
COPY ./web .
56+
57+
# Set environment to avoid native dependency issues
58+
ENV NODE_ENV=production
59+
ENV VITE_BUILD_TARGET=docker
60+
61+
# Building UI with Docker-specific config
62+
RUN npm run build
63+
64+
FROM alpine:3.22.1
65+
RUN apk --update add ca-certificates
66+
67+
COPY --from=go-build-env /app/bin/backend /bin
68+
COPY --from=ui-build-env /app/dist /www
69+
70+
71+
72+
ENTRYPOINT ["/bin/backend"]

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ deploy-docs: venv ## Deploy docs
379379
.PHONY: image-local
380380
image-local:
381381
@echo "Building images locally with tag $(REV)"
382+
@command -v docker >/dev/null 2>&1 || { echo "docker not found. Please install Docker"; exit 1; }
382383
@command -v ko >/dev/null 2>&1 || { echo "ko not found. Install with: go install github.com/google/ko@latest"; exit 1; }
383384

384385
@echo "Building konnector image locally..."
@@ -389,11 +390,10 @@ image-local:
389390
./cmd/konnector
390391

391392
@echo "Building backend image locally..."
392-
KO_DOCKER_REPO=$(IMAGE_REPO) ko build \
393-
--local \
394-
-B \
395-
-t $(REV) \
396-
./cmd/backend
393+
docker build \
394+
--build-arg LDFLAGS="$(LDFLAGS)" \
395+
-t $(IMAGE_REPO)/backend:$(REV) \
396+
-f Dockerfile .
397397

398398
@echo "Successfully built local images:"
399399
@echo " $(IMAGE_REPO)/konnector:$(REV)"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ There are several ways to communicate with us:
5858

5959
All the actions shown between the clusters are done by the konnector, except: the pull at the start is done by the kubectl plugin that installs the konnector.
6060

61+
See [web/README.md](./web/README.md) for detailed frontend documentation.
62+
6163
## Usage
6264

6365
To get familiar with setting up the environment, please check out docs at [kube-bind.io](https://docs.kube-bind.io/main/setup).

0 commit comments

Comments
 (0)