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

adding option to create and destroy kind clusters #365

Merged
merged 17 commits into from
Oct 5, 2020
Merged
36 changes: 25 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ 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

#Docker Tasks
#Make a release
# 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
@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
Expand All @@ -18,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
Expand All @@ -30,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
@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)" ] ; \
Expand All @@ -52,17 +57,26 @@ 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
@docker push $(IMAGE_REPO):$(TAG)
@docker push $(IMAGE_REPO):latest

# Create KIND cluster
create-kind: system-check
@./hack/kind-cluster.sh create-kind

# Destroy KIND cluster
destroy-kind: system-check
@./hack/kind-cluster.sh destroy-kind

58 changes: 58 additions & 0 deletions hack/kind-cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/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() {
install_kind
echo "creating KIND cluster"
kind create cluster --name kind-cicd
}

destroy_kind_cluster() {
echo "destroying KIND cluster"
kind delete cluster --name kind-cicd
}

help() {
usage="$(basename "$0") [option] -- Script to create or destroy KIND cluster.
Available options are destroy-kind, create-kind or help"
echo $usage
}


if [ $# -gt 1 ]; then help ;fi
case "${1}" in
create-kind)
create_kind_cluster
;;
destroy-kind)
destroy_kind_cluster
;;
*)
help
exit 1
esac