Skip to content

Commit

Permalink
feat: new cli with cobra
Browse files Browse the repository at this point in the history
  • Loading branch information
mlabouardy committed Nov 13, 2022
1 parent 4dd8441 commit 94d0eef
Show file tree
Hide file tree
Showing 41 changed files with 2,035 additions and 868 deletions.
26 changes: 11 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,31 @@ jobs:
command: mv /tmp/dashboard/out .
- run:
name: Create assets
command: go-bindata-assetfs -o template.go out/...
- run:
name: Install gox
command: go install github.com/mitchellh/gox@latest
command: |
go-bindata-assetfs -o internal/api/v1/template.go out/...
sed -i -e 's/package main/package v1/g' internal/api/v1/template.go
- run:
name: Build binary
no_output_timeout: 20m
command: |
gox -osarch="linux/amd64"
gox -osarch="windows/amd64"
gox -osarch="darwin/amd64"
make build
make package
- run:
name: Install AWS CLI
command: |
apt-get update
apt-get install -y awscli
chmod +x komiser_windows_amd64.exe komiser_darwin_amd64 komiser_linux_amd64
chmod +x bin/komiser_windows_amd64.exe bin/komiser_darwin_amd64 bin/komiser_darwin_arm64 bin/komiser_linux_amd64
- run:
name: Push Linux binary
command: aws s3 cp komiser_linux_amd64 s3://komiser-releases/3.0.0/linux/komiser --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
command: aws s3 cp bin/komiser_linux_amd64 s3://komiser-releases/3.0.0/linux/komiser --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
- run:
name: Push Windows binary
command: aws s3 cp komiser_windows_amd64.exe s3://komiser-releases/3.0.0/windows/komiser --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
command: aws s3 cp bin/komiser_windows_amd64.exe s3://komiser-releases/3.0.0/windows/komiser --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
- run:
name: Push Mac OS X binary
command: aws s3 cp komiser_darwin_amd64 s3://komiser-releases/3.0.0/osx/komiser --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
- run:
name: Upload IAM policy
command: aws s3 cp policy.json s3://komiser-releases/policy.json --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
command: |
aws s3 cp bin/komiser_darwin_amd64 s3://komiser-releases/3.0.0/osx/amd/komiser --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
aws s3 cp bin/komiser_darwin_arm64 s3://komiser-releases/3.0.0/osx/arm/komiser --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
build_docker:
docker:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ tmp
credentials
main
config.toml
_
_
out
bin
38 changes: 35 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
# Build all
.PHONY: build
build:
./scripts/build.sh
VERSION := $(shell git rev-parse --abbrev-ref HEAD)
BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
COMMIT := $(shell git rev-parse --short HEAD)

EXECUTABLE=komiser

GO_LD_FLAGS += -X github.com/mlabouardy/komiser/internal.Version=$(VERSION)
GO_LD_FLAGS += -X github.com/mlabouardy/komiser/internal.Buildtime=$(BUILDTIME)
GO_LD_FLAGS += -X github.com/mlabouardy/komiser/internal.Commit=$(COMMIT)
GO_FLAGS = -ldflags "$(GO_LD_FLAGS)"

build: ## Build for the current platform
go build -o bin/$(EXECUTABLE) $(GO_FLAGS) .
@echo built: bin/$(EXECUTABLE)
@echo version: $(VERSION)
@echo commit: $(COMMIT)

package: ## Build for all platforms
env GOOS=windows GOARCH=amd64 go build -o bin/$(EXECUTABLE)_windows_amd64.exe $(GO_FLAGS) .
env GOOS=linux GOARCH=amd64 go build -o bin/$(EXECUTABLE)_linux_amd64 $(GO_FLAGS) .
env GOOS=darwin GOARCH=amd64 go build -o bin/$(EXECUTABLE)_darwin_amd64 $(GO_FLAGS) .
env GOOS=darwin GOARCH=arm64 go build -o bin/$(EXECUTABLE)_darwin_arm64 $(GO_FLAGS) .
@echo built: bin/$(EXECUTABLE)_windows_amd64.exe, bin/$(EXECUTABLE)_linux_amd64, bin/$(EXECUTABLE)_darwin_amd64, bin/$(EXECUTABLE)_darwin_arm64
@echo version: $(VERSION)
@echo commit: $(COMMIT)

test: ## Run tests
go test -v ./...

