From f300bb3705059a9020d837d4af1c20578cc96e32 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 1 Oct 2020 03:55:06 +0530 Subject: [PATCH 01/11] adding option to create and destroy kind clusters --- Makefile | 21 ++++++++++++++++++++- hack/kind-cluster.sh | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100755 hack/kind-cluster.sh diff --git a/Makefile b/Makefile index 3202601fa..53ebda618 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,10 @@ TAG=$(shell cut -d'=' -f2- .release) .DEFAULT_GOAL := build .PHONY: release git-tag check-git-status build container-image pre-build tag-image publish test system-check +# Show this help. +help: + @awk '/^#/{c=substr($$0,3);next}c&&/^[[:alpha:]][[:alnum:]_-]+:/{print substr($$1,1,index($$1,":")),c}1{c=0}' $(MAKEFILE_LIST) | column -s: -t + #Docker Tasks #Make a release release: check-git-status test container-image tag-image publish git-tag @@ -32,7 +36,7 @@ test: system-check #Build the binary build: pre-build - @cd cmd/botkube;GOOS_VAL=$(shell go env GOOS) GOARCH_VAL=$(shell go env GOARCH) go build -o $(shell go env GOPATH)/bin/botkube + @cd cmd/botkube;GOOS_VAL=$(shell go env GOOS) GOARCH_VAL=$(shell go env GOARCH) go build -o $(shell go env GOPATH)/bin/botkube @echo "Build completed successfully" #Build the image container-image: pre-build @@ -66,3 +70,18 @@ publish: @docker login @docker push $(IMAGE_REPO):$(TAG) @docker push $(IMAGE_REPO):latest + +# Install KIND +install-kind: system-check + @chmod +x hack/kind-cluster.sh + @source ./hack/kind-cluster.sh && install_kind + +# Create KIND cluster +create-kind: system-check + @chmod +x hack/kind-cluster.sh + @source ./hack/kind-cluster.sh && create_kind_cluster + +# Destroy KIND cluster +destroy-kind: system-check + @chmod +x hack/kind-cluster.sh + @source ./hack/kind-cluster.sh && destroy_kind_cluster \ No newline at end of file diff --git a/hack/kind-cluster.sh b/hack/kind-cluster.sh new file mode 100755 index 000000000..0e20f8d8e --- /dev/null +++ b/hack/kind-cluster.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Copyright (c) 2019 InfraCloud Technologies +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +set -e + +install_kind() { + echo "Installing KIND cluster" + GO111MODULE="on" go get sigs.k8s.io/kind@v0.9.0 +} + +create_kind_cluster() { + echo "creating KIND cluster" + kind create cluster +} + +destroy_kind_cluster() { + echo "destroying KIND cluster" + kind delete clusters --all +} \ No newline at end of file From 236e0c8c68a89696883bfe04bcc97bf60907d86c Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 1 Oct 2020 13:46:18 +0530 Subject: [PATCH 02/11] addressing review comments --- Makefile | 6 +++--- hack/kind-cluster.sh | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 53ebda618..4f666858e 100644 --- a/Makefile +++ b/Makefile @@ -74,14 +74,14 @@ publish: # Install KIND install-kind: system-check @chmod +x hack/kind-cluster.sh - @source ./hack/kind-cluster.sh && install_kind + @./hack/kind-cluster.sh install-kind # Create KIND cluster create-kind: system-check @chmod +x hack/kind-cluster.sh - @source ./hack/kind-cluster.sh && create_kind_cluster + @./hack/kind-cluster.sh create-kind # Destroy KIND cluster destroy-kind: system-check @chmod +x hack/kind-cluster.sh - @source ./hack/kind-cluster.sh && destroy_kind_cluster \ No newline at end of file + @./hack/kind-cluster.sh destroy-kind \ No newline at end of file diff --git a/hack/kind-cluster.sh b/hack/kind-cluster.sh index 0e20f8d8e..402302e82 100755 --- a/hack/kind-cluster.sh +++ b/hack/kind-cluster.sh @@ -33,4 +33,27 @@ create_kind_cluster() { destroy_kind_cluster() { echo "destroying KIND cluster" kind delete clusters --all -} \ No newline at end of file +} + +help() { + usage="$(basename "$0") [option] -- Script to create or destroy KIND cluster. + Available option are install-kind, destroy-kind or create-kind" + echo $usage +} + + +if [ $# -gt 1 ]; then help ;fi +case "${1}" in + install-kind) + install_kind + ;; + create-kind) + create_kind_cluster + ;; + destroy-kind) + destroy_kind_cluster + ;; + *) + help + exit 1 +esac From 1304f61c9e46555d8b7f3a53da36865777dd2156 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 1 Oct 2020 13:48:07 +0530 Subject: [PATCH 03/11] add newline --- Makefile | 2 +- hack/kind-cluster.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4f666858e..b56f37f82 100644 --- a/Makefile +++ b/Makefile @@ -84,4 +84,4 @@ create-kind: system-check # Destroy KIND cluster destroy-kind: system-check @chmod +x hack/kind-cluster.sh - @./hack/kind-cluster.sh destroy-kind \ No newline at end of file + @./hack/kind-cluster.sh destroy-kind diff --git a/hack/kind-cluster.sh b/hack/kind-cluster.sh index 402302e82..52a02730d 100755 --- a/hack/kind-cluster.sh +++ b/hack/kind-cluster.sh @@ -57,3 +57,4 @@ case "${1}" in help exit 1 esac + From 2475df13a7ccb5f1c645f6647f45266ea1ce487d Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 1 Oct 2020 13:51:18 +0530 Subject: [PATCH 04/11] add newline --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index b56f37f82..8a642fdad 100644 --- a/Makefile +++ b/Makefile @@ -85,3 +85,4 @@ create-kind: system-check destroy-kind: system-check @chmod +x hack/kind-cluster.sh @./hack/kind-cluster.sh destroy-kind + From 55878840573fe4beeeec72683a8e45679a20af1d Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 1 Oct 2020 19:49:28 +0530 Subject: [PATCH 05/11] addressing review comments --- Makefile | 3 --- hack/kind-cluster.sh | 4 +--- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 8a642fdad..2ef80dcc4 100644 --- a/Makefile +++ b/Makefile @@ -73,16 +73,13 @@ publish: # Install KIND install-kind: system-check - @chmod +x hack/kind-cluster.sh @./hack/kind-cluster.sh install-kind # Create KIND cluster create-kind: system-check - @chmod +x hack/kind-cluster.sh @./hack/kind-cluster.sh create-kind # Destroy KIND cluster destroy-kind: system-check - @chmod +x hack/kind-cluster.sh @./hack/kind-cluster.sh destroy-kind diff --git a/hack/kind-cluster.sh b/hack/kind-cluster.sh index 52a02730d..4a6574579 100755 --- a/hack/kind-cluster.sh +++ b/hack/kind-cluster.sh @@ -26,6 +26,7 @@ install_kind() { } create_kind_cluster() { + install_kind echo "creating KIND cluster" kind create cluster } @@ -44,9 +45,6 @@ help() { if [ $# -gt 1 ]; then help ;fi case "${1}" in - install-kind) - install_kind - ;; create-kind) create_kind_cluster ;; From 58af5b1efef04b96db6d98e884d17ad4962f3e3a Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 1 Oct 2020 19:52:40 +0530 Subject: [PATCH 06/11] fix comments for makefile help option --- Makefile | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 2ef80dcc4..795c27203 100644 --- a/Makefile +++ b/Makefile @@ -8,12 +8,12 @@ TAG=$(shell cut -d'=' -f2- .release) help: @awk '/^#/{c=substr($$0,3);next}c&&/^[[:alpha:]][[:alnum:]_-]+:/{print substr($$1,1,index($$1,":")),c}1{c=0}' $(MAKEFILE_LIST) | column -s: -t -#Docker Tasks -#Make a release +# Docker Tasks +# Make a release release: check-git-status test container-image tag-image publish git-tag @echo "Successfully releeased version $(TAG)" -#Create a git tag +# Create a git tag git-tag: @echo "Creating a git tag" @git add .release helm/botkube deploy-all-in-one.yaml deploy-all-in-one-tls.yaml CHANGELOG.md @@ -22,7 +22,7 @@ git-tag: @git push --tags origin develop; @echo 'Git tag pushed successfully' ; -#Check git status +# Check git status check-git-status: @echo "Checking git status" @if [ -n "$(shell git tag | grep $(TAG))" ] ; then echo 'ERROR: Tag already exists' && exit 1 ; fi @@ -34,17 +34,18 @@ test: system-check @echo "Starting unit and integration tests" @./hack/runtests.sh -#Build the binary +# Build the binary build: pre-build @cd cmd/botkube;GOOS_VAL=$(shell go env GOOS) GOARCH_VAL=$(shell go env GOARCH) go build -o $(shell go env GOPATH)/bin/botkube @echo "Build completed successfully" -#Build the image + +# Build the image container-image: pre-build @echo "Building docker image" @docker build --build-arg GOOS_VAL=$(shell go env GOOS) --build-arg GOARCH_VAL=$(shell go env GOARCH) -t $(IMAGE_REPO) -f build/Dockerfile --no-cache . @echo "Docker image build successfully" -#system checks +# system checks system-check: @echo "Checking system information" @if [ -z "$(shell go env GOOS)" ] || [ -z "$(shell go env GOARCH)" ] ; \ @@ -56,15 +57,15 @@ system-check: echo 'System information checks passed.'; \ fi ; -#Pre-build checks +# Pre-build checks pre-build: system-check -#Tag images +# Tag images tag-image: @echo 'Tagging image' @docker tag $(IMAGE_REPO) $(IMAGE_REPO):$(TAG) -#Docker push image +# Docker push image publish: @echo "Pushing docker image to repository" @docker login From a3df60d11416992b5cf1fe8ce6a594638b876015 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 1 Oct 2020 19:54:35 +0530 Subject: [PATCH 07/11] remove install kind option from make --- Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Makefile b/Makefile index 795c27203..f2a349bd5 100644 --- a/Makefile +++ b/Makefile @@ -72,10 +72,6 @@ publish: @docker push $(IMAGE_REPO):$(TAG) @docker push $(IMAGE_REPO):latest -# Install KIND -install-kind: system-check - @./hack/kind-cluster.sh install-kind - # Create KIND cluster create-kind: system-check @./hack/kind-cluster.sh create-kind From a878288e50f681f7a0ef379d806ac7ebfa0c70d5 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Fri, 2 Oct 2020 14:25:28 +0530 Subject: [PATCH 08/11] fix indentation --- hack/kind-cluster.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/hack/kind-cluster.sh b/hack/kind-cluster.sh index 4a6574579..d0b7bcd8e 100755 --- a/hack/kind-cluster.sh +++ b/hack/kind-cluster.sh @@ -26,33 +26,33 @@ install_kind() { } create_kind_cluster() { - install_kind - echo "creating KIND cluster" - kind create cluster + install_kind + echo "creating KIND cluster" + kind create cluster } destroy_kind_cluster() { - echo "destroying KIND cluster" - kind delete clusters --all + echo "destroying KIND cluster" + kind delete clusters --all } help() { - usage="$(basename "$0") [option] -- Script to create or destroy KIND cluster. - Available option are install-kind, destroy-kind or create-kind" - echo $usage + usage="$(basename "$0") [option] -- Script to create or destroy KIND cluster. + Available option are install-kind, destroy-kind or create-kind" + echo $usage } if [ $# -gt 1 ]; then help ;fi case "${1}" in - create-kind) - create_kind_cluster - ;; - destroy-kind) - destroy_kind_cluster + create-kind) + create_kind_cluster ;; - *) - help - exit 1 + destroy-kind) + destroy_kind_cluster + ;; + *) + help + exit 1 esac From 746a6b463be29ed210b9610ca88de2fda4d3f343 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Fri, 2 Oct 2020 14:27:24 +0530 Subject: [PATCH 09/11] fix indentation --- hack/kind-cluster.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/hack/kind-cluster.sh b/hack/kind-cluster.sh index d0b7bcd8e..4b93c2473 100755 --- a/hack/kind-cluster.sh +++ b/hack/kind-cluster.sh @@ -21,38 +21,38 @@ set -e install_kind() { - echo "Installing KIND cluster" - GO111MODULE="on" go get sigs.k8s.io/kind@v0.9.0 + echo "Installing KIND cluster" + GO111MODULE="on" go get sigs.k8s.io/kind@v0.9.0 } create_kind_cluster() { - install_kind - echo "creating KIND cluster" - kind create cluster + install_kind + echo "creating KIND cluster" + kind create cluster } destroy_kind_cluster() { - echo "destroying KIND cluster" - kind delete clusters --all + echo "destroying KIND cluster" + kind delete clusters --all } help() { - usage="$(basename "$0") [option] -- Script to create or destroy KIND cluster. - Available option are install-kind, destroy-kind or create-kind" - echo $usage + usage="$(basename "$0") [option] -- Script to create or destroy KIND cluster. + Available option are install-kind, destroy-kind or create-kind" + echo $usage } if [ $# -gt 1 ]; then help ;fi case "${1}" in - create-kind) - create_kind_cluster - ;; - destroy-kind) - destroy_kind_cluster - ;; - *) - help - exit 1 + create-kind) + create_kind_cluster + ;; + destroy-kind) + destroy_kind_cluster + ;; + *) + help + exit 1 esac From 62e9dd1a97049904a419d0e6f118d0df62132ad1 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 3 Oct 2020 16:04:31 +0530 Subject: [PATCH 10/11] modify script help --- hack/kind-cluster.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/kind-cluster.sh b/hack/kind-cluster.sh index 4b93c2473..94b692cbe 100755 --- a/hack/kind-cluster.sh +++ b/hack/kind-cluster.sh @@ -38,7 +38,7 @@ destroy_kind_cluster() { help() { usage="$(basename "$0") [option] -- Script to create or destroy KIND cluster. - Available option are install-kind, destroy-kind or create-kind" + Available options are destroy-kind, create-kind or help" echo $usage } From 3144142e348d62a0efb79049d32d937329bb355b Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 3 Oct 2020 18:03:28 +0530 Subject: [PATCH 11/11] create and delete kind-cicd cluster --- hack/kind-cluster.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hack/kind-cluster.sh b/hack/kind-cluster.sh index 94b692cbe..5d6328401 100755 --- a/hack/kind-cluster.sh +++ b/hack/kind-cluster.sh @@ -28,12 +28,12 @@ install_kind() { create_kind_cluster() { install_kind echo "creating KIND cluster" - kind create cluster + kind create cluster --name kind-cicd } destroy_kind_cluster() { echo "destroying KIND cluster" - kind delete clusters --all + kind delete cluster --name kind-cicd } help() {