mirror of
https://github.com/project-zot/zot.git
synced 2024-12-16 21:56:37 -05:00
refactor: Reduce zli binary size (#1805)
Signed-off-by: Alexei Dodon <adodon@cisco.com>
This commit is contained in:
parent
8e18917b07
commit
f58597ade9
45 changed files with 166 additions and 155 deletions
26
.github/workflows/compare-binary-size.yml
vendored
26
.github/workflows/compare-binary-size.yml
vendored
|
@ -33,7 +33,7 @@ jobs:
|
||||||
|
|
||||||
echo "PR binary size: $BINSIZE Bytes"
|
echo "PR binary size: $BINSIZE Bytes"
|
||||||
echo "main branch binary size: $BINSIZE_MAIN Bytes"
|
echo "main branch binary size: $BINSIZE_MAIN Bytes"
|
||||||
[[ $BINSIZE -eq $BINSIZE_MAIN ]] && echo "zot-minimal binary size is not affected by PR" && exit 0
|
[[ $BINSIZE -eq $BINSIZE_MAIN ]] && echo "zot-minimal binary size is not affected by PR" && exit 0
|
||||||
|
|
||||||
if [[ $BINSIZE -gt $BINSIZE_MAIN ]]; then \
|
if [[ $BINSIZE -gt $BINSIZE_MAIN ]]; then \
|
||||||
PERCENTAGE=$(echo "scale=2; (($BINSIZE-$BINSIZE_MAIN)*100)/$BINSIZE_MAIN" | bc); \
|
PERCENTAGE=$(echo "scale=2; (($BINSIZE-$BINSIZE_MAIN)*100)/$BINSIZE_MAIN" | bc); \
|
||||||
|
@ -58,7 +58,7 @@ jobs:
|
||||||
|
|
||||||
echo "PR binary size: $BINSIZE Bytes"
|
echo "PR binary size: $BINSIZE Bytes"
|
||||||
echo "main branch binary size: $BINSIZE_MAIN Bytes"
|
echo "main branch binary size: $BINSIZE_MAIN Bytes"
|
||||||
[[ $BINSIZE -eq $BINSIZE_MAIN ]] && echo "zb binary size is not affected by PR" && exit 0
|
[[ $BINSIZE -eq $BINSIZE_MAIN ]] && echo "zb binary size is not affected by PR" && exit 0
|
||||||
|
|
||||||
if [[ $BINSIZE -gt $BINSIZE_MAIN ]]; then \
|
if [[ $BINSIZE -gt $BINSIZE_MAIN ]]; then \
|
||||||
PERCENTAGE=$(echo "scale=2; (($BINSIZE-$BINSIZE_MAIN)*100)/$BINSIZE_MAIN" | bc); \
|
PERCENTAGE=$(echo "scale=2; (($BINSIZE-$BINSIZE_MAIN)*100)/$BINSIZE_MAIN" | bc); \
|
||||||
|
@ -68,6 +68,28 @@ jobs:
|
||||||
PERCENTAGE=$(echo "scale=2; (($BINSIZE_MAIN-$BINSIZE)*100)/$BINSIZE_MAIN" | bc); \
|
PERCENTAGE=$(echo "scale=2; (($BINSIZE_MAIN-$BINSIZE)*100)/$BINSIZE_MAIN" | bc); \
|
||||||
echo "zb binary decreased by $PERCENTAGE% comparing with main"; \
|
echo "zb binary decreased by $PERCENTAGE% comparing with main"; \
|
||||||
fi
|
fi
|
||||||
|
- if: always()
|
||||||
|
name: Check if zli binary increased with more than 1%
|
||||||
|
run: |
|
||||||
|
echo "Building zli and check size"
|
||||||
|
cd $GITHUB_WORKSPACE
|
||||||
|
make cli
|
||||||
|
BINSIZE=$(stat -c%s "bin/zli-linux-amd64")
|
||||||
|
|
||||||
|
echo "Building zli on main branch and check size"
|
||||||
|
cd zot_main
|
||||||
|
make cli
|
||||||
|
BINSIZE_MAIN=$(stat -c%s "bin/zli-linux-amd64")
|
||||||
|
|
||||||
|
echo "PR binary size: $BINSIZE Bytes"
|
||||||
|
echo "main branch binary size: $BINSIZE_MAIN Bytes"
|
||||||
|
[[ $BINSIZE -eq $BINSIZE_MAIN ]] && echo "zli binary size is not affected by PR" && exit 0
|
||||||
|
|
||||||
|
if [[ $BINSIZE -gt $BINSIZE_MAIN ]]; then \
|
||||||
|
PERCENTAGE=$(echo "scale=2; (($BINSIZE-$BINSIZE_MAIN)*100)/$BINSIZE_MAIN" | bc); \
|
||||||
|
echo "zli binary increased by $PERCENTAGE% comparing with main"; \
|
||||||
|
if ((`bc <<< "$PERCENTAGE>=1.0"`)); then exit 1; fi; \
|
||||||
|
else \
|
||||||
|
PERCENTAGE=$(echo "scale=2; (($BINSIZE_MAIN-$BINSIZE)*100)/$BINSIZE_MAIN" | bc); \
|
||||||
|
echo "zli binary decreased by $PERCENTAGE% comparing with main"; \
|
||||||
|
fi
|
||||||
|
|
4
Makefile
4
Makefile
|
@ -137,12 +137,12 @@ test: check-skopeo $(TESTDATA) $(ORAS)
|
||||||
rm -rf /tmp/getter*; rm -rf /tmp/trivy*
|
rm -rf /tmp/getter*; rm -rf /tmp/trivy*
|
||||||
go test -failfast -tags dev,containers_image_openpgp -v -trimpath -race -cover -coverpkg ./... -coverprofile=coverage-dev-minimal.txt -covermode=atomic ./pkg/test/... ./pkg/storage/... ./pkg/extensions/sync/... -run ^TestInject
|
go test -failfast -tags dev,containers_image_openpgp -v -trimpath -race -cover -coverpkg ./... -coverprofile=coverage-dev-minimal.txt -covermode=atomic ./pkg/test/... ./pkg/storage/... ./pkg/extensions/sync/... -run ^TestInject
|
||||||
rm -rf /tmp/getter*; rm -rf /tmp/trivy*
|
rm -rf /tmp/getter*; rm -rf /tmp/trivy*
|
||||||
go test -failfast -tags stress,$(BUILD_LABELS),containers_image_openpgp -v -trimpath -race -timeout 15m ./pkg/cli/stress_test.go
|
go test -failfast -tags stress,$(BUILD_LABELS),containers_image_openpgp -v -trimpath -race -timeout 15m ./pkg/cli/server/stress_test.go
|
||||||
|
|
||||||
.PHONY: privileged-test
|
.PHONY: privileged-test
|
||||||
privileged-test: $(if $(findstring ui,$(BUILD_LABELS)), ui)
|
privileged-test: $(if $(findstring ui,$(BUILD_LABELS)), ui)
|
||||||
privileged-test: check-skopeo $(TESTDATA)
|
privileged-test: check-skopeo $(TESTDATA)
|
||||||
go test -failfast -tags needprivileges,$(BUILD_LABELS),containers_image_openpgp -v -trimpath -race -timeout 15m -cover -coverpkg ./... -coverprofile=coverage-dev-needprivileges.txt -covermode=atomic ./pkg/storage/... ./pkg/cli/... -run ^TestElevatedPrivileges
|
go test -failfast -tags needprivileges,$(BUILD_LABELS),containers_image_openpgp -v -trimpath -race -timeout 15m -cover -coverpkg ./... -coverprofile=coverage-dev-needprivileges.txt -covermode=atomic ./pkg/storage/local/... ./pkg/cli/client/... -run ^TestElevatedPrivileges
|
||||||
|
|
||||||
$(TESTDATA): check-skopeo
|
$(TESTDATA): check-skopeo
|
||||||
mkdir -p ${TESTDATA}; \
|
mkdir -p ${TESTDATA}; \
|
||||||
|
|
|
@ -2,12 +2,10 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
crand "crypto/rand"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math/big"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -24,6 +22,7 @@ import (
|
||||||
zerr "zotregistry.io/zot/errors"
|
zerr "zotregistry.io/zot/errors"
|
||||||
"zotregistry.io/zot/pkg/common"
|
"zotregistry.io/zot/pkg/common"
|
||||||
testc "zotregistry.io/zot/pkg/test/common"
|
testc "zotregistry.io/zot/pkg/test/common"
|
||||||
|
"zotregistry.io/zot/pkg/test/image-utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeHTTPGetRequest(url string, resultPtr interface{}, client *resty.Client) error {
|
func makeHTTPGetRequest(url string, resultPtr interface{}, client *resty.Client) error {
|
||||||
|
@ -1023,21 +1022,7 @@ func loadOrStore(statusRequests *sync.Map, key string, value int) int { //nolint
|
||||||
|
|
||||||
// TO DO: replace with pkg/test/images when available.
|
// TO DO: replace with pkg/test/images when available.
|
||||||
func getRandomImageConfig() ([]byte, godigest.Digest) {
|
func getRandomImageConfig() ([]byte, godigest.Digest) {
|
||||||
const maxLen = 16
|
config := image.GetDefaultConfig()
|
||||||
|
|
||||||
randomAuthor := randomString(maxLen)
|
|
||||||
|
|
||||||
config := ispec.Image{
|
|
||||||
Platform: ispec.Platform{
|
|
||||||
Architecture: "amd64",
|
|
||||||
OS: "linux",
|
|
||||||
},
|
|
||||||
RootFS: ispec.RootFS{
|
|
||||||
Type: "layers",
|
|
||||||
DiffIDs: []godigest.Digest{},
|
|
||||||
},
|
|
||||||
Author: randomAuthor,
|
|
||||||
}
|
|
||||||
|
|
||||||
configBlobContent, err := json.MarshalIndent(&config, "", "\t")
|
configBlobContent, err := json.MarshalIndent(&config, "", "\t")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1048,20 +1033,3 @@ func getRandomImageConfig() ([]byte, godigest.Digest) {
|
||||||
|
|
||||||
return configBlobContent, configBlobDigestRaw
|
return configBlobContent, configBlobDigestRaw
|
||||||
}
|
}
|
||||||
|
|
||||||
func randomString(n int) string {
|
|
||||||
const letters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
|
|
||||||
|
|
||||||
ret := make([]byte, n)
|
|
||||||
|
|
||||||
for count := 0; count < n; count++ {
|
|
||||||
num, err := crand.Int(crand.Reader, big.NewInt(int64(len(letters))))
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ret[count] = letters[num.Int64()]
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(ret)
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
|
//go:build search
|
||||||
|
// +build search
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"zotregistry.io/zot/pkg/cli"
|
cli "zotregistry.io/zot/pkg/cli/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
//go:build search
|
||||||
|
// +build search
|
||||||
|
|
||||||
package main_test
|
package main_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -7,7 +10,7 @@ import (
|
||||||
|
|
||||||
"zotregistry.io/zot/pkg/api"
|
"zotregistry.io/zot/pkg/api"
|
||||||
"zotregistry.io/zot/pkg/api/config"
|
"zotregistry.io/zot/pkg/api/config"
|
||||||
"zotregistry.io/zot/pkg/cli"
|
cli "zotregistry.io/zot/pkg/cli/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIntegration(t *testing.T) {
|
func TestIntegration(t *testing.T) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"zotregistry.io/zot/pkg/cli"
|
cli "zotregistry.io/zot/pkg/cli/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
"zotregistry.io/zot/pkg/api"
|
"zotregistry.io/zot/pkg/api"
|
||||||
"zotregistry.io/zot/pkg/api/config"
|
"zotregistry.io/zot/pkg/api/config"
|
||||||
"zotregistry.io/zot/pkg/cli"
|
cli "zotregistry.io/zot/pkg/cli/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIntegration(t *testing.T) {
|
func TestIntegration(t *testing.T) {
|
||||||
|
|
|
@ -2,7 +2,6 @@ ignore:
|
||||||
- "*_gen.go"
|
- "*_gen.go"
|
||||||
- "./pkg/extensions/search/gql_generated"
|
- "./pkg/extensions/search/gql_generated"
|
||||||
- "./pkg/extensions/minimal.go"
|
- "./pkg/extensions/minimal.go"
|
||||||
- "./pkg/cli/minimal.go"
|
|
||||||
- "./cmd/zb/*.go"
|
- "./cmd/zb/*.go"
|
||||||
- "./pkg/test/mocks/*.go"
|
- "./pkg/test/mocks/*.go"
|
||||||
- "./swagger/*.go"
|
- "./swagger/*.go"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import "github.com/spf13/cobra"
|
import "github.com/spf13/cobra"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli //nolint:testpackage
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli //nolint:testpackage
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search && needprivileges
|
//go:build search && needprivileges
|
||||||
// +build search,needprivileges
|
// +build search,needprivileges
|
||||||
|
|
||||||
package cli //nolint:testpackage
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -33,7 +33,7 @@ func TestElevatedPrivilegesTLSNewControllerPrivilegedCert(t *testing.T) {
|
||||||
defer exec.Command("rm", "-rf", "/etc/containers/certs.d/127.0.0.1:8089/")
|
defer exec.Command("rm", "-rf", "/etc/containers/certs.d/127.0.0.1:8089/")
|
||||||
|
|
||||||
workDir, _ := os.Getwd()
|
workDir, _ := os.Getwd()
|
||||||
_ = os.Chdir("../../test/data")
|
_ = os.Chdir("../../../test/data")
|
||||||
|
|
||||||
clientGlob, _ := filepath.Glob("client.*")
|
clientGlob, _ := filepath.Glob("client.*")
|
||||||
caGlob, _ := filepath.Glob("ca.*")
|
caGlob, _ := filepath.Glob("ca.*")
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
type GQLField struct {
|
type GQLField struct {
|
||||||
Name string
|
Name string
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli //nolint:testpackage
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli //nolint:testpackage
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -2686,11 +2686,11 @@ func makeConfigFile(content string) string {
|
||||||
|
|
||||||
func getTestSearchConfig(url string, searchService SearchService) searchConfig {
|
func getTestSearchConfig(url string, searchService SearchService) searchConfig {
|
||||||
var (
|
var (
|
||||||
user string = ""
|
user string
|
||||||
outputFormat string = ""
|
outputFormat string
|
||||||
verbose bool = false
|
verbose bool
|
||||||
debug bool = false
|
debug bool
|
||||||
verifyTLS bool = false
|
verifyTLS bool
|
||||||
)
|
)
|
||||||
|
|
||||||
return searchConfig{
|
return searchConfig{
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli //nolint:testpackage
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -35,10 +35,10 @@ const (
|
||||||
SecurePort3 = "8090"
|
SecurePort3 = "8090"
|
||||||
username = "test"
|
username = "test"
|
||||||
passphrase = "test"
|
passphrase = "test"
|
||||||
ServerCert = "../../test/data/server.cert"
|
ServerCert = "../../../test/data/server.cert"
|
||||||
ServerKey = "../../test/data/server.key"
|
ServerKey = "../../../test/data/server.key"
|
||||||
CACert = "../../test/data/ca.crt"
|
CACert = "../../../test/data/ca.crt"
|
||||||
sourceCertsDir = "../../test/data"
|
sourceCertsDir = "../../../test/data"
|
||||||
certsDir1 = "/.config/containers/certs.d/127.0.0.1:8088/"
|
certsDir1 = "/.config/containers/certs.d/127.0.0.1:8088/"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli //nolint:testpackage
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
42
pkg/cli/client/root.go
Normal file
42
pkg/cli/client/root.go
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
//go:build search
|
||||||
|
// +build search
|
||||||
|
|
||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
distspec "github.com/opencontainers/distribution-spec/specs-go"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"zotregistry.io/zot/pkg/api/config"
|
||||||
|
"zotregistry.io/zot/pkg/cli/cmdflags"
|
||||||
|
)
|
||||||
|
|
||||||
|
// "zli" - client-side cli.
|
||||||
|
func NewCliRootCmd() *cobra.Command {
|
||||||
|
showVersion := false
|
||||||
|
|
||||||
|
rootCmd := &cobra.Command{
|
||||||
|
Use: "zli",
|
||||||
|
Short: "`zli`",
|
||||||
|
Long: "`zli`",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if showVersion {
|
||||||
|
log.Info().Str("distribution-spec", distspec.Version).Str("commit", config.Commit).
|
||||||
|
Str("binary-type", config.BinaryType).Str("go version", config.GoVersion).Msg("version")
|
||||||
|
} else {
|
||||||
|
_ = cmd.Usage()
|
||||||
|
cmd.SilenceErrors = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
rootCmd.SilenceUsage = true
|
||||||
|
|
||||||
|
// additional cmds
|
||||||
|
enableCli(rootCmd)
|
||||||
|
// "version"
|
||||||
|
rootCmd.Flags().BoolVarP(&showVersion, cmdflags.VersionFlag, "v", false, "show the version and exit")
|
||||||
|
|
||||||
|
return rootCmd
|
||||||
|
}
|
31
pkg/cli/client/root_test.go
Normal file
31
pkg/cli/client/root_test.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
//go:build search
|
||||||
|
// +build search
|
||||||
|
|
||||||
|
package client_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
|
|
||||||
|
"zotregistry.io/zot/pkg/cli/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCliUsage(t *testing.T) {
|
||||||
|
oldArgs := os.Args
|
||||||
|
|
||||||
|
defer func() { os.Args = oldArgs }()
|
||||||
|
|
||||||
|
Convey("Test usage", t, func(c C) {
|
||||||
|
os.Args = []string{"cli_test", "help"}
|
||||||
|
err := client.NewCliRootCmd().Execute()
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("Test version", t, func(c C) {
|
||||||
|
os.Args = []string{"cli_test", "--version"}
|
||||||
|
err := client.NewCliRootCmd().Execute()
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
})
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli //nolint:testpackage
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
//
|
//
|
||||||
//nolint:dupl
|
//nolint:dupl
|
||||||
package cli //nolint:testpackage
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli //nolint:testpackage
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,9 +0,0 @@
|
||||||
//go:build !search
|
|
||||||
// +build !search
|
|
||||||
|
|
||||||
package cli
|
|
||||||
|
|
||||||
import "github.com/spf13/cobra"
|
|
||||||
|
|
||||||
func enableCli(rootCmd *cobra.Command) {
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
package cli
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build search
|
//go:build search
|
||||||
// +build search
|
// +build search
|
||||||
|
|
||||||
package cli_test
|
package server_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -13,7 +13,7 @@ import (
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
|
||||||
"zotregistry.io/zot/pkg/cli"
|
cli "zotregistry.io/zot/pkg/cli/server"
|
||||||
"zotregistry.io/zot/pkg/test"
|
"zotregistry.io/zot/pkg/test"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build sync && scrub && metrics && search && userprefs && mgmt && imagetrust
|
//go:build sync && scrub && metrics && search && userprefs && mgmt && imagetrust
|
||||||
// +build sync,scrub,metrics,search,userprefs,mgmt,imagetrust
|
// +build sync,scrub,metrics,search,userprefs,mgmt,imagetrust
|
||||||
|
|
||||||
package cli_test
|
package server_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -13,7 +13,7 @@ import (
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"gopkg.in/resty.v1"
|
"gopkg.in/resty.v1"
|
||||||
|
|
||||||
"zotregistry.io/zot/pkg/cli"
|
cli "zotregistry.io/zot/pkg/cli/server"
|
||||||
. "zotregistry.io/zot/pkg/test"
|
. "zotregistry.io/zot/pkg/test"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package cli
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -22,7 +22,6 @@ import (
|
||||||
"zotregistry.io/zot/pkg/api"
|
"zotregistry.io/zot/pkg/api"
|
||||||
"zotregistry.io/zot/pkg/api/config"
|
"zotregistry.io/zot/pkg/api/config"
|
||||||
"zotregistry.io/zot/pkg/api/constants"
|
"zotregistry.io/zot/pkg/api/constants"
|
||||||
"zotregistry.io/zot/pkg/cli/cmdflags"
|
|
||||||
extconf "zotregistry.io/zot/pkg/extensions/config"
|
extconf "zotregistry.io/zot/pkg/extensions/config"
|
||||||
"zotregistry.io/zot/pkg/extensions/monitoring"
|
"zotregistry.io/zot/pkg/extensions/monitoring"
|
||||||
zlog "zotregistry.io/zot/pkg/log"
|
zlog "zotregistry.io/zot/pkg/log"
|
||||||
|
@ -191,35 +190,6 @@ func NewServerRootCmd() *cobra.Command {
|
||||||
return rootCmd
|
return rootCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// "zli" - client-side cli.
|
|
||||||
func NewCliRootCmd() *cobra.Command {
|
|
||||||
showVersion := false
|
|
||||||
|
|
||||||
rootCmd := &cobra.Command{
|
|
||||||
Use: "zli",
|
|
||||||
Short: "`zli`",
|
|
||||||
Long: "`zli`",
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
if showVersion {
|
|
||||||
log.Info().Str("distribution-spec", distspec.Version).Str("commit", config.Commit).
|
|
||||||
Str("binary-type", config.BinaryType).Str("go version", config.GoVersion).Msg("version")
|
|
||||||
} else {
|
|
||||||
_ = cmd.Usage()
|
|
||||||
cmd.SilenceErrors = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
rootCmd.SilenceUsage = true
|
|
||||||
|
|
||||||
// additional cmds
|
|
||||||
enableCli(rootCmd)
|
|
||||||
// "version"
|
|
||||||
rootCmd.Flags().BoolVarP(&showVersion, cmdflags.VersionFlag, "v", false, "show the version and exit")
|
|
||||||
|
|
||||||
return rootCmd
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateStorageConfig(cfg *config.Config, log zlog.Logger) error {
|
func validateStorageConfig(cfg *config.Config, log zlog.Logger) error {
|
||||||
expConfigMap := make(map[string]config.StorageConfig, 0)
|
expConfigMap := make(map[string]config.StorageConfig, 0)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package cli_test
|
package server_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
"zotregistry.io/zot/pkg/api"
|
"zotregistry.io/zot/pkg/api"
|
||||||
"zotregistry.io/zot/pkg/api/config"
|
"zotregistry.io/zot/pkg/api/config"
|
||||||
"zotregistry.io/zot/pkg/cli"
|
cli "zotregistry.io/zot/pkg/cli/server"
|
||||||
storageConstants "zotregistry.io/zot/pkg/storage/constants"
|
storageConstants "zotregistry.io/zot/pkg/storage/constants"
|
||||||
. "zotregistry.io/zot/pkg/test"
|
. "zotregistry.io/zot/pkg/test"
|
||||||
)
|
)
|
||||||
|
@ -35,24 +35,6 @@ func TestServerUsage(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCliUsage(t *testing.T) {
|
|
||||||
oldArgs := os.Args
|
|
||||||
|
|
||||||
defer func() { os.Args = oldArgs }()
|
|
||||||
|
|
||||||
Convey("Test usage", t, func(c C) {
|
|
||||||
os.Args = []string{"cli_test", "help"}
|
|
||||||
err := cli.NewCliRootCmd().Execute()
|
|
||||||
So(err, ShouldBeNil)
|
|
||||||
})
|
|
||||||
|
|
||||||
Convey("Test version", t, func(c C) {
|
|
||||||
os.Args = []string{"cli_test", "--version"}
|
|
||||||
err := cli.NewCliRootCmd().Execute()
|
|
||||||
So(err, ShouldBeNil)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestServe(t *testing.T) {
|
func TestServe(t *testing.T) {
|
||||||
oldArgs := os.Args
|
oldArgs := os.Args
|
||||||
|
|
||||||
|
@ -1335,7 +1317,7 @@ func TestServeAPIKey(t *testing.T) {
|
||||||
func TestLoadConfig(t *testing.T) {
|
func TestLoadConfig(t *testing.T) {
|
||||||
Convey("Test viper load config", t, func(c C) {
|
Convey("Test viper load config", t, func(c C) {
|
||||||
config := config.New()
|
config := config.New()
|
||||||
err := cli.LoadConfiguration(config, "../../examples/config-policy.json")
|
err := cli.LoadConfiguration(config, "../../../examples/config-policy.json")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
})
|
})
|
||||||
Convey("Test subpath config combination", t, func(c C) {
|
Convey("Test subpath config combination", t, func(c C) {
|
||||||
|
@ -1445,18 +1427,18 @@ func TestLoadConfig(t *testing.T) {
|
||||||
func TestGC(t *testing.T) {
|
func TestGC(t *testing.T) {
|
||||||
Convey("Test GC config", t, func(c C) {
|
Convey("Test GC config", t, func(c C) {
|
||||||
config := config.New()
|
config := config.New()
|
||||||
err := cli.LoadConfiguration(config, "../../examples/config-multiple.json")
|
err := cli.LoadConfiguration(config, "../../../examples/config-multiple.json")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(config.Storage.GCDelay, ShouldEqual, storageConstants.DefaultGCDelay)
|
So(config.Storage.GCDelay, ShouldEqual, storageConstants.DefaultGCDelay)
|
||||||
err = cli.LoadConfiguration(config, "../../examples/config-gc.json")
|
err = cli.LoadConfiguration(config, "../../../examples/config-gc.json")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(config.Storage.GCDelay, ShouldNotEqual, storageConstants.DefaultGCDelay)
|
So(config.Storage.GCDelay, ShouldNotEqual, storageConstants.DefaultGCDelay)
|
||||||
err = cli.LoadConfiguration(config, "../../examples/config-gc-periodic.json")
|
err = cli.LoadConfiguration(config, "../../../examples/config-gc-periodic.json")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Test GC config corner cases", t, func(c C) {
|
Convey("Test GC config corner cases", t, func(c C) {
|
||||||
contents, err := os.ReadFile("../../examples/config-gc.json")
|
contents, err := os.ReadFile("../../../examples/config-gc.json")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
Convey("GC delay without GC", func() {
|
Convey("GC delay without GC", func() {
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build stress
|
//go:build stress
|
||||||
// +build stress
|
// +build stress
|
||||||
|
|
||||||
package cli_test
|
package server_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -16,7 +16,7 @@ import (
|
||||||
|
|
||||||
"zotregistry.io/zot/pkg/api"
|
"zotregistry.io/zot/pkg/api"
|
||||||
"zotregistry.io/zot/pkg/api/config"
|
"zotregistry.io/zot/pkg/api/config"
|
||||||
"zotregistry.io/zot/pkg/cli"
|
cli "zotregistry.io/zot/pkg/cli/server"
|
||||||
"zotregistry.io/zot/pkg/test"
|
"zotregistry.io/zot/pkg/test"
|
||||||
)
|
)
|
||||||
|
|
|
@ -38,7 +38,7 @@ import (
|
||||||
"zotregistry.io/zot/pkg/api"
|
"zotregistry.io/zot/pkg/api"
|
||||||
"zotregistry.io/zot/pkg/api/config"
|
"zotregistry.io/zot/pkg/api/config"
|
||||||
"zotregistry.io/zot/pkg/api/constants"
|
"zotregistry.io/zot/pkg/api/constants"
|
||||||
"zotregistry.io/zot/pkg/cli"
|
cli "zotregistry.io/zot/pkg/cli/server"
|
||||||
zcommon "zotregistry.io/zot/pkg/common"
|
zcommon "zotregistry.io/zot/pkg/common"
|
||||||
extconf "zotregistry.io/zot/pkg/extensions/config"
|
extconf "zotregistry.io/zot/pkg/extensions/config"
|
||||||
syncconf "zotregistry.io/zot/pkg/extensions/config/sync"
|
syncconf "zotregistry.io/zot/pkg/extensions/config/sync"
|
||||||
|
|
|
@ -76,7 +76,7 @@ func createMockStorage(rootDir string, cacheDir string, dedupe bool, store drive
|
||||||
|
|
||||||
var cacheDriver cache.Cache
|
var cacheDriver cache.Cache
|
||||||
|
|
||||||
// from pkg/cli/root.go/applyDefaultValues, s3 magic
|
// from pkg/cli/server/root.go/applyDefaultValues, s3 magic
|
||||||
if _, err := os.Stat(path.Join(cacheDir,
|
if _, err := os.Stat(path.Join(cacheDir,
|
||||||
storageConstants.BoltdbName+storageConstants.DBExtensionName)); dedupe || (!dedupe && err == nil) {
|
storageConstants.BoltdbName+storageConstants.DBExtensionName)); dedupe || (!dedupe && err == nil) {
|
||||||
cacheDriver, _ = storage.Create("boltdb", cache.BoltDBDriverParameters{
|
cacheDriver, _ = storage.Create("boltdb", cache.BoltDBDriverParameters{
|
||||||
|
@ -151,7 +151,7 @@ func createObjectsStore(rootDir string, cacheDir string, dedupe bool) (
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// from pkg/cli/root.go/applyDefaultValues, s3 magic
|
// from pkg/cli/server/root.go/applyDefaultValues, s3 magic
|
||||||
s3CacheDBPath := path.Join(cacheDir, storageConstants.BoltdbName+storageConstants.DBExtensionName)
|
s3CacheDBPath := path.Join(cacheDir, storageConstants.BoltdbName+storageConstants.DBExtensionName)
|
||||||
if _, err = os.Stat(s3CacheDBPath); dedupe || (!dedupe && err == nil) {
|
if _, err = os.Stat(s3CacheDBPath); dedupe || (!dedupe && err == nil) {
|
||||||
cacheDriver, _ = storage.Create("boltdb", cache.BoltDBDriverParameters{
|
cacheDriver, _ = storage.Create("boltdb", cache.BoltDBDriverParameters{
|
||||||
|
@ -179,7 +179,7 @@ func createObjectsStoreDynamo(rootDir string, cacheDir string, dedupe bool, tabl
|
||||||
|
|
||||||
var cacheDriver cache.Cache
|
var cacheDriver cache.Cache
|
||||||
|
|
||||||
// from pkg/cli/root.go/applyDefaultValues, s3 magic
|
// from pkg/cli/server/root.go/applyDefaultValues, s3 magic
|
||||||
tableName = strings.ReplaceAll(tableName, "/", "")
|
tableName = strings.ReplaceAll(tableName, "/", "")
|
||||||
|
|
||||||
cacheDriver, _ = storage.Create("dynamodb", cache.DynamoDBDriverParameters{
|
cacheDriver, _ = storage.Create("dynamodb", cache.DynamoDBDriverParameters{
|
||||||
|
|
Loading…
Reference in a new issue