Skip to content

Commit

Permalink
Merge pull request #166 from srl-labs/feat/ui
Browse files Browse the repository at this point in the history
Feat/UI
  • Loading branch information
carlmontanari authored Aug 13, 2024
2 parents bf8e8ed + 88feea6 commit 425440d
Show file tree
Hide file tree
Showing 85 changed files with 25,515 additions and 7 deletions.
48 changes: 43 additions & 5 deletions .develop/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ vars:
MANAGER_IMAGE: ${REGISTRY}/${CLABERNETES}-manager
MANAGER_DEV_IMAGE: ${MANAGER_IMAGE}-dev
LAUNCHER_IMAGE: ${REGISTRY}/${CLABERNETES}-launcher
UI_IMAGE: ${REGISTRY}/${CLABERNETES}-ui
CLABVERTER_IMAGE: ${REGISTRY}/clabverter

# always build w/ 0.0.0 -- overridden for actual releases by release profile. for "normal" builds
Expand All @@ -26,6 +27,10 @@ vars:
# to be set in ci
RELEASE_VERSION: ""

CLABERNETES_DEV_DOMAIN:
source: env
default: containerlab.dev

localRegistry:
enabled: false

Expand All @@ -37,7 +42,7 @@ images:
dockerfile: dev.Dockerfile
rebuildStrategy: ignoreContextChanges
tags:
- $(git describe --always --abbrev=8)
- ${COMMIT_HASH}

clabernetes:
createPullSecret: false
Expand All @@ -49,7 +54,7 @@ images:
VERSION: ${VERSION}-${COMMIT_HASH}
tags:
- dev-latest
- $(git describe --always --abbrev=8)
- ${COMMIT_HASH}

clabernetes-launcher:
createPullSecret: false
Expand All @@ -63,6 +68,20 @@ images:
- dev-latest
- ${COMMIT_HASH}

clabernetes-ui:
createPullSecret: false
image: ${UI_IMAGE}
context: ../ui/
dockerfile: ../build/ui.Dockerfile
rebuildStrategy: ignoreContextChanges
buildArgs:
VERSION: ${VERSION}-${COMMIT_HASH}
# seems node things dont wanna ever build w/out buildkit?
buildKit: {}
tags:
- dev-latest
- ${COMMIT_HASH}

clabverter:
createPullSecret: false
image: ${CLABVERTER_IMAGE}
Expand All @@ -85,6 +104,9 @@ deployments:
manager:
image: ${MANAGER_IMAGE}
imagePullPolicy: ${PULL_POLICY}
ui:
image: ${UI_IMAGE}
imagePullPolicy: ${PULL_POLICY}
globalConfig:
deployment:
launcherImage: ${LAUNCHER_IMAGE}
Expand All @@ -110,6 +132,16 @@ dev:
command: .develop/start.sh

profiles:
- name: dev
patches:
- op: add
path: deployments.clabernetes.helm.values.ui
value:
enabled: true
ingress:
enabled: true
host: ui.clabernetes.${CLABERNETES_DEV_DOMAIN}

- name: debug
patches:
- op: add
Expand All @@ -128,6 +160,12 @@ profiles:
path: deployments.clabernetes.helm.values.manager.replicaCount
value: 1

- name: single-ui
patches:
- op: add
path: deployments.clabernetes.helm.values.ui.replicaCount
value: 1

# for development using devspace on "non-local" clusters (meaning *not* kind/docker-desktop/
# minikube/maybe others) you will want to have Always for image pull so launcher and clicker pick
# up the new image -- you may even want always pull on manager so the manager dev image is pulled;
Expand Down Expand Up @@ -209,12 +247,12 @@ pipelines:
build:
# override the default build pipeline so we don't bother building dev image in ci
run: |
build_images clabernetes clabernetes-launcher clabverter
build_images clabernetes clabernetes-launcher clabernetes-ui clabverter
dev:
# override the default dev pipeline to not bother building clabverter while doing dev things
run: |
build_images clabernetes-dev clabernetes clabernetes-launcher
build_images clabernetes-dev clabernetes clabernetes-launcher clabernetes-ui
create_deployments --all
start_dev --all
Expand All @@ -223,7 +261,7 @@ pipelines:
# deploy pipeline
run: |
run_dependencies --all
build_images clabernetes clabernetes-launcher
build_images clabernetes clabernetes-launcher clabernetes-ui
create_deployments --all
purge:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ cover.out

