Skip to content

Commit c5aa764

Browse files
committed
feat(cli): allow setting default values for Control Plane and CAS endpoints endpoints at the CLI build time
Signed-off-by: Daniel Liszka <daniel@chainloop.dev>
1 parent 90c6765 commit c5aa764

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

app/cli/cmd/root.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ var (
3737
flagOutputFormat string
3838
actionOpts *action.ActionsOpts
3939
logger zerolog.Logger
40+
defaultCpAPI = "api.cp.chainloop.dev:443"
41+
defaultCasAPI = "api.cas.chainloop.dev:443"
4042
)
4143

4244
const useWorkflowRobotAccount = "withWorkflowRobotAccount"
@@ -92,11 +94,12 @@ func NewRootCmd(l zerolog.Logger) *cobra.Command {
9294
rootCmd.SetHelpCommand(&cobra.Command{Hidden: true})
9395

9496
rootCmd.PersistentFlags().StringVarP(&flagCfgFile, "config", "c", "", "Path to an existing config file (default is $HOME/.config/chainloop/config.toml)")
95-
rootCmd.PersistentFlags().String(confOptions.controlplaneAPI.flagName, "api.cp.chainloop.dev:443", "URL for the Control Plane API")
97+
98+
rootCmd.PersistentFlags().String(confOptions.controlplaneAPI.flagName, defaultCpAPI, "URL for the Control Plane API")
9699
err := viper.BindPFlag(confOptions.controlplaneAPI.viperKey, rootCmd.PersistentFlags().Lookup(confOptions.controlplaneAPI.flagName))
97100
cobra.CheckErr(err)
98101

99-
rootCmd.PersistentFlags().String(confOptions.CASAPI.flagName, "api.cas.chainloop.dev:443", "URL for the Artifacts Content Addressable Storage (CAS)")
102+
rootCmd.PersistentFlags().String(confOptions.CASAPI.flagName, defaultCasAPI, "URL for the Artifacts Content Addressable Storage (CAS)")
100103
err = viper.BindPFlag(confOptions.CASAPI.viperKey, rootCmd.PersistentFlags().Lookup(confOptions.CASAPI.flagName))
101104
cobra.CheckErr(err)
102105

devel/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,41 @@ You will get redirected to the pre-configured local OIDC provider (DEX) where th
6969
- `john@chainloop.local`/`password`
7070

7171
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.
72+
73+
## Building CLI
74+
### Updating default values
75+
76+
By default the Chainloop command line tool uses the following values for the Control Plane and Artifacts CAS API endpoints:
77+
78+
- Artifacts CAS: api.cas.chainloop.dev:443
79+
- Control Plane API: api.cp.chainloop.dev:443
80+
81+
You can review them in the Chainloop CLI help message.
82+
83+
```
84+
Flags:
85+
--artifact-cas string URL for the Artifacts Content Addressable Storage (CAS) (default "api.cas.chainloop.dev:443")
86+
-c, --config string Path to an existing config file (default is $HOME/.config/chainloop/config.toml)
87+
--control-plane string URL for the Control Plane API (default "api.cp.chainloop.dev:443")
88+
```
89+
90+
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:
91+
92+
**Example 1** Building the Chainloop CLI:
93+
94+
```
95+
cd chainloop
96+
go build app/cli/main.go
97+
```
98+
99+
**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`.
100+
101+
```
102+
go build -ldflags "-X 'github.com/chainloop-dev/chainloop/app/cli/cmd.defaultCasAPI=api.cas.acme.com:443'" app/cli/main.go
103+
```
104+
105+
**Example 3** Set both the Artifacts CAS and Control Plane endpoints. We use two variables here: `defaultCasAPI` and `defaultCpAPI`.
106+
107+
```
108+
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
109+
```

0 commit comments

Comments
 (0)