go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/docs/development.md (about) 1 # Development 2 3 ## Build 4 5 ### Prerequisites 6 7 Before building from source, be sure to install: 8 9 - [Go 1.21.0+](https://golang.org/dl/) 10 - [Protocol Buffers v21+](https://github.com/protocolbuffers/protobuf/releases) 11 12 On macOS systems with Homebrew, run: `brew install go@1.21 protobuf` 13 14 ## Install from source 15 16 1. Verify that you have Go 1.21+ installed: 17 18 ``` 19 $ go version 20 ``` 21 22 If `go` is not installed or an older version exists, follow instructions 23 on [the Go website](https://golang.org/doc/install). 24 25 2. Clone this repository: 26 27 ```sh 28 $ git clone https://github.com/mondoohq/cnquery.git 29 $ cd cnquery 30 ``` 31 32 3. Build and install on Unix-like systems 33 34 ```sh 35 # Build all providers 36 make providers 37 38 # To install cnquery using Go into the $GOBIN directory: 39 make cnquery/install 40 ``` 41 42 ## Develop cnquery, providers, or resources 43 44 Whenever you change resources, providers, or protos, you must generate files for the compiler. To do this, make sure you 45 have the necessary tools installed (such as protobuf): 46 47 ```bash 48 make prep 49 ``` 50 51 Then, whenever you make changes, just run: 52 53 ```bash 54 make cnquery/generate 55 ``` 56 57 This generates and updates all required files for the build. At this point you can `make cnquery/install` again as 58 outlined above. 59 60 ## Debug providers 61 62 In v9 we introduced providers, which split up the providers into individual go modules. This make it more development 63 more lightweight and speedy. 64 65 To debug a provider locally with cnquery: 66 67 1. Modify the `providers.yaml` in the root folder and add providers you want to test to the `builtin` field. Example: 68 ```yaml 69 builtin: [aws] 70 ``` 71 2. Build and update everything via: 72 ```bash 73 make providers/config 74 ``` 75 3. You can now use and debug your code. For example `make cnquery/install` or start a debugger. 76 4. Once done, please remember to restore `providers.yaml` (or just set back: `builtin: []`) and 77 re-run `make providers/config`. 78 79 80 ## Update provider versions 81 82 Providers each have their own version, which is based on [Semver](https://semver.org/). 83 84 It's often easy to forget to update them. We didn't want to auto-update versions and accidentally release them for now, so you'll have to update versions in order to get the new providers out. 85 86 Here's how to make this process as easy as ๐ฅง 87 88 **Setup** 89 90 In the cnquery repo you can now find the version utility in `providers-sdk/v1/util/version`. 91 92 To make working with it easier, let's alias it: 93 94 ```bash 95 alias version="go run providers-sdk/v1/util/version/version.go" 96 ``` 97 98 **Version checking** 99 100 This utility can check if providers need upgrades. If you use it in `--fast` mode, it won't crawl the entire git change history but only looks for the first change. 101 102 ```bash 103 version check providers/*/ 104 ``` 105 106 ``` 107 ... 108 crawling git history.... 109 โ no changes provider=opcua version=9.0.1 110 crawling git history...... 111 โ provider changed changes=2 provider=os version=9.0.1 112 ... 113 ``` 114 115 It will automatically detect if providers have no changes since their last version bump and count changes that may have happened for those providers that have changed. 116 117 If you prefer not to wait, you can use the `--fast` option which will only look for the first change. 118 119 **Version update** 120 121 Once you are ready to release providers, you can use the `update` command. 122 123 Here is an example showing how the version tool will increment and update all provider versions: 124 125 ```bash 126 version update providers/*/ 127 ``` 128 129 Notable options include: 130 - `--increment` will auto-increment either the patch or minor version for you (eg: `--increment=patch`). Without this option you get the interactive CLI. 131 - `--fast` will do fast change detection (i.e. once a change is found it will create the update) 132 - `--commit` will automatically generate the commit for you and push the branch to github 133 134 If you use the `--commit` option, it will create both the commit and push it back to `origin`: 135 136 ```bash 137 version update providers/*/ --increment=patch --commit 138 ``` 139 140 ``` 141 ... 142 โ committed changes for os-9.0.2, slack-9.0.1, terraform-9.0.1, vcd-9.0.1, vsphere-9.0.1 143 โ running: git push -u origin version/os-9.0.2+slack-9.0.1+terraform-9.0.1+vcd-9.0.1+vsphere-9.0.1 144 โ updates pushed successfully, open: 145 https://github.com/mondoohq/cnquery/compare/version/os-9.0.2+slack-9.0.1+terraform-9.0.1+vcd-9.0.1+vsphere-9.0.1?expand=1 146 ``` 147 148 The final line of this message is the blueprint for the pull request. 149 150 ## Using go workspaces 151 152 In case you want to develop cnquery, cnspec and providers at the same time, you can use go workspaces. This allows you 153 to use the latest updates from each other without having to commit and push changes. 154 155 Here is a sample config for `go.work` in the root folder of `cnquery` and `cnspec`: 156 157 ``` 158 go 1.21 159 160 use ( 161 ./cnquery 162 ./cnquery/providers/arista 163 ./cnquery/providers/aws 164 ./cnquery/providers/azure 165 ./cnquery/providers/equinix 166 ./cnquery/providers/gcp 167 ./cnquery/providers/github 168 ./cnquery/providers/gitlab 169 ./cnquery/providers/google-workspace 170 ./cnquery/providers/ipmi 171 ./cnquery/providers/k8s 172 ./cnquery/providers/ms365 173 ./cnquery/providers/oci 174 ./cnquery/providers/okta 175 ./cnquery/providers/opcua 176 ./cnquery/providers/slack 177 ./cnquery/providers/terraform 178 ./cnquery/providers/vcd 179 ./cnquery/providers/vsphere 180 ./cnspec 181 ) 182 ``` 183 184 ## Contribute changes 185 186 ### Mark PRs with emojis 187 188 We love emojis in our commits. These are their meanings: 189 190 ๐ breaking ๐ bugfix ๐งน cleanup/internals โก speed ๐ docs 191 โจโญ๐๐ smaller or larger features ๐ race condition 192 ๐ MQL ๐ visual ๐ข fix tests ๐ซ auth ๐ฆ falcon ๐ณ container