# build files
cmd/clabverter/build/

# for crd -> openapi gen
venv
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ run-openapi-gen: ## Run openapi-gen
--output-file openapi_generated.go \
--output-pkg github.com/srl-labs/clabernetes/generated/openapi \
github.com/srl-labs/clabernetes/apis/...
venv/bin/python build/crds-to-openapi/crds-to-openapi.py && \
cp generated/openapi/openapi.json ui/clabernetes-openapi.json

run-client-gen: ## Run client-gen
client-gen \
Expand Down
1,322 changes: 1,322 additions & 0 deletions build/crds-to-openapi/crds-to-openapi.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/crds-to-openapi/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruamel.yaml==0.17.28
34 changes: 34 additions & 0 deletions build/ui.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM node:22.6.0-bookworm AS deps

WORKDIR /clabernetes

COPY package.json package-lock.json /clabernetes/

RUN npm ci && npm cache clean --force


FROM node:22.6.0-bookworm AS builder

ENV NODE_ENV=production

WORKDIR /clabernetes

COPY --from=deps /clabernetes/node_modules ./node_modules

COPY . .

RUN npm run build


FROM --platform=linux/amd64 gcr.io/distroless/nodejs22-debian12:nonroot

EXPOSE 3000
ENV PORT=3000
ENV NODE_ENV=production

WORKDIR /clabernetes

COPY --from=builder --chown=nonroot:nonroot /clabernetes/.next/standalone ./
COPY --from=builder --chown=nonroot:nonroot /clabernetes/.next/static ./.next/static

CMD ["server.js"]
119 changes: 119 additions & 0 deletions charts/clabernetes/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,122 @@ spec:
failureThreshold: 2
periodSeconds: 30
timeoutSeconds: 5

