diff --git a/jenkins/job_dsl.groovy b/jenkins/job_dsl.groovy index b6789dd..e6794e5 100755 --- a/jenkins/job_dsl.groovy +++ b/jenkins/job_dsl.groovy @@ -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"') } } ''') diff --git a/kube/helm/whanos-1.0.0.tgz b/kube/helm/whanos-1.0.0.tgz deleted file mode 100644 index 03d7379..0000000 Binary files a/kube/helm/whanos-1.0.0.tgz and /dev/null differ diff --git a/kube/helm/whanos-deploy/.helmignore b/kube/helm/whanos-deploy/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/kube/helm/whanos-deploy/.helmignore @@ -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/ diff --git a/kube/helm/whanos-deploy/Chart.yaml b/kube/helm/whanos-deploy/Chart.yaml new file mode 100644 index 0000000..3e7fb4e --- /dev/null +++ b/kube/helm/whanos-deploy/Chart.yaml @@ -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" \ No newline at end of file diff --git a/kube/helm/whanos-deploy/templates/deployment.yaml b/kube/helm/whanos-deploy/templates/deployment.yaml new file mode 100644 index 0000000..675251d --- /dev/null +++ b/kube/helm/whanos-deploy/templates/deployment.yaml @@ -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 }} \ No newline at end of file diff --git a/kube/helm/whanos-deploy/values.yaml b/kube/helm/whanos-deploy/values.yaml new file mode 100644 index 0000000..49f68dc --- /dev/null +++ b/kube/helm/whanos-deploy/values.yaml @@ -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: [] \ No newline at end of file diff --git a/scripts/deploy_image.sh b/scripts/deploy_image.sh index 7d709dd..499fb9e 100644 --- a/scripts/deploy_image.sh +++ b/scripts/deploy_image.sh @@ -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 @@ -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 diff --git a/scripts/installation/all.sh b/scripts/installation/all.sh index 9d6bf90..97e02d8 100755 --- a/scripts/installation/all.sh +++ b/scripts/installation/all.sh @@ -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" diff --git a/scripts/installation/docker-registry.sh b/scripts/installation/docker-registry.sh index 49e2ea5..8d5d903 100755 --- a/scripts/installation/docker-registry.sh +++ b/scripts/installation/docker-registry.sh @@ -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 \ @@ -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" \ No newline at end of file +printf "āœ… Installed docker registry certificate\n\n\n" \ No newline at end of file diff --git a/scripts/installation/installation-summary.sh b/scripts/installation/installation-summary.sh index adf6fc5..5031d8d 100755 --- a/scripts/installation/installation-summary.sh +++ b/scripts/installation/installation-summary.sh @@ -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" \ No newline at end of file diff --git a/scripts/installation/jenkins.sh b/scripts/installation/jenkins.sh index a35f08c..8a0d701 100755 --- a/scripts/installation/jenkins.sh +++ b/scripts/installation/jenkins.sh @@ -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" diff --git a/scripts/installation/kubetools.sh b/scripts/installation/kubetools.sh index fc2bf42..a68b4c0 100755 --- a/scripts/installation/kubetools.sh +++ b/scripts/installation/kubetools.sh @@ -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" \ No newline at end of file +printf "āœ… Installed helm\n\n\n" \ No newline at end of file diff --git a/scripts/whanos.sh b/scripts/whanos.sh index 8630d61..2463840 100644 --- a/scripts/whanos.sh +++ b/scripts/whanos.sh @@ -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