Skip to content

Commit

Permalink
fix(dsl): fix display name variable & add deploy helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Neeptossss committed Dec 14, 2023
1 parent a010a92 commit b67ed5a
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 47 deletions.
7 changes: 2 additions & 5 deletions jenkins/job_dsl.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ freeStyleJob("link-project") {
preBuildCleanup()
}
steps {
environmentVariables {
env("DISPLAY_NAME", "$DISPLAY_NAME")
}
shell('echo "Building project $DISPLAY_NAME"')
shell('cp -r /whanos/scripts/* . && chmod -R 777 . && sh -c "./whanos.sh $DISPLAY_NAME"')
shell('echo "Building project $JOB_BASE_NAME"')
shell('cp -r /whanos/scripts/* . && chmod -R 777 . && sh -c "./whanos.sh $JOB_BASE_NAME"')
}
}
''')
Expand Down
Binary file removed kube/helm/whanos-1.0.0.tgz
Binary file not shown.
23 changes: 23 additions & 0 deletions kube/helm/whanos-deploy/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions kube/helm/whanos-deploy/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: whanos-deploy
description: A Whanos kube deployment with Jenkins

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
48 changes: 48 additions & 0 deletions kube/helm/whanos-deploy/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-deployment
annotations:
rollme: {{ randAlphaNum 5 | quote }}
spec:
replicas: {{ .Values.deployment.replicas }}
selector:
matchLabels:
app: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ .Release.Name }}
annotations:
rollme: {{ randAlphaNum 5 | quote }}
spec:
containers:
- name: {{ .Values.image.name }}
image: {{ .Values.image.image }}
{{- if .Values.deployment.resources }}
resources: {{ .Values.deployment.resources | toJson }}
{{- end }}
{{- if .Values.deployment.ports }}
ports:
{{- range .Values.deployment.ports }}
- containerPort: {{ . }}
{{- end }}
{{- end }}
{{- if .Values.deployment.ports }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-lb
spec:
type: LoadBalancer
ports:
{{- range .Values.deployment.ports }}
- targetPort: {{ . }}
protocol: TCP
port: {{ . }}
name: {{ . | quote }}
{{- end }}
selector:
app: {{ .Release.Name }}
{{- end }}
8 changes: 8 additions & 0 deletions kube/helm/whanos-deploy/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Default values for AutoDeploy.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

deployment:
replicas: 1
resources: {}
ports: []
15 changes: 11 additions & 4 deletions scripts/deploy_image.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash
LANGUAGE=$1
NAME=$2

image_name=$DOCKER_REGISTRY/whanos/whanos-$NAME-$LANGUAGE

if [[ -f whanos.yml ]]; then
helm upgrade -if whanos.yml "$1" /whanos/helm/AutoDeploy --set image.image=$image_name --set image.name="$1-name"
helm upgrade -if whanos.yml "$NAME" /whanos/helm/whanos-deploy --set image.image="$image_name" --set image.name="$NAME-name"

external_ip=""
ip_timeout=20
Expand All @@ -11,14 +17,15 @@ if [[ -f whanos.yml ]]; then
fi
sleep 5
echo -n "."
external_ip=$(kubectl get svc $1-lb --template="{{range .status.loadBalancer.ingress}}{{.ip}}{{end}}")
external_ip=$(kubectl get svc "$NAME"-lb --template="{{range .status.loadBalancer.ingress}}{{.ip}}{{end}}")
ip_timeout=$(($ip_timeout - 1))
done

echo "."
echo "$external_ip"
else
if helm status "$1" &> /dev/null; then
helm uninstall "$1"
exit 0
if helm status "$NAME" &> /dev/null; then
helm uninstall "$NAME"
fi
fi
22 changes: 11 additions & 11 deletions scripts/installation/all.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
#!/bin/bash
printf "Installing kubetools\n"
printf "🏗️ Installing kubetools\n"
./scripts/installation/kubetools.sh
if [ $? -ne 0 ]; then
printf "Installation of kubetools failed\n"
printf "Installation of kubetools failed\n"
exit 1
fi
printf "\n\n\nInstallation of kubetools completed successfully\n\n\n"
printf "\n\n\n✅ Installation of kubetools completed successfully\n\n\n"

printf "Installing docker registry\n"
printf "🏗️ Installing docker registry\n"
./scripts/installation/docker-registry.sh
if [ $? -ne 0 ]; then
printf "Installation of docker registry failed\n"
printf "Installation of docker registry failed\n"
exit 1
fi
printf "\n\n\nInstallation of docker registry completed successfully\n"
printf "\n\n\n✅ Installation of docker registry completed successfully\n"

printf "Installing jenkins\n"
printf "🏗️ Installing jenkins\n"
./scripts/installation/jenkins.sh
if [ $? -ne 0 ]; then
echo "Installation of jenkins failed\n"
echo "Installation of jenkins failed\n"
exit 1
fi
printf "\n\n\nInstallation of jenkins completed successfully\n"
printf "\n\n\n✅ Installation of jenkins completed successfully\n"

printf "\n\n\nINSTALLATION COMPLETED SUCCESSFULLY\n"
printf "\n\n\nINSTALLATION COMPLETED SUCCESSFULLY\n"
printf "\n\n\n\n\n"

printf "========INSTALLATION SUMMARY========\n"
./scripts/installation/installation-summary.sh
if [ $? -ne 0 ]; then
echo "Installation summary failed\n"
echo "Installation summary failed\n"
exit 1
fi
printf "====================================\n"
Expand Down
32 changes: 16 additions & 16 deletions scripts/installation/docker-registry.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/bash
printf "Installing nginx ingress controller\n"
printf "🏗️ Installing nginx ingress controller\n"
kubectl apply -f kube/init/nginx-ingress-controller/deployment.yaml
printf "Installed nginx ingress controller\n\n\n"
printf "Installed nginx ingress controller\n\n\n"

printf "Waiting for ingress controller to be ready\n"
printf "🏗️ Waiting for ingress controller to be ready\n"
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=120s
printf "Ingress controller is ready\n\n\n"
printf "Ingress controller is ready\n\n\n"

printf "Installing cert-manager\n"
printf "🏗️ Installing cert-manager\n"
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm install \
Expand All @@ -22,29 +22,29 @@ helm install \
--set ingressShim.defaultIssuerName=letsencrypt-prod \
--set ingressShim.defaultIssuerKind=ClusterIssuer \
--set ingressShim.defaultIssuerGroup=cert-manager.io
printf "Installed cert-manager\n\n\n"
printf "Installed cert-manager\n\n\n"

printf "Waiting for cert-manager to be ready"
printf "🏗️ Waiting for cert-manager to be ready"
kubectl wait --namespace cert-manager \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=webhook \
--timeout=120s
printf "Cert-manager is ready\n\n\n"
printf "Cert-manager is ready\n\n\n"

printf "Deploying cluster issuer for cert-manager\n"
printf "🏗️ Deploying cluster issuer for cert-manager\n"
kubectl apply -f kube/init/cert-manager/cluster-issuer.yaml
printf "Deployed cluster issuer for cert-manager\n\n\n"
printf "Deployed cluster issuer for cert-manager\n\n\n"

printf "Deploying docker registry\n"
printf "🏗️ Deploying docker registry\n"
kubectl apply -f kube/init/docker-registry/deployment.yaml
kubectl apply -f kube/init/docker-registry/ingress.yaml
printf "Deployed docker registry\n\n\n"
printf "Deployed docker registry\n\n\n"

printf "Adding whanos-registry.local fake DNS to /etc/hosts\n"
printf "🏗️ Adding whanos-registry.local fake DNS to /etc/hosts\n"
sh -c 'external_ip=""; while [ -z $external_ip ]; do echo "Waiting for end point..."; external_ip=$(kubectl get ingress -n docker-registry docker-registry -o jsonpath="{.status.loadBalancer.ingress[0].ip}"); [ -z "$external_ip" ] && sleep 10; done; sudo echo "End point ready" && sudo sh -c "echo $external_ip whanos-registry.local >> /etc/hosts"'
printf "Added whanos-registry.local fake DNS to /etc/hosts\n\n\n"
printf "Added whanos-registry.local fake DNS to /etc/hosts\n\n\n"

printf "Installing docker registry certificate\n"
printf "🏗️ Installing docker registry certificate\n"
sudo mkdir -p /etc/docker/certs.d/whanos-registry.local:443/
kubectl get secret registry-tls -n docker-registry -o jsonpath="{.data.ca\.crt}" | base64 --decode > /tmp/whanos-registry.local.crt && sudo mv /tmp/whanos-registry.local.crt /etc/docker/certs.d/whanos-registry.local:443/ca.crt
printf "Installed docker registry certificate\n\n\n"
printf "Installed docker registry certificate\n\n\n"
13 changes: 11 additions & 2 deletions scripts/installation/installation-summary.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#!/bin/bash
printf "🚀 You can now access your Jenkins instance at http://localhost:8080\n"
printf "🚀 You can now access your Docker registry at http://localhost:5000\n"

get_jenkins_port() {
kubectl get svc -n whanos whanos-jenkins -o jsonpath='{.spec.ports[0].nodePort}'
}

get_whanos_registry_address() {
kubectl get ingress -n docker-registry docker-registry -o jsonpath="{.status.loadBalancer.ingress[0].ip}"
}

printf "🚀 You can now access your Jenkins instance at http://localhost:%s\n" "$(get_jenkins_port)"
printf "🚀 You can now access your Docker registry at https://%s/\n" "$(get_whanos_registry_address)"
printf "🚀 You can now access your Kubernetes dashboard at http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/\n"
2 changes: 0 additions & 2 deletions scripts/installation/jenkins.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#!/bin/bash
printf "Installing jenkins\n"
helm install whanos kube/helm/whanos --create-namespace --namespace whanos
printf "Installed jenkins ✅\n\n\n"
12 changes: 6 additions & 6 deletions scripts/installation/kubetools.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/bin/bash
printf "Installing kubectl\n"
printf "🏗️ Installing kubectl\n"
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
printf 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl
printf "Installed kubectl\n\n\n"
printf "Installed kubectl\n\n\n"

printf "Configuring kubectl\n"
printf "🏗️ Configuring kubectl\n"
mkdir -p ~/.kube
sudo cp /etc/kubernetes/admin.conf ~/.kube/config
sudo chown $(id -u):$(id -g) ~/.kube/config
printf "Configured kubectl\n\n\n"
printf "Configured kubectl\n\n\n"

printf "Installing helm\n"
printf "🏗️ Installing helm\n"
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
printf "Installed helm\n\n\n"
printf "Installed helm\n\n\n"
2 changes: 1 addition & 1 deletion scripts/whanos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if [ $? -ne 0 ]; then
fi

# Execute deploy_image.sh script
./deploy_image.sh
./deploy_image.sh "$language" "$DISPLAY_NAME"
if [ $? -ne 0 ]; then
echo "deploy_image.sh failed"
exit 1
Expand Down

0 comments on commit b67ed5a

Please sign in to comment.