Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manifest files to deploy UI stack in kind and openshift cluster #30

Merged
merged 1 commit into from
Jul 10, 2024
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
18 changes: 18 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.env
.env.example
.next
auth.log
.yamllint.yaml
SECURITY.md
README.md
Makefile
MAINTAINERS.md
LICENSE
CONTRIBUTING.md
CODE_OF_CONDUCT.md
.markdownlint-cli2.json
deploy/
docs/
certificates/
server/
.github/
10 changes: 6 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ IL_UI_ADMIN_USERNAME=admin
IL_UI_ADMIN_PASSWORD=password
OAUTH_GITHUB_ID=<OAUTH_APP_ID>
OAUTH_GITHUB_SECRET=<OAUTH_APP_SECRET>
GITHUB_TOKEN=<TOKEN FOR OAUTH INSTRUCTLAB MEMBER LOOKUP>
NEXTAUTH_SECRET=your_super_secret_random_string
NEXTAUTH_URL=http://localhost:3000

TAXONOMY_DOCUMENTS_REPO=github.com/<USER_ID>/<REPO_NAME>
NEXT_PUBLIC_TAXONOMY_REPO_OWNER=<GITHUB_ACCOUNT>
NEXT_PUBLIC_TAXONOMY_REPO=<REPO_NAME>

IL_GRANITE_API=<GRANITE_HOST>
IL_GRANITE_MODEL_NAME=<GRANITE_MODEL_NAME>
IL_MERLINITE_API=<MERLINITE_HOST>
IL_MERLINITE_MODEL_NAME=<MERLINITE_MODEL_NAME>
GITHUB_TOKEN=<TOKEN FOR OAUTH INSTRUCTLAB MEMBER LOOKUP>
TAXONOMY_DOCUMENTS_REPO=github.com/<USER_ID>/<REPO_NAME>
NEXT_PUBLIC_TAXONOMY_REPO_OWNER=<GITHUB_ACCOUNT>
NEXT_PUBLIC_TAXONOMY_REPO=<REPO_NAME>
2 changes: 1 addition & 1 deletion Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM node:22-alpine
WORKDIR /app

COPY package*.json ./
RUN npm install
RUN npm install --production
COPY ./ .

RUN npm run build
Expand Down
96 changes: 93 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ else
PIPE_DEV_NULL=
endif

ILAB_KUBE_CONTEXT?=kind-instructlab-ui
ILAB_KUBE_NAMESPACE?=instructlab
ILAB_KUBE_CLUSTER_NAME?=instructlab-ui
TAG=$(shell git rev-parse HEAD)
##@ Development - Helper commands for development
.PHONY: md-lint
md-lint: ## Lint markdown files
$(ECHO_PREFIX) printf " %-12s ./...\n" "[MD LINT]"
$(CMD_PREFIX) podman run --rm -v $(CURDIR):/workdir docker.io/davidanson/markdownlint-cli2:v0.6.0 > /dev/null
$(CMD_PREFIX) docker run --rm -v $(CURDIR):/workdir docker.io/davidanson/markdownlint-cli2:v0.6.0 > /dev/null

.PHONY: action-lint
action-lint: ## Lint GitHub Action workflows
Expand All @@ -31,6 +36,91 @@ action-lint: ## Lint GitHub Action workflows
fi
$(CMD_PREFIX) actionlint -color

##@ Artifacts - Command to build and publish artifacts
ui-image: Containerfile ## Build continaer image for the InstructLab UI
$(ECHO_PREFIX) printf " %-12s Containerfile\n" "[PODMAN]"
$(CMD_PREFIX) podman build -f Containerfile -t ghcr.io/instructlab/ui/ui:main .
$(ECHO_PREFIX) printf " %-12s Containerfile\n" "[docker]"
$(CMD_PREFIX) docker build -f Containerfile -t ghcr.io/instructlab/ui/ui:$(TAG) .
$(CMD_PREFIX) docker tag ghcr.io/instructlab/ui/ui:$(TAG) ghcr.io/instructlab/ui/ui:main


##@ Kubernetes - kind dev environment
.PHONY: check-kind
check-kind:
$(CMD_PREFIX) if [ -z "$(shell which kind)" ]; then \
echo "Please install kind and then start the kind dev environment." ; \
echo "https://kind.sigs.k8s.io/" ; \
exit 1 ; \
fi

.PHONY: check-kubectl
check-kubectl:
$(CMD_PREFIX) if [ -z "$(shell which kubectl)" ]; then \
echo "Please install kubectl" ; \
echo "https://kubernetes.io/docs/tasks/tools/#kubectl" ; \
exit 1 ; \
fi

.PHONY: load-images
load-images: ## Load images onto kind
$(CMD_PREFIX) kind load --name $(ILAB_KUBE_CLUSTER_NAME) docker-image ghcr.io/instructlab/ui/ui:main

.PHONY: stop-dev
stop-dev: check-kind ## Stop the kind cluster to destroy the development environment
$(CMD_PREFIX) kind delete cluster --name $(ILAB_KUBE_CLUSTER_NAME)

.PHONY: setup-kind
setup-kind: check-kind check-kubectl stop-dev ## Create a kind cluster with ingress enabled
$(CMD_PREFIX) kind create cluster --config ./deploy/k8s/kind.yaml
$(CMD_PREFIX) kubectl cluster-info
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) apply -f ./deploy/k8s/kind-ingress.yaml

.PHONY: wait-for-readiness
wait-for-readiness: # Wait for operators to be ready
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) -n ingress-nginx rollout restart deployment ingress-nginx-controller
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) -n ingress-nginx rollout status deployment ingress-nginx-controller --timeout=5m

.PHONY: deploy
deploy: wait-for-readiness ## Deploy a InstructLab UI development stack onto a kubernetes cluster
$(CMD_PREFIX) if [ ! -f .env ]; then \
echo "Please create a .env file in the root of the project." ; \
exit 1 ; \
fi
$(CMD_PREFIX) yes | cp -rf .env ./deploy/k8s/overlays/kind/.env
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) apply -k ./deploy/k8s/overlays/kind
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) wait --for=condition=Ready pods -n $(ILAB_KUBE_NAMESPACE) --all -l app.kubernetes.io/part-of=ui --timeout=15m

.PHONY: redeploy
redeploy: ui-image load-images ## Redeploy the InstructLab UI stack onto a kubernetes cluster
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) -n $(ILAB_KUBE_NAMESPACE) rollout restart deploy/ui

.PHONY: undeploy
undeploy: ## Undeploy the InstructLab UI stack from a kubernetes cluster
$(CMD_PREFIX) if [ -f ./deploy/k8s/overlays/kind/.env ]; then \
rm ./deploy/k8s/overlays/kind/.env ; \
fi
$(CMD_PREFIX) kubectl --context=$(ILAB_KUBE_CONTEXT) delete namespace $(ILAB_KUBE_NAMESPACE)

.PHONY: start-dev ## Run the development environment on kind
start-dev: setup-kind deploy ## Setup a kind cluster and deploy InstructLab UI on it

##@ OpenShift - UI deployment in OpenShift
.PHONY: deploy-openshift
deploy-openshift: ## Deploy the InstructLab UI on OpenShift
$(CMD_PREFIX) if [ ! -f .env ]; then \
echo "Please create a .env file in the root of the project." ; \
exit 1 ; \
fi

$(CMD_PREFIX) yes | cp -rf .env ./deploy/k8s/overlays/openshift/.env
$(CMD_PREFIX) oc apply -k ./deploy/k8s/overlays/openshift
$(CMD_PREFIX) oc wait --for=condition=Ready pods -n $(ILAB_KUBE_NAMESPACE) --all -l app.kubernetes.io/part-of=ui --timeout=15m

.PHONY: redeploy-openshift
redeploy-openshift: deploy-openshift ## Redeploy the InstructLab UI on OpenShift

.PHONY: undeploy-openshift
undeploy-openshift: ## Undeploy the InstructLab UI on OpenShift
$(CMD_PREFIX) oc delete -k ./deploy/k8s/overlays/openshift
$(CMD_PREFIX) if [ -f ./deploy/k8s/overlays/openshift/.env ]; then \
rm ./deploy/k8s/overlays/openshift/.env ; \
fi
10 changes: 10 additions & 0 deletions deploy/k8s/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: instructlab
resources:
- namespace.yaml
- ui
labels:
- includeSelectors: true
pairs:
app.kubernetes.io/part-of: ui
4 changes: 4 additions & 0 deletions deploy/k8s/base/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: instructlab
29 changes: 29 additions & 0 deletions deploy/k8s/base/ui/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: ui
spec:
replicas: 1
strategy:
type: RollingUpdate
template:
spec:
containers:
- name: ui
image: ghcr.io/instructlab/ui/ui:main
imagePullPolicy: Always
resources:
requests:
cpu: 100m
memory: 200Mi
limits:
cpu: 100m
memory: 200Mi
ports:
- name: http
protocol: TCP
containerPort: 3000
envFrom:
- secretRef:
name: ui-config
restartPolicy: Always
20 changes: 20 additions & 0 deletions deploy/k8s/base/ui/ingress-ui.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ui
spec:
tls:
- hosts:
- localhost
secretName: letsencrypt-ui
rules:
- host: localhost
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: ui
port:
number: 8080
12 changes: 12 additions & 0 deletions deploy/k8s/base/ui/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- service.yaml
- ingress-ui.yaml
labels:
- includeSelectors: true
pairs:
app.kubernetes.io/component: ui
app.kubernetes.io/instance: ui
app.kubernetes.io/name: ui
13 changes: 13 additions & 0 deletions deploy/k8s/base/ui/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: ui
spec:
clusterIP: None
selector:
app.kubernetes.io/component: ui
app.kubernetes.io/instance: ui
app.kubernetes.io/name: ui
ports:
- port: 8080
targetPort: 3000
Loading