Added git tag and docker images versioning support with Makefile.

Updated travis to use Makefile.
Removed @botkube help commands.
This commit is contained in:
mugdha-adhav 2019-03-05 19:19:27 +05:30
parent 1769d47e1e
commit 661083777c
6 changed files with 59 additions and 73 deletions

1
.release Normal file
View File

@ -0,0 +1 @@
release=1.0.0

View File

@ -11,7 +11,7 @@ install:
- go get -u golang.org/x/lint/golint
- curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh
- chmod +x get_helm.sh
- sudo ./get_helm.sh
- ./get_helm.sh
before_script:
- hack/verify-gofmt.sh
@ -21,4 +21,4 @@ before_script:
- helm lint helm/botkube
script:
- build/docker.sh infracloudio/botkube latest
- make

51
Makefile Normal file
View File

@ -0,0 +1,51 @@
IMAGE_REPO=infracloud/botkube
TAG=$(shell cut -d'=' -f2- .release)
.DEFAULT_GOAL := build
.PHONY: release git-tag check-git-status build pre-build tag-image publish
#Docker Tasks
#Make a release
release: check-git-status build tag-image publish git-tag
@echo "Successfully released version $(TAG)"
#Create a git tag
git-tag:
@echo "Creating a git tag"
@git add .
@git commit -m "Bumped to version $(TAG)" ;
@git tag $(TAG) ;
@git push --tags origin master;
@echo 'Git tag pushed successfully' ;
#Check git status
check-git-status:
@echo "Checking git status"
@if [ -n "$(shell git tag | grep $(TAG))" ] ; then echo 'Tag already exists' && exit 1 ; fi
@if [ -z "$(shell git remote -v)" ] ; then echo 'No remote to push tags to' && exit 1 ; fi
@if [ -z "$(shell git config user.email)" ] ; then echo 'Unable to detect git credentials' && exit 1 ; fi
#Build the image
build: 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"
#Pre-build checks
pre-build:
@echo "Checking system information"
@if [ -z "$(shell go env GOOS)" ] || [ -z "$(shell go env GOARCH)" ] ; then echo 'Could not determine the system architecture.' && exit 1 ; fi
#Tag images
tag-image:
@echo 'Tagging image'
@docker tag $(IMAGE_REPO) $(IMAGE_REPO):$(TAG)
@docker tag $(IMAGE_REPO) $(IMAGE_REPO):latest
#Docker push image
publish:
@echo "Pushing docker image to repository"
@docker login
@docker push $(IMAGE_REPO):$(TAG)
@docker push $(IMAGE_REPO):latest

View File

@ -1,13 +0,0 @@
set +x
BUILD_ROOT=$(dirname $0)
IMAGE_REPO=${1:-infracloud/botkube}
IMAGE_TAG=${2:-latest}
[ ! -z $(go env GOOS) ] && [ ! -z $(go env GOARCH) ] && \
GOOS=$(go env GOOS) && GOARCH=$(go env GOARCH) || \
echo "Couldn't determine the system architecture."
pushd ${BUILD_ROOT}/..
docker build --build-arg GOOS_VAL=${GOOS} --build-arg GOARCH_VAL=${GOARCH} -t $IMAGE_REPO:$IMAGE_TAG -f ${BUILD_ROOT}/Dockerfile --no-cache .
popd

View File

@ -6,7 +6,7 @@ replicaCount: 1
image:
repository: infracloud/botkube
tag: "0.4"
tag: "latest"
pullPolicy: Always
nameOverride: ""

View File

@ -32,16 +32,13 @@ var validNotifierCommand = map[string]bool{
var validPingCommand = map[string]bool{
"ping": true,
}
var validHelpCommand = map[string]bool{
"help": true,
}
var kubectlBinary = "/usr/local/bin/kubectl"
const (
notifierStartMsg = "Brace yourselves, notifications are coming from cluster '%s'."
notifierStopMsg = "Sure! I won't send you notifications from cluster '%s' anymore."
unsupportedCmdMsg = "Command not supported. Please run '@BotKube help' to see supported commands."
unsupportedCmdMsg = "Command not supported. Please run /botkubehelp to see supported commands."
kubectlDisabledMsg = "Sorry, the admin hasn't given me the permission to execute kubectl command on cluster '%s'."
)
@ -116,60 +113,10 @@ func (e *DefaultExecutor) Execute() string {
if validPingCommand[args[0]] {
return runPingCommand(args, e.ClusterName)
}
if validHelpCommand[args[0]] {
return printHelp(e.ChannelName)
if e.IsAuthChannel {
return unsupportedCmdMsg
}
return unsupportedCmdMsg
}
func printHelp(channelName string) string {
kubecltCmdKeys := make([]string, 0, len(validKubectlCommands))
for cmd := range validKubectlCommands {
kubecltCmdKeys = append(kubecltCmdKeys, cmd)
}
allowedKubectl := strings.Join(kubecltCmdKeys, ", ")
helpMsg := `
BotKube Help
Usage:
@BotKube <kubectl command without kubectl prefix> [--cluster-name <cluster_name>]
@BotKube notifier [stop|start|status|showconfig]
@BotKube ping [--cluster-name <cluster-name>]
Description:
Kubectl commands:
- Executes kubectl commands on k8s cluster and returns output.
Example:
@BotKube get pods
@BotKube logs podname -n namespace
@BotKube get deployment --cluster-name cluster_name
Allowed kubectl commands:
%s
Cluster Status:
- List all available Kubernetes Clusters and check connection health.
- If flag specified, gives response from the specified cluster.
Example:
@BotKube ping
@BotKube ping --cluster-name mycluster
Notifier commands:
- Commands to manage notifier (Runs only on configured channel %s).
Example:
@BotKube notifier stop Stop sending k8s event notifications to Slack
@BotKube notifier start Start sending k8s event notifications to Slack
@BotKube notifier status Show running status of event notifier
@BotKube notifier showconfig Show BotKube configuration for event notifier
Options:
--cluster-name Get cluster specific response
`
return fmt.Sprintf(helpMsg, allowedKubectl, channelName)
return ""
}
func printDefaultMsg() string {