{{- if $.Values.ui.enabled }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $.Values.appName }}-ui
namespace: {{ .Release.Namespace }}
labels:
chart: "{{ $.Chart.Name }}-{{ $.Chart.Version }}"
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
revision: "{{ .Release.Revision }}"
app.kubernetes.io/name: "{{ $.Values.appName }}-ui"
clabernetes/app: {{ $.Values.appName }}
clabernetes/name: "{{ $.Values.appName }}-ui"
clabernetes/component: ui
{{- $labels := merge $.Values.globalLabels $.Values.ui.deploymentLabels }}
{{- if $labels }}
{{ toYaml $labels | indent 4 }}
{{- end }}
{{- $annotations := merge $.Values.globalAnnotations $.Values.ui.deploymentAnnotations }}
{{- if $annotations }}
annotations:
{{ toYaml $annotations | indent 4 }}
{{- end }}
spec:
selector:
matchLabels:
clabernetes/app: {{ $.Values.appName }}
release: {{ .Release.Name }}
replicas: {{ $.Values.ui.replicaCount }}
strategy:
rollingUpdate:
maxSurge: 1
{{- if (eq (int $.Values.ui.replicaCount) 1) }}
maxUnavailable: 0
{{- else }}
maxUnavailable: 1
{{- end }}
type: RollingUpdate
template:
metadata:
labels:
chart: "{{ $.Chart.Name }}-{{ $.Chart.Version }}"
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
revision: "{{ .Release.Revision }}"
app.kubernetes.io/name: "{{ $.Values.appName }}-ui"
clabernetes/app: {{ $.Values.appName }}
clabernetes/name: "{{ $.Values.appName }}-ui"
clabernetes/component: ui
{{- $podLabels := merge $.Values.globalLabels $.Values.ui.podLabels }}
{{- if $podLabels }}
{{ toYaml $podLabels | indent 8 }}
{{- end }}
{{- $podAnnotations := merge $.Values.globalAnnotations $.Values.ui.podAnnotations }}
{{- if $podAnnotations }}
annotations:
{{ toYaml $podAnnotations | indent 8 }}
{{- end }}
spec:
{{- if $.Values.ui.affinity }}
affinity:
{{ toYaml $.Values.ui.affinity | indent 8 }}
{{- else if (ge (int $.Values.ui.replicaCount) 2) }}
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchLabels:
clabernetes/app: {{ $.Values.appName }}
clabernetes/name: "{{ $.Values.appName }}-ui"
clabernetes/component: ui
topologyKey: kubernetes.io/hostname
- weight: 50
podAffinityTerm:
labelSelector:
matchLabels:
clabernetes/app: {{ $.Values.appName }}
clabernetes/name: "{{ $.Values.appName }}-ui"
clabernetes/component: ui
topologyKey: topology.kubernetes.io/zone
{{- end }}
terminationGracePeriodSeconds: 10
serviceAccountName: "{{ $.Values.appName }}-service-account"
containers:
- name: ui
{{- if .Values.ui.image }}
image: {{ .Values.ui.image }}
{{- else if eq .Chart.Version "0.0.0" }}
image: "ghcr.io/srl-labs/clabernetes/clabernetes-ui:dev-latest"
{{- else }}
image: "ghcr.io/srl-labs/clabernetes/clabernetes-ui:{{ .Chart.Version }}"
{{- end }}
imagePullPolicy: {{ $.Values.ui.imagePullPolicy }}
resources:
requests:
memory: {{ $.Values.ui.resources.requests.memory }}
cpu: {{ $.Values.ui.resources.requests.cpu }}
{{- if $.Values.ui.resources.limits }}
limits:
{{ toYaml $.Values.ui.resources.limits | indent 14 }}
{{- end }}
ports:
- name: http
containerPort: 3000
livenessProbe:
httpGet:
path: /alive
port: http
scheme: HTTP
successThreshold: 1
failureThreshold: 2
periodSeconds: 30
timeoutSeconds: 5
{{- end }}
40 changes: 40 additions & 0 deletions charts/clabernetes/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{- if and $.Values.ui.enabled $.Values.ui.ingress.enabled }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $.Values.appName }}-ui
namespace: {{ .Release.Namespace }}
labels:
chart: "{{ $.Chart.Name }}-{{ $.Chart.Version }}"
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
revision: "{{ .Release.Revision }}"
app.kubernetes.io/name: "{{ $.Values.appName }}-ui"
clabernetes/app: {{ $.Values.appName }}
clabernetes/name: "{{ $.Values.appName }}-ui"
clabernetes/component: ui
{{- $labels := merge $.Values.globalLabels $.Values.ui.deploymentLabels }}
{{- if $labels }}
{{ toYaml $labels | indent 4 }}
{{- end }}
{{- $annotations := merge $.Values.globalAnnotations $.Values.ui.deploymentAnnotations }}
{{- if $annotations }}
annotations:
kubernetes.io/ingress.class: {{ .Values.ui.ingress.ingressClass }}
{{ toYaml $annotations | indent 4 }}
{{- end }}
spec:
ingressClassName: {{ .Values.ui.ingress.ingressClass }}
rules:
- host: {{ .Values.ui.ingress.host }}
http:
paths:
- backend:
service:
name: {{ .Values.appName }}-ui
port:
number: 443
path: /
pathType: ImplementationSpecific
{{- end }}
40 changes: 40 additions & 0 deletions charts/clabernetes/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,43 @@ spec:
clabernetes/app: {{ .Values.appName }}
clabernetes/name: "{{ .Values.appName }}-manager"
clabernetes/component: manager

{{- if $.Values.ui.enabled }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ $.Values.appName }}-ui
namespace: {{ .Release.Namespace }}
labels:
chart: "{{ $.Chart.Name }}-{{ $.Chart.Version }}"
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
revision: "{{ .Release.Revision }}"
app.kubernetes.io/name: "{{ $.Values.appName }}-ui"
clabernetes/app: {{ $.Values.appName }}
clabernetes/name: "{{ $.Values.appName }}-ui"
clabernetes/component: ui
{{- $labels := merge $.Values.globalLabels $.Values.ui.deploymentLabels }}
{{- if $labels }}
{{ toYaml $labels | indent 4 }}
{{- end }}
{{- $annotations := merge $.Values.globalAnnotations $.Values.ui.deploymentAnnotations }}
{{- if $annotations }}
annotations:
kubernetes.io/ingress.class: {{ .Values.ui.ingress.ingressClass }}
{{ toYaml $annotations | indent 4 }}
{{- end }}
spec:
type: ClusterIP
sessionAffinity: None
ports:
- name: https
port: 443
protocol: TCP
targetPort: 3000
selector:
clabernetes/app: {{ $.Values.appName }}
clabernetes/name: "{{ $.Values.appName }}-ui"
clabernetes/component: ui
{{- end }}
Loading

0 comments on commit 425440d

Please sign in to comment.