diff --git a/Dockerfile b/Dockerfile index 060abad9bdca8..5ff315ff0ef2d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -131,3 +131,12 @@ RUN if [ "$BUILD_ALL_CLIS" = "true" ] ; then \ FROM argocd-base COPY --from=argocd-build /go/src/github.com/argoproj/argo-cd/dist/argocd* /usr/local/bin/ COPY --from=argocd-ui ./src/dist/app /shared/app + +USER root +RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-util +RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-server +RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-repo-server +RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-application-controller +RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-dex + +USER 999 \ No newline at end of file diff --git a/Makefile b/Makefile index 71d48f4d33ebb..5fe98e9eead0d 100644 --- a/Makefile +++ b/Makefile @@ -207,9 +207,9 @@ release-cli: clean-debug image docker cp tmp-argocd-linux:/usr/local/bin/argocd ${DIST_DIR}/argocd-linux-amd64 docker cp tmp-argocd-linux:/usr/local/bin/argocd-darwin-amd64 ${DIST_DIR}/argocd-darwin-amd64 docker cp tmp-argocd-linux:/usr/local/bin/argocd-windows-amd64.exe ${DIST_DIR}/argocd-windows-amd64.exe - docker cp tmp-argocd-linux:/usr/local/bin/argocd ${DIST_DIR}/argocd-util-linux-amd64 - docker cp tmp-argocd-linux:/usr/local/bin/argocd-darwin-amd64 ${DIST_DIR}/argocd-util-darwin-amd64 - docker cp tmp-argocd-linux:/usr/local/bin/argocd-windows-amd64.exe ${DIST_DIR}/argocd-util-windows-amd64.exe + ln -s ${DIST_DIR}/argocd-linux-amd64 ${DIST_DIR}/argocd-util-linux-amd64 + ln -s ${DIST_DIR}/argocd-darwin-amd64 ${DIST_DIR}/argocd-util-darwin-amd64 + ln -s ${DIST_DIR}/argocd-windows-amd64.exe ${DIST_DIR}/argocd-util-windows-amd64.exe docker rm tmp-argocd-linux .PHONY: argocd-util @@ -267,15 +267,15 @@ IMAGE_TAG="dev-$(shell git describe --always --dirty)" image: packr docker build -t argocd-base --target argocd-base . docker build -t argocd-ui --target argocd-ui . - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 dist/packr build -v -i -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-server ./cmd - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 dist/packr build -v -i -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-application-controller ./cmd - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 dist/packr build -v -i -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-repo-server ./cmd CGO_ENABLED=0 GOOS=linux GOARCH=amd64 dist/packr build -v -i -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd ./cmd CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 dist/packr build -v -i -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-darwin-amd64 ./cmd CGO_ENABLED=0 GOOS=windows GOARCH=amd64 dist/packr build -v -i -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-windows-amd64.exe ./cmd - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 dist/packr build -v -i -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-util ./cmd - CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 dist/packr build -v -i -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-util-darwin-amd64 ./cmd - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 dist/packr build -v -i -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-util-windows-amd64.exe ./cmd + ln -s ${DIST_DIR}/argocd ${DIST_DIR}/argocd-util + ln -s ${DIST_DIR}/argocd ${DIST_DIR}/argocd-server + ln -s ${DIST_DIR}/argocd ${DIST_DIR}/argocd-application-controller + ln -s ${DIST_DIR}/argocd ${DIST_DIR}/argocd-repo-server + ln -s ${DIST_DIR}/argocd-darwin-amd64 ${DIST_DIR}/argocd-util-darwin-amd64 + ln -s ${DIST_DIR}/argocd-windows-amd64.exe ${DIST_DIR}/argocd-util-windows-amd64.exe cp Dockerfile.dev dist docker build -t $(IMAGE_PREFIX)argocd:$(IMAGE_TAG) -f dist/Dockerfile.dev dist else diff --git a/cmd/argocd-application-controller/commands/argocd_application_controller.go b/cmd/argocd-application-controller/commands/argocd_application_controller.go index 3fdecfb3dee86..3f2d8c25c3bd5 100644 --- a/cmd/argocd-application-controller/commands/argocd_application_controller.go +++ b/cmd/argocd-application-controller/commands/argocd_application_controller.go @@ -12,6 +12,7 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" + cmdutil "github.com/argoproj/argo-cd/cmd/util" "github.com/argoproj/argo-cd/common" "github.com/argoproj/argo-cd/controller" "github.com/argoproj/argo-cd/controller/sharding" @@ -43,8 +44,6 @@ func NewCommand() *cobra.Command { selfHealTimeoutSeconds int statusProcessors int operationProcessors int - logFormat string - logLevel string glogLevel int metricsPort int kubectlParallelismLimit int64 @@ -57,8 +56,8 @@ func NewCommand() *cobra.Command { Long: "ArgoCD application controller is a Kubernetes controller that continuously monitors running applications and compares the current, live state against the desired target state (as specified in the repo). This command runs Application Controller in the foreground. It can be configured by following options.", DisableAutoGenTag: true, RunE: func(c *cobra.Command, args []string) error { - cli.SetLogFormat(logFormat) - cli.SetLogLevel(logLevel) + cli.SetLogFormat(cmdutil.LogFormat) + cli.SetLogLevel(cmdutil.LogLevel) cli.SetGLogLevel(glogLevel) config, err := clientConfig.ClientConfig() @@ -117,8 +116,8 @@ func NewCommand() *cobra.Command { command.Flags().IntVar(&repoServerTimeoutSeconds, "repo-server-timeout-seconds", 60, "Repo server RPC call timeout seconds.") command.Flags().IntVar(&statusProcessors, "status-processors", 1, "Number of application status processors") command.Flags().IntVar(&operationProcessors, "operation-processors", 1, "Number of application operation processors") - command.Flags().StringVar(&logFormat, "logformat", "text", "Set the logging format. One of: text|json") - command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") + command.Flags().StringVar(&cmdutil.LogFormat, "logformat", "text", "Set the logging format. One of: text|json") + command.Flags().StringVar(&cmdutil.LogLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") command.Flags().IntVar(&glogLevel, "gloglevel", 0, "Set the glog logging level") command.Flags().IntVar(&metricsPort, "metrics-port", common.DefaultPortArgoCDMetrics, "Start metrics server on given port") command.Flags().IntVar(&selfHealTimeoutSeconds, "self-heal-timeout-seconds", 5, "Specifies timeout between application self heal attempts") diff --git a/cmd/argocd-dex/commands/argocd_dex.go b/cmd/argocd-dex/commands/argocd_dex.go index 3413dabc70705..0aa84b20d7b67 100644 --- a/cmd/argocd-dex/commands/argocd_dex.go +++ b/cmd/argocd-dex/commands/argocd_dex.go @@ -14,6 +14,7 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" + cmdutil "github.com/argoproj/argo-cd/cmd/util" "github.com/argoproj/argo-cd/util/cli" "github.com/argoproj/argo-cd/util/dex" "github.com/argoproj/argo-cd/util/errors" @@ -25,11 +26,6 @@ const ( ) func NewCommand() *cobra.Command { - var ( - logFormat string - logLevel string - ) - var command = &cobra.Command{ Use: cliName, Short: "argocd-util tools used by Argo CD", @@ -43,8 +39,8 @@ func NewCommand() *cobra.Command { command.AddCommand(NewRunDexCommand()) command.AddCommand(NewGenDexConfigCommand()) - command.Flags().StringVar(&logFormat, "logformat", "text", "Set the logging format. One of: text|json") - command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") + command.Flags().StringVar(&cmdutil.LogFormat, "logformat", "text", "Set the logging format. One of: text|json") + command.Flags().StringVar(&cmdutil.LogLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") return command } diff --git a/cmd/argocd-repo-server/commands/argocd_repo_server.go b/cmd/argocd-repo-server/commands/argocd_repo_server.go index b1a644c6a44f9..208e018d60f60 100644 --- a/cmd/argocd-repo-server/commands/argocd_repo_server.go +++ b/cmd/argocd-repo-server/commands/argocd_repo_server.go @@ -14,6 +14,7 @@ import ( "github.com/spf13/cobra" "google.golang.org/grpc/health/grpc_health_v1" + cmdutil "github.com/argoproj/argo-cd/cmd/util" "github.com/argoproj/argo-cd/common" "github.com/argoproj/argo-cd/reposerver" "github.com/argoproj/argo-cd/reposerver/apiclient" @@ -62,8 +63,6 @@ func getPauseGenerationOnFailureForRequests() int { func NewCommand() *cobra.Command { var ( - logFormat string - logLevel string parallelismLimit int64 listenPort int metricsPort int @@ -77,8 +76,8 @@ func NewCommand() *cobra.Command { Long: "ArgoCD Repository Server is an internal service which maintains a local cache of the Git repository holding the application manifests, and is responsible for generating and returning the Kubernetes manifests. This command runs Repository Server in the foreground. It can be configured by following options.", DisableAutoGenTag: true, RunE: func(c *cobra.Command, args []string) error { - cli.SetLogFormat(logFormat) - cli.SetLogLevel(logLevel) + cli.SetLogFormat(cmdutil.LogFormat) + cli.SetLogLevel(cmdutil.LogLevel) tlsConfigCustomizer, err := tlsConfigCustomizerSrc() errors.CheckError(err) @@ -148,8 +147,8 @@ func NewCommand() *cobra.Command { }, } - command.Flags().StringVar(&logFormat, "logformat", "text", "Set the logging format. One of: text|json") - command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") + command.Flags().StringVar(&cmdutil.LogFormat, "logformat", "text", "Set the logging format. One of: text|json") + command.Flags().StringVar(&cmdutil.LogLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") command.Flags().Int64Var(¶llelismLimit, "parallelismlimit", 0, "Limit on number of concurrent manifests generate requests. Any value less the 1 means no limit.") command.Flags().IntVar(&listenPort, "port", common.DefaultPortRepoServer, "Listen on given port for incoming connections") command.Flags().IntVar(&metricsPort, "metrics-port", common.DefaultPortRepoServerMetrics, "Start metrics server on given port") diff --git a/cmd/argocd-server/commands/argocd_server.go b/cmd/argocd-server/commands/argocd_server.go index 76977f7533daf..a48e0a5976296 100644 --- a/cmd/argocd-server/commands/argocd_server.go +++ b/cmd/argocd-server/commands/argocd_server.go @@ -11,6 +11,7 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" + cmdutil "github.com/argoproj/argo-cd/cmd/util" "github.com/argoproj/argo-cd/common" "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1" appclientset "github.com/argoproj/argo-cd/pkg/client/clientset/versioned" @@ -46,8 +47,6 @@ func NewCommand() *cobra.Command { insecure bool listenPort int metricsPort int - logFormat string - logLevel string glogLevel int clientConfig clientcmd.ClientConfig repoServerTimeoutSeconds int @@ -68,8 +67,8 @@ func NewCommand() *cobra.Command { Long: "The API server is a gRPC/REST server which exposes the API consumed by the Web UI, CLI, and CI/CD systems. This command runs API server in the foreground. It can be configured by following options.", DisableAutoGenTag: true, Run: func(c *cobra.Command, args []string) { - cli.SetLogFormat(logFormat) - cli.SetLogLevel(logLevel) + cli.SetLogFormat(cmdutil.LogFormat) + cli.SetLogLevel(cmdutil.LogLevel) cli.SetGLogLevel(glogLevel) config, err := clientConfig.ClientConfig() @@ -142,8 +141,8 @@ func NewCommand() *cobra.Command { command.Flags().StringVar(&staticAssetsDir, "staticassets", "", "Static assets directory path") command.Flags().StringVar(&baseHRef, "basehref", "/", "Value for base href in index.html. Used if Argo CD is running behind reverse proxy under subpath different from /") command.Flags().StringVar(&rootPath, "rootpath", "", "Used if Argo CD is running behind reverse proxy under subpath different from /") - command.Flags().StringVar(&logFormat, "logformat", "text", "Set the logging format. One of: text|json") - command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") + command.Flags().StringVar(&cmdutil.LogFormat, "logformat", "text", "Set the logging format. One of: text|json") + command.Flags().StringVar(&cmdutil.LogLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") command.Flags().IntVar(&glogLevel, "gloglevel", 0, "Set the glog logging level") command.Flags().StringVar(&repoServerAddress, "repo-server", common.DefaultRepoServerAddr, "Repo server address") command.Flags().StringVar(&dexServerAddress, "dex-server", common.DefaultDexServerAddr, "Dex server address") diff --git a/cmd/argocd-util/commands/argocd_util.go b/cmd/argocd-util/commands/argocd_util.go index 5a377b42b7df1..9b723afe50c92 100644 --- a/cmd/argocd-util/commands/argocd_util.go +++ b/cmd/argocd-util/commands/argocd_util.go @@ -23,6 +23,7 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" + cmdutil "github.com/argoproj/argo-cd/cmd/util" "github.com/argoproj/argo-cd/common" "github.com/argoproj/argo-cd/util/cli" "github.com/argoproj/argo-cd/util/db" @@ -47,9 +48,7 @@ var ( // NewCommand returns a new instance of an argocd command func NewCommand() *cobra.Command { var ( - logFormat string - logLevel string - pathOpts = clientcmd.NewDefaultPathOptions() + pathOpts = clientcmd.NewDefaultPathOptions() ) var command = &cobra.Command{ @@ -72,8 +71,8 @@ func NewCommand() *cobra.Command { command.AddCommand(NewRBACCommand()) command.AddCommand(NewGenerateConfigCommand(pathOpts)) - command.Flags().StringVar(&logFormat, "logformat", "text", "Set the logging format. One of: text|json") - command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") + command.Flags().StringVar(&cmdutil.LogFormat, "logformat", "text", "Set the logging format. One of: text|json") + command.Flags().StringVar(&cmdutil.LogLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") return command } diff --git a/cmd/argocd/commands/root.go b/cmd/argocd/commands/root.go index 0b33a5e739c9d..a6a2306f243b7 100644 --- a/cmd/argocd/commands/root.go +++ b/cmd/argocd/commands/root.go @@ -4,6 +4,7 @@ import ( "github.com/spf13/cobra" "k8s.io/client-go/tools/clientcmd" + cmdutil "github.com/argoproj/argo-cd/cmd/util" argocdclient "github.com/argoproj/argo-cd/pkg/apiclient" "github.com/argoproj/argo-cd/util/cli" "github.com/argoproj/argo-cd/util/config" @@ -15,14 +16,9 @@ func init() { cobra.OnInitialize(initConfig) } -var ( - logFormat string - logLevel string -) - func initConfig() { - cli.SetLogFormat(logFormat) - cli.SetLogLevel(logLevel) + cli.SetLogFormat(cmdutil.LogFormat) + cli.SetLogLevel(cmdutil.LogLevel) } // NewCommand returns a new instance of an argocd command @@ -68,8 +64,8 @@ func NewCommand() *cobra.Command { command.PersistentFlags().StringVar(&clientOpts.AuthToken, "auth-token", config.GetFlag("auth-token", ""), "Authentication token") command.PersistentFlags().BoolVar(&clientOpts.GRPCWeb, "grpc-web", config.GetBoolFlag("grpc-web"), "Enables gRPC-web protocol. Useful if Argo CD server is behind proxy which does not support HTTP2.") command.PersistentFlags().StringVar(&clientOpts.GRPCWebRootPath, "grpc-web-root-path", config.GetFlag("grpc-web-root-path", ""), "Enables gRPC-web protocol. Useful if Argo CD server is behind proxy which does not support HTTP2. Set web root.") - command.PersistentFlags().StringVar(&logFormat, "logformat", config.GetFlag("logformat", "text"), "Set the logging format. One of: text|json") - command.PersistentFlags().StringVar(&logLevel, "loglevel", config.GetFlag("loglevel", "info"), "Set the logging level. One of: debug|info|warn|error") + command.PersistentFlags().StringVar(&cmdutil.LogFormat, "logformat", config.GetFlag("logformat", "text"), "Set the logging format. One of: text|json") + command.PersistentFlags().StringVar(&cmdutil.LogLevel, "loglevel", config.GetFlag("loglevel", "info"), "Set the logging level. One of: debug|info|warn|error") command.PersistentFlags().StringSliceVarP(&clientOpts.Headers, "header", "H", []string{}, "Sets additional header to all requests made by Argo CD CLI. (Can be repeated multiple times to add multiple headers, also supports comma separated headers)") command.PersistentFlags().BoolVar(&clientOpts.PortForward, "port-forward", config.GetBoolFlag("port-forward"), "Connect to a random argocd-server port using port forwarding") command.PersistentFlags().StringVar(&clientOpts.PortForwardNamespace, "port-forward-namespace", config.GetFlag("port-forward-namespace", ""), "Namespace name which should be used for port forwarding") diff --git a/cmd/main.go b/cmd/main.go index 9265b9fdd29cd..231f5446ca94f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -15,16 +15,18 @@ import ( cli "github.com/argoproj/argo-cd/cmd/argocd/commands" ) +const ( + binaryNameEnv = "ARGOCD_BINARY_NAME" +) + func main() { var command *cobra.Command binaryName := filepath.Base(os.Args[0]) - if val := os.Getenv("ARGOCD_BINARY_NAME"); val != "" { + if val := os.Getenv(binaryNameEnv); val != "" { binaryName = val } switch binaryName { - case "argocd", "argocd-linux-amd64", "argocd-darwin-amd64", "argocd-windows-amd64.exe": - command = cli.NewCommand() case "argocd-util", "argocd-util-linux-amd64", "argocd-util-darwin-amd64", "argocd-util-windows-amd64.exe": command = util.NewCommand() case "argocd-server": @@ -36,8 +38,8 @@ func main() { case "argocd-dex": command = dex.NewCommand() default: - fmt.Printf("Unexpected binary name '%s'", binaryName) - os.Exit(1) + // default is argocd cli + command = cli.NewCommand() } if err := command.Execute(); err != nil { diff --git a/cmd/util/common.go b/cmd/util/common.go index f2d11174abfd4..e71ec26258d69 100644 --- a/cmd/util/common.go +++ b/cmd/util/common.go @@ -10,6 +10,11 @@ import ( "github.com/argoproj/gitops-engine/pkg/utils/kube" ) +var ( + LogFormat string + LogLevel string +) + // PrintResource prints a single resource in YAML or JSON format to stdout according to the output format func PrintResources(resources []interface{}, output string) error { for i, resource := range resources {