version:
@echo version: $(VERSION)

clean: ## Remove previous builds and clear test cache
rm -f bin/$(EXECUTABLE)*
go clean -testcache
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ brew install komiser
- [Connect Komiser CLI to your AWS account.](#connect-komiser-cli-to-your-aws-account)
- [Deploy Komiser to single account access EKS cluster (Helm chart)](#deploy-komiser-to-single-account-access-eks-cluster-helm-chart)
- [Deploy Komiser to a multi account access EKS cluster (Helm chart)](#deploy-komiser-to-a-multi-account-access-eks-cluster-helm-chart)
- [Installtion on GCP](#installtion-on-gcp)
- [Instalation on Azure](#instalation-on-azure)
- [Installation on GCP](#installation-on-gcp)
- [Installation on Azure](#installation-on-azure)
- [Installation on Digital Ocean](#installation-on-digital-ocean)
- [Installation on OVH](#installation-on-ovh)
- [Documentation](#documentation)
Expand All @@ -59,7 +59,7 @@ brew install komiser
<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# What is Komiser?
Komiser is an open source project created in 2017. Created to **analyse** and **manage cloud cost**, **usage**, **security** and **governance** all in one place. With komiser you can also:
Komiser is an open source project created to **analyse** and **manage cloud cost**, **usage**, **security** and **governance** all in one place. With komiser you can also:
* Control your **resource usage** and gain visibility across all used services to achieve maximum cost-effectiveness.
* Detect **potential vulnerabilities** that could put your cloud environment at risk.
* Get a deep understanding of **how you spend** on the AWS, GCP, OVH, DigitalOcean and Azure.
Expand All @@ -85,11 +85,11 @@ Below are the available downloads for the latest version of Komiser (2.11.0). Pl
### Deploy Komiser to a multi account access EKS cluster (Helm chart)
* If you are would like to connect various AWS accounts to a Komiser deployment in a Management EKS cluster, follow the steps [here](https://docs.komiser.io/docs/Cloud%20Providers/aws#multiple-account-eks-helm-chart-installation).

## Installtion on GCP
## Installation on GCP

Connect a local deployment of Komiser CLI to your [**GCP**](https://docs.komiser.io/docs/Cloud%20Providers/gcp) account.

## Instalation on Azure
## Installation on Azure

Connect a local deployment of Komiser CLI to you [**Azure**](https://docs.komiser.io/docs/Cloud%20Providers/azure) account.

Expand Down
24 changes: 24 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"os"

"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "komiser",
Short: "Cloud environment inspector",
Long: `Komiser enables you to have a clear view into your cloud account,
gives helpful advice to reduce the cost and secure your environment.`,
}

func Execute() {
rootCmd.CompletionOptions.HiddenDefaultCmd = true
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

func init() {}
67 changes: 67 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package cmd

import (
"errors"

"github.com/mlabouardy/komiser/internal"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var startCmd = &cobra.Command{
Use: "start",
Short: "Run Komiser server",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
file, err := cmd.Flags().GetString("config")
if err != nil {
return err
}
if file == "" {
return errors.New("you must specify a manifest with '--config path/url'")
}

regions, err := cmd.Flags().GetStringArray("regions")
if err != nil {
return err
}

verbose, _ := cmd.Flags().GetBool("verbose")
setupLogging(verbose)

noTracking, _ := cmd.Flags().GetBool("no-tracking")
if noTracking {
log.Info("Tracking has been disabled")
}

port, err := cmd.Flags().GetInt("port")
if err != nil {
return err
}

err = internal.Exec(port, file, noTracking, regions, cmd)
if err != nil {
return err
}

return nil
},
}

func init() {
rootCmd.AddCommand(startCmd)
startCmd.PersistentFlags().Int("port", 3000, `Port to start server on, default:"3000".`)
startCmd.PersistentFlags().StringArray("regions", []string{}, "Restrict Komiser inspection to list of regions.")
startCmd.PersistentFlags().String("config", "", "Path to configuration file.")
startCmd.PersistentFlags().Bool("verbose", true, "Show verbose debug information.")
startCmd.PersistentFlags().Bool("no-tracking", false, "Disable user analytics.")
}

func setupLogging(verbose bool) {
if verbose {
log.SetLevel(log.DebugLevel)
log.Debugf("Debug logging is enabled")
} else {
log.SetLevel(log.InfoLevel)
}
}
32 changes: 32 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"fmt"

"github.com/mlabouardy/komiser/internal"
"github.com/spf13/cobra"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "Show tool version",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Komiser")
showLine(cmd, "Version", internal.Version)
showLine(cmd, "Go version", internal.GoVersion)
showLine(cmd, "Commit", internal.Commit)
showLine(cmd, "OS/Arch", fmt.Sprintf("%s/%s", internal.Os, internal.Arch))
showLine(cmd, "Built", internal.Buildtime)
},
}

func showLine(cmd *cobra.Command, title string, value string) {
cmd.Printf(" %-16s %s\n", fmt.Sprintf("%s:", cases.Title(language.Und, cases.NoLower).String(title)), value)
}

func init() {
rootCmd.AddCommand(versionCmd)
}
3 changes: 2 additions & 1 deletion dashboard/environments/environment-production.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const environment = {
production: true,
API_URL: ''
API_URL: '',
GA_TRACKING_ID: 'G-9HF3HT6S6W'
};

export default environment;
3 changes: 2 additions & 1 deletion dashboard/environments/environment-sandbox.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const environment = {
production: false,
API_URL: ''
API_URL: '',
GA_TRACKING_ID: 'G-9HF3HT6S6W'
};

export default environment;
3 changes: 2 additions & 1 deletion dashboard/environments/environment-staging.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const environment = {
production: false,
API_URL: ''
API_URL: '',
GA_TRACKING_ID: 'G-9HF3HT6S6W'
};

export default environment;
3 changes: 2 additions & 1 deletion dashboard/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const environment = {
production: false,
API_URL: 'http://localhost:3000'
API_URL: 'http://localhost:3000',
GA_TRACKING_ID: 'G-9HF3HT6S6W'
};

export default environment;
37 changes: 14 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,68 @@ module github.com/mlabouardy/komiser
go 1.17

require (
github.com/BurntSushi/toml v1.2.1
github.com/aws/aws-sdk-go-v2 v1.17.1
github.com/aws/aws-sdk-go-v2/config v1.15.14
github.com/aws/aws-sdk-go-v2/service/cloudfront v1.20.7
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.17.3
github.com/aws/aws-sdk-go-v2/service/ec2 v1.50.0
github.com/aws/aws-sdk-go-v2/service/ecr v1.17.20
github.com/aws/aws-sdk-go-v2/service/ecs v1.18.26
github.com/aws/aws-sdk-go-v2/service/eks v1.21.4
github.com/aws/aws-sdk-go-v2/service/iam v1.18.9
github.com/aws/aws-sdk-go-v2/service/lambda v1.23.4
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.1
github.com/aws/aws-sdk-go-v2/service/sns v1.18.3
github.com/aws/aws-sdk-go-v2/service/sqs v1.19.12
github.com/aws/aws-sdk-go-v2/service/sts v1.16.9
github.com/digitalocean/godo v1.88.0
github.com/elazarl/go-bindata-assetfs v1.0.1
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/hashicorp/go-version v1.6.0
github.com/oracle/oci-go-sdk v24.3.0+incompatible
github.com/rs/cors v1.8.2
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
github.com/uptrace/bun v1.1.8
github.com/uptrace/bun/dialect/pgdialect v1.1.8
github.com/uptrace/bun/driver/pgdriver v1.1.8
github.com/urfave/cli v1.22.9
gopkg.in/ini.v1 v1.67.0
golang.org/x/text v0.4.0
)

require (
cloud.google.com/go/compute v1.12.1 // indirect
cloud.google.com/go/compute/metadata v0.2.1 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.3 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.12.9 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.8 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.25 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.19 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ecr v1.17.20 // indirect
github.com/aws/aws-sdk-go-v2/service/ecs v1.18.26 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.10 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.9 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.19 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.8 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.8 // indirect
github.com/aws/aws-sdk-go-v2/service/sns v1.18.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sqs v1.19.12 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.11.12 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.16.9 // indirect
github.com/aws/smithy-go v1.13.4 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/digitalocean/godo v1.88.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.6.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/oracle/oci-go-sdk v24.3.0+incompatible // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d // indirect
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
google.golang.org/api v0.102.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
mellium.im/sasl v0.3.0 // indirect
Expand Down
Loading

0 comments on commit 94d0eef

Please sign in to comment.