From c5aa764f136d95cdb92b801377f5200fd0f85ab8 Mon Sep 17 00:00:00 2001 From: Daniel Liszka Date: Mon, 8 May 2023 10:42:55 +0200 Subject: [PATCH 1/3] feat(cli): allow setting default values for Control Plane and CAS endpoints endpoints at the CLI build time Signed-off-by: Daniel Liszka --- app/cli/cmd/root.go | 7 +++++-- devel/README.md | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/app/cli/cmd/root.go b/app/cli/cmd/root.go index 80d9ed5e9..879480427 100644 --- a/app/cli/cmd/root.go +++ b/app/cli/cmd/root.go @@ -37,6 +37,8 @@ var ( flagOutputFormat string actionOpts *action.ActionsOpts logger zerolog.Logger + defaultCpAPI = "api.cp.chainloop.dev:443" + defaultCasAPI = "api.cas.chainloop.dev:443" ) const useWorkflowRobotAccount = "withWorkflowRobotAccount" @@ -92,11 +94,12 @@ func NewRootCmd(l zerolog.Logger) *cobra.Command { rootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) rootCmd.PersistentFlags().StringVarP(&flagCfgFile, "config", "c", "", "Path to an existing config file (default is $HOME/.config/chainloop/config.toml)") - rootCmd.PersistentFlags().String(confOptions.controlplaneAPI.flagName, "api.cp.chainloop.dev:443", "URL for the Control Plane API") + + rootCmd.PersistentFlags().String(confOptions.controlplaneAPI.flagName, defaultCpAPI, "URL for the Control Plane API") err := viper.BindPFlag(confOptions.controlplaneAPI.viperKey, rootCmd.PersistentFlags().Lookup(confOptions.controlplaneAPI.flagName)) cobra.CheckErr(err) - rootCmd.PersistentFlags().String(confOptions.CASAPI.flagName, "api.cas.chainloop.dev:443", "URL for the Artifacts Content Addressable Storage (CAS)") + rootCmd.PersistentFlags().String(confOptions.CASAPI.flagName, defaultCasAPI, "URL for the Artifacts Content Addressable Storage (CAS)") err = viper.BindPFlag(confOptions.CASAPI.viperKey, rootCmd.PersistentFlags().Lookup(confOptions.CASAPI.flagName)) cobra.CheckErr(err) diff --git a/devel/README.md b/devel/README.md index 572b4fa00..14f08511d 100644 --- a/devel/README.md +++ b/devel/README.md @@ -69,3 +69,41 @@ You will get redirected to the pre-configured local OIDC provider (DEX) where th - `john@chainloop.local`/`password` Once logged in, please refer to our [Getting Started guide](https://docs.chainloop.dev/getting-started/setup) to learn how to setup an OCI registry. + +## Building CLI +### Updating default values + +By default the Chainloop command line tool uses the following values for the Control Plane and Artifacts CAS API endpoints: + +- Artifacts CAS: api.cas.chainloop.dev:443 +- Control Plane API: api.cp.chainloop.dev:443 + +You can review them in the Chainloop CLI help message. + +``` +Flags: + --artifact-cas string URL for the Artifacts Content Addressable Storage (CAS) (default "api.cas.chainloop.dev:443") + -c, --config string Path to an existing config file (default is $HOME/.config/chainloop/config.toml) + --control-plane string URL for the Control Plane API (default "api.cp.chainloop.dev:443") +``` + +If you want to change these default values to your custom endpoints, you can do that at the command line build time. Please take a look at some examples below: + +**Example 1** Building the Chainloop CLI: + +``` +cd chainloop +go build app/cli/main.go +``` + +**Example 2** Set the default value for the Artifacts CAS endpoint. We will use `ldflags` and the `defaultCasAPI` variable. We assume in this example that we have our instance of CAS running at the following location: `api.cas.acme.com:443`. + +``` +go build -ldflags "-X 'github.com/chainloop-dev/chainloop/app/cli/cmd.defaultCasAPI=api.cas.acme.com:443'" app/cli/main.go +``` + +**Example 3** Set both the Artifacts CAS and Control Plane endpoints. We use two variables here: `defaultCasAPI` and `defaultCpAPI`. + +``` +go build -ldflags "-X 'github.com/chainloop-dev/chainloop/app/cli/cmd.defaultCasAPI=api.cas.acme.com:443' -X 'github.com/chainloop-dev/chainloop/app/cli/cmd.defaultCpAPI=api.cp.acme.com:443'" app/cli/main.go +``` \ No newline at end of file From 006c2809e122149c16659e778c4fbb64f4e26204 Mon Sep 17 00:00:00 2001 From: Daniel Liszka Date: Mon, 8 May 2023 11:40:53 +0200 Subject: [PATCH 2/3] fix the wording and move documentation to the CLI README.md Signed-off-by: Daniel Liszka --- app/cli/README.md | 13 +++++++++++++ devel/README.md | 37 ------------------------------------- 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/app/cli/README.md b/app/cli/README.md index 10aa56c59..091ede397 100644 --- a/app/cli/README.md +++ b/app/cli/README.md @@ -57,6 +57,19 @@ We leverage buf.io to lint and generate proto files. Make sure you [install buf] make api ``` +### Updating default values + +By default CLI uses the following values for the Control Plane and Artifacts CAS API endpoints: + +- Artifacts CAS: api.cas.chainloop.dev:443 +- Control Plane API: api.cp.chainloop.dev:443 + +If you want to change them to your custom endpoints, you can do that at build time. We will use `ldflags` and the following variables: `defaultCasAPI` and `defaultCpAPI`. We assume in this example that we have our instance of Chainloop running at the following locations: `api.cas.acme.com:443` and `api.cp.acme.com:443`. + +``` +go build -ldflags "-X 'github.com/chainloop-dev/chainloop/app/cli/cmd.defaultCasAPI=api.cas.acme.com:443' -X 'github.com/chainloop-dev/chainloop/app/cli/cmd.defaultCpAPI=api.cp.acme.com:443'" app/cli/main.go +``` + ## Contribution guidelines Please make sure to review the [Contribution guidelines](../../CONTRIBUTING.md) and feel free to reach out if you have any questions! diff --git a/devel/README.md b/devel/README.md index 14f08511d..ed4234693 100644 --- a/devel/README.md +++ b/devel/README.md @@ -70,40 +70,3 @@ You will get redirected to the pre-configured local OIDC provider (DEX) where th Once logged in, please refer to our [Getting Started guide](https://docs.chainloop.dev/getting-started/setup) to learn how to setup an OCI registry. -## Building CLI -### Updating default values - -By default the Chainloop command line tool uses the following values for the Control Plane and Artifacts CAS API endpoints: - -- Artifacts CAS: api.cas.chainloop.dev:443 -- Control Plane API: api.cp.chainloop.dev:443 - -You can review them in the Chainloop CLI help message. - -``` -Flags: - --artifact-cas string URL for the Artifacts Content Addressable Storage (CAS) (default "api.cas.chainloop.dev:443") - -c, --config string Path to an existing config file (default is $HOME/.config/chainloop/config.toml) - --control-plane string URL for the Control Plane API (default "api.cp.chainloop.dev:443") -``` - -If you want to change these default values to your custom endpoints, you can do that at the command line build time. Please take a look at some examples below: - -**Example 1** Building the Chainloop CLI: - -``` -cd chainloop -go build app/cli/main.go -``` - -**Example 2** Set the default value for the Artifacts CAS endpoint. We will use `ldflags` and the `defaultCasAPI` variable. We assume in this example that we have our instance of CAS running at the following location: `api.cas.acme.com:443`. - -``` -go build -ldflags "-X 'github.com/chainloop-dev/chainloop/app/cli/cmd.defaultCasAPI=api.cas.acme.com:443'" app/cli/main.go -``` - -**Example 3** Set both the Artifacts CAS and Control Plane endpoints. We use two variables here: `defaultCasAPI` and `defaultCpAPI`. - -``` -go build -ldflags "-X 'github.com/chainloop-dev/chainloop/app/cli/cmd.defaultCasAPI=api.cas.acme.com:443' -X 'github.com/chainloop-dev/chainloop/app/cli/cmd.defaultCpAPI=api.cp.acme.com:443'" app/cli/main.go -``` \ No newline at end of file From 7b7798695c955d56c49334503263bffd8fc496a1 Mon Sep 17 00:00:00 2001 From: Daniel Liszka Date: Mon, 8 May 2023 11:52:36 +0200 Subject: [PATCH 3/3] fix the variables naming Signed-off-by: Daniel Liszka --- app/cli/README.md | 4 ++-- app/cli/cmd/root.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/cli/README.md b/app/cli/README.md index 091ede397..5d1f1b265 100644 --- a/app/cli/README.md +++ b/app/cli/README.md @@ -64,10 +64,10 @@ By default CLI uses the following values for the Control Plane and Artifacts CAS - Artifacts CAS: api.cas.chainloop.dev:443 - Control Plane API: api.cp.chainloop.dev:443 -If you want to change them to your custom endpoints, you can do that at build time. We will use `ldflags` and the following variables: `defaultCasAPI` and `defaultCpAPI`. We assume in this example that we have our instance of Chainloop running at the following locations: `api.cas.acme.com:443` and `api.cp.acme.com:443`. +If you want to change them to your custom endpoints, you can do that at build time. We will use `ldflags` and the following variables: `defaultCASAPI` and `defaultCPAPI`. We assume in this example that we have our instance of Chainloop running at the following locations: `api.cas.acme.com:443` and `api.cp.acme.com:443`. ``` -go build -ldflags "-X 'github.com/chainloop-dev/chainloop/app/cli/cmd.defaultCasAPI=api.cas.acme.com:443' -X 'github.com/chainloop-dev/chainloop/app/cli/cmd.defaultCpAPI=api.cp.acme.com:443'" app/cli/main.go +go build -ldflags "-X 'github.com/chainloop-dev/chainloop/app/cli/cmd.defaultCASAPI=api.cas.acme.com:443' -X 'github.com/chainloop-dev/chainloop/app/cli/cmd.defaultCPAPI=api.cp.acme.com:443'" app/cli/main.go ``` ## Contribution guidelines diff --git a/app/cli/cmd/root.go b/app/cli/cmd/root.go index 879480427..254588ac8 100644 --- a/app/cli/cmd/root.go +++ b/app/cli/cmd/root.go @@ -37,8 +37,8 @@ var ( flagOutputFormat string actionOpts *action.ActionsOpts logger zerolog.Logger - defaultCpAPI = "api.cp.chainloop.dev:443" - defaultCasAPI = "api.cas.chainloop.dev:443" + defaultCPAPI = "api.cp.chainloop.dev:443" + defaultCASAPI = "api.cas.chainloop.dev:443" ) const useWorkflowRobotAccount = "withWorkflowRobotAccount" @@ -95,11 +95,11 @@ func NewRootCmd(l zerolog.Logger) *cobra.Command { rootCmd.PersistentFlags().StringVarP(&flagCfgFile, "config", "c", "", "Path to an existing config file (default is $HOME/.config/chainloop/config.toml)") - rootCmd.PersistentFlags().String(confOptions.controlplaneAPI.flagName, defaultCpAPI, "URL for the Control Plane API") + rootCmd.PersistentFlags().String(confOptions.controlplaneAPI.flagName, defaultCPAPI, "URL for the Control Plane API") err := viper.BindPFlag(confOptions.controlplaneAPI.viperKey, rootCmd.PersistentFlags().Lookup(confOptions.controlplaneAPI.flagName)) cobra.CheckErr(err) - rootCmd.PersistentFlags().String(confOptions.CASAPI.flagName, defaultCasAPI, "URL for the Artifacts Content Addressable Storage (CAS)") + rootCmd.PersistentFlags().String(confOptions.CASAPI.flagName, defaultCASAPI, "URL for the Artifacts Content Addressable Storage (CAS)") err = viper.BindPFlag(confOptions.CASAPI.viperKey, rootCmd.PersistentFlags().Lookup(confOptions.CASAPI.flagName)) cobra.CheckErr(err)