build: add build tags to create customizable binaries

This commit is contained in:
Shivam Mishra
2020-10-14 14:47:20 -07:00
parent 17dce7e63b
commit 46beb30fc1
27 changed files with 213 additions and 92 deletions
+4
View File
@@ -3,10 +3,12 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"cli.go",
"client.go",
"config_cmd.go",
"cve_cmd.go",
"image_cmd.go",
"minimal.go",
"root.go",
"searcher.go",
"service.go",
@@ -43,11 +45,13 @@ go_test(
"//:exported_testdata",
],
embed = [":go_default_library"],
gotags = ["extended"],
race = "on",
deps = [
"//errors:go_default_library",
"//pkg/api:go_default_library",
"//pkg/compliance/v1_0_0:go_default_library",
"//pkg/extensions:go_default_library",
"@com_github_opencontainers_go_digest//:go_default_library",
"@com_github_opencontainers_image_spec//specs-go/v1:go_default_library",
"@com_github_smartystreets_goconvey//convey:go_default_library",
+11
View File
@@ -0,0 +1,11 @@
// +build extended
package cli
import "github.com/spf13/cobra"
func enableCli(rootCmd *cobra.Command) {
rootCmd.AddCommand(NewConfigCommand())
rootCmd.AddCommand(NewImageCommand(NewSearchService()))
rootCmd.AddCommand(NewCveCommand(NewSearchService()))
}
+2
View File
@@ -1,3 +1,5 @@
// +build extended
package cli
import (
+2
View File
@@ -1,3 +1,5 @@
// +build extended
package cli
import (
+2
View File
@@ -1,3 +1,5 @@
// +build extended
package cli //nolint:testpackage
import (
+2
View File
@@ -1,3 +1,5 @@
// +build extended
package cli
import (
+6 -3
View File
@@ -1,3 +1,5 @@
// +build extended
package cli //nolint:testpackage
import (
@@ -15,6 +17,7 @@ import (
zotErrors "github.com/anuvu/zot/errors"
"github.com/anuvu/zot/pkg/api"
ext "github.com/anuvu/zot/pkg/extensions"
"gopkg.in/resty.v1"
. "github.com/smartystreets/goconvey/convey"
@@ -301,13 +304,13 @@ func TestServerCVEResponse(t *testing.T) {
defer os.RemoveAll(dir)
c.Config.Storage.RootDirectory = dir
cveConfig := &api.CVEConfig{
cveConfig := &ext.CVEConfig{
UpdateInterval: 2,
}
searchConfig := &api.SearchConfig{
searchConfig := &ext.SearchConfig{
CVE: cveConfig,
}
c.Config.Extensions = &api.ExtensionConfig{
c.Config.Extensions = &ext.ExtensionConfig{
Search: searchConfig,
}
+2
View File
@@ -1,3 +1,5 @@
// +build extended
package cli
import (
+2
View File
@@ -1,3 +1,5 @@
// +build extended
package cli //nolint:testpackage
import (
+8
View File
@@ -0,0 +1,8 @@
// +build minimal
package cli
import "github.com/spf13/cobra"
func enableCli(rootCmd *cobra.Command) {
}
+1 -3
View File
@@ -97,9 +97,7 @@ func NewRootCmd() *cobra.Command {
rootCmd.AddCommand(serveCmd)
rootCmd.AddCommand(gcCmd)
rootCmd.AddCommand(NewConfigCommand())
rootCmd.AddCommand(NewImageCommand(NewSearchService()))
rootCmd.AddCommand(NewCveCommand(NewSearchService()))
enableCli(rootCmd)
rootCmd.Flags().BoolVarP(&showVersion, "version", "v", false, "show the version and exit")
+19 -17
View File
@@ -1,3 +1,5 @@
// +build extended
package cli
import (
@@ -331,6 +333,23 @@ func validateImageNameTag(input string) bool {
return true
}
type spinnerState struct {
spinner *spinner.Spinner
enabled bool
}
func (spinner *spinnerState) startSpinner() {
if spinner.enabled {
spinner.spinner.Start()
}
}
func (spinner *spinnerState) stopSpinner() {
if spinner.enabled && spinner.spinner.Active() {
spinner.spinner.Stop()
}
}
type set struct {
m map[string]struct{}
}
@@ -365,23 +384,6 @@ type stringResult struct {
Err error
}
type spinnerState struct {
spinner *spinner.Spinner
enabled bool
}
func (spinner *spinnerState) startSpinner() {
if spinner.enabled {
spinner.spinner.Start()
}
}
func (spinner *spinnerState) stopSpinner() {
if spinner.enabled && spinner.spinner.Active() {
spinner.spinner.Stop()
}
}
type printHeader func(writer io.Writer)
func printImageTableHeader(writer io.Writer) {
+2
View File
@@ -1,3 +1,5 @@
// +build extended
package cli
import (