Skip to content

Commit

Permalink
Merge pull request #32 from bharathappali/add-manifests
Browse files Browse the repository at this point in the history
Add manifests
  • Loading branch information
dinogun authored Aug 11, 2023
2 parents d4f9732 + b6eed77 commit ede2860
Show file tree
Hide file tree
Showing 16 changed files with 403 additions and 185 deletions.
41 changes: 14 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,27 @@
FROM node:16 AS builder

WORKDIR /builder

RUN npm config set legacy-peer-deps true

COPY package.json ./

RUN npm install
WORKDIR /app

COPY . ./

COPY deploy.sh /deploy.sh

RUN ./deploy.sh -c

FROM registry.access.redhat.com/ubi8/nginx-118
RUN npm config set legacy-peer-deps true \
&& npm install \
&& KRUIZE_UI_ENV=production npm run build

USER root
FROM nginx:latest

COPY --from=builder /builder/dist/* /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf \
&&mkdir -p /var/cache/nginx/client_temp /var/run/nginx \
&& chown -R nginx:nginx /var/cache/nginx /var/run/nginx \
&& touch /var/run/nginx.pid \
&& chown nginx:nginx /var/run/nginx.pid

#RUN rm -rf /etc/nginx/conf.d/default.conf
# Switch to the non-root user
USER nginx

#COPY ./nginx.conf /etc/nginx/conf.d

#USER default
COPY --from=builder /app/dist/* /usr/share/nginx/html/

EXPOSE 80

# WORKDIR /etc/nginx

# RUN cp nginx.conf /tmp
# RUN sed -i 's|listen \[::\]:8080 default_server|listen 8080|' /tmp/nginx.conf
# RUN sed -i 's|listen 8080 default_server;||' /tmp/nginx.conf
# RUN cat /tmp/nginx.conf >nginx.conf


CMD ["nginx", "-g", "daemon off;"]

#ENTRYPOINT ["nginx", "-g", "daemon off;"]
8 changes: 0 additions & 8 deletions Nginx/Dockerfile

This file was deleted.

24 changes: 0 additions & 24 deletions Nginx/nginx.conf

This file was deleted.

93 changes: 91 additions & 2 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
#!/bin/bash

export KRUIZE_UI_IMAGE="quay.io/kruize/kruize-ui:0.0.1"
KRUIZE_UI_MANIFEST_FILE="kruize-ui-nginx-setup.yaml"
MANIFEST_TEMPLATE="./manifests/templates/kruize-ui-nginx-setup-template.yaml"

launch_to_kube_with_image=false
is_image_set=false
image_name=""

POD_NAME="kruize-ui-nginx-pod"
SERVICE_NAME="kruize-ui-nginx-service"
NAMESPACE="monitoring"

function start_gui_dev_mode() {
if ! command -v npm
then
Expand All @@ -14,7 +27,57 @@ function start_gui_docker_mode() {
npm run build
}

while getopts ":dc" gopts;
# Check the status of a pod
function check_pod_status() {
local status=$(kubectl get pods -n "$NAMESPACE" "$POD_NAME" -o jsonpath='{.status.phase}')

if [[ "${status}" == "Running" ]]; then
echo "Pod ${POD_NAME} is running."
else
echo "Pod ${POD_NAME} is not running. Status: ${status}. Exiting"
exit 1
fi
}

function launch_gui_kube_mode() {
if [ -f "./manifests/dynamic/kruize-ui-nginx-setup.yaml" ]; then
# Remove existing deployments
kubectl delete -f ./manifests/dynamic/
fi

if ${is_image_set}; then
unset KRUIZE_UI_IMAGE
export KRUIZE_UI_IMAGE="${image_name}"
fi

export KRUIZE_UI_NAMESPACE="${NAMESPACE}"

envsubst < ./manifests/templates/kruize-ui-nginx-setup-template.yaml > "./manifests/dynamic/${KRUIZE_UI_MANIFEST_FILE}"

echo ${manifest_file_content}

# Re-Launch the UI deployment
kubectl apply -f ./manifests/dynamic/

# Sleep for 10 secs for UI to come up
echo -n "Waiting for 10 secs for UI pod to start "
for ((i = 0; i < 10; i++)); do
echo -n "."
sleep 1
done

echo " Done."
echo "Checking pod status"
check_pod_status

port=$(kubectl -n ${NAMESPACE} get services | grep "${SERVICE_NAME}" | awk '{print $5}' | cut -d':' -f2 | cut -d'/' -f1)

echo "Kruize UI is running on port: ${port}"
}



while getopts ":dcki:e:" gopts;
do
case ${gopts} in
d)
Expand All @@ -25,8 +88,34 @@ while getopts ":dc" gopts;
start_gui_docker_mode
echo "docker mode"
;;
k)
launch_to_kube_with_image=true
echo "Launching to Kubernetes"
;;
i)
is_image_set=true
image_name="${OPTARG}"
;;
e)
case "${OPTARG}" in
minikube)
NAMESPACE="monitoring"
;;
openshift)
NAMESPACE="openshift-tuning"
;;
*)
echo "Invalid value for option -e. Use 'minikube' or 'openshift'."
exit 1
;;
esac
;;
\?)
echo "exit, use d or c options"
echo "exit, use d, c, or k (with i for passing image) options"
;;
esac
done

if ${launch_to_kube_with_image}; then
launch_gui_kube_mode
fi
68 changes: 68 additions & 0 deletions manifests/dynamic/kruize-ui-nginx-setup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
namespace: monitoring
data:
nginx.conf: |
events {}
http {
upstream kruize-api {
server kruize:8080;
}
server {
listen 8080;
server_name localhost;
root /usr/share/nginx/html;
location ^~ /api/ {
rewrite ^/api(.*)$ $1 break;
proxy_pass http://kruize-api;
}
location / {
index index.html;
error_page 404 =200 /index.html;
}
}
}
---
apiVersion: v1
kind: Service
metadata:
name: kruize-ui-nginx-service
namespace: monitoring
spec:
type: NodePort
ports:
- name: http
port: 8080
targetPort: 8080
selector:
app: kruize-ui-nginx
---
apiVersion: v1
kind: Pod
metadata:
name: kruize-ui-nginx-pod
namespace: monitoring
labels:
app: kruize-ui-nginx
spec:
containers:
- name: kruize-ui-nginx-container
image: quay.io/kruize/kruize-ui:0.0.1
imagePullPolicy: Always
env:
- name: KRUIZE_UI_ENV
value: "production"
volumeMounts:
- name: nginx-config-volume
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: nginx-config-volume
configMap:
name: nginx-config
63 changes: 63 additions & 0 deletions manifests/static/kruize-ui-nginx-setup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
namespace: monitoring
data:
nginx.conf: |
events {}
http {
upstream kruize-api {
server kruize:8080;
}
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /api/ {
rewrite ^/api(.*)$ $1 break;
proxy_pass http://kruize-api;
}
}
}
---
apiVersion: v1
kind: Service
metadata:
name: kruize-ui-nginx-service
namespace: monitoring
spec:
type: NodePort
ports:
- name: http
port: 80
targetPort: 80
nodePort: 32323
selector:
app: kruize-ui-nginx
---
apiVersion: v1
kind: Pod
metadata:
name: kruize-ui-nginx-pod
namespace: monitoring
labels:
app: kruize-ui-nginx
spec:
containers:
- name: kruize-ui-nginx-container
image: quay.io/kruize/kruize-ui:0.0.1
volumeMounts:
- name: nginx-config-volume
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: nginx-config-volume
configMap:
name: nginx-config
Loading

0 comments on commit ede2860

Please sign in to comment.