Skip to content

Commit

Permalink
Merge pull request #45 from infracloudio/infracloudio/add-Makefile
Browse files Browse the repository at this point in the history
Issue #46: Removed @botkube help commands. Added Makefile to add support for git tags and docker build with versioning
  • Loading branch information
PrasadG193 authored Mar 7, 2019
2 parents 4d9e227 + 6610837 commit 775417c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 73 deletions.
1 change: 1 addition & 0 deletions .release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
release=1.0.0
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,4 +21,4 @@ before_script:
- helm lint helm/botkube

script:
- build/docker.sh infracloudio/botkube latest
- make
51 changes: 51 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
13 changes: 0 additions & 13 deletions build/docker.sh

This file was deleted.

2 changes: 1 addition & 1 deletion helm/botkube/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ replicaCount: 1

image:
repository: infracloud/botkube
tag: "0.4"
tag: "latest"
pullPolicy: Always

nameOverride: ""
Expand Down
61 changes: 4 additions & 57 deletions pkg/execute/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'."
)

Expand Down Expand Up @@ -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)
}
return unsupportedCmdMsg
}

func printHelp(channelName string) string {
kubecltCmdKeys := make([]string, 0, len(validKubectlCommands))
for cmd := range validKubectlCommands {
kubecltCmdKeys = append(kubecltCmdKeys, cmd)
if e.IsAuthChannel {
return unsupportedCmdMsg
}
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 {
Expand Down

0 comments on commit 775417c

Please sign in to comment.