|
| 1 | +--- |
| 2 | +title: "The native CLI" |
| 3 | +description: "Contribution docs for the native CLI" |
| 4 | +pagefind: true |
| 5 | +--- |
| 6 | + |
| 7 | +This executable sets up a local development cluster with a pass-through |
| 8 | +container registry, mount-through nix store and external load balancer. It's |
| 9 | +automatically accessible as a tool in the `nativelink` development flake and |
| 10 | +self contained to be usable in external projects. |
| 11 | + |
| 12 | +:::danger |
| 13 | +Make sure that you don't have an existing Pulumi stack or `kubectl` context |
| 14 | +active. Otherwise you might accidentally deploy into clusters other than the |
| 15 | +local kind cluster that the native CLI creates. |
| 16 | +::: |
| 17 | + |
| 18 | +import { Tabs, TabItem } from '@astrojs/starlight/components'; |
| 19 | + |
| 20 | +<Tabs syncKey="deployment"> |
| 21 | + <TabItem label="NativeLink nix flake"> |
| 22 | + To run the cluster: |
| 23 | + |
| 24 | + ```bash |
| 25 | + native up |
| 26 | + ``` |
| 27 | + |
| 28 | + To shut the cluster down: |
| 29 | + |
| 30 | + ```bash |
| 31 | + native down |
| 32 | + ``` |
| 33 | + </TabItem> |
| 34 | + <TabItem label="Standalone invocation"> |
| 35 | + To run the cluster from outside of the development flake: |
| 36 | + |
| 37 | + ```bash |
| 38 | + nix run github:TraceMachina/nativelink#native up |
| 39 | + ``` |
| 40 | + |
| 41 | + To shut the cluster down from outside of the development flake: |
| 42 | + |
| 43 | + ```bash |
| 44 | + nix run github:TraceMachina/nativelink#native down |
| 45 | + ``` |
| 46 | + </TabItem> |
| 47 | +</Tabs> |
| 48 | + |
| 49 | +:::note |
| 50 | +The containers for the container registry and the load balancer are currently |
| 51 | +not cleaned up and need to be deleted manually: |
| 52 | + |
| 53 | +```bash |
| 54 | +# Get the container IDs for the registry and load balancer |
| 55 | +docker container ls |
| 56 | +``` |
| 57 | +```bash |
| 58 | +# Delete the images |
| 59 | +docker container stop SOME_CONTAINER_ID |
| 60 | +docker container rm SOME_CONTAINER_ID |
| 61 | +``` |
| 62 | +::: |
| 63 | + |
| 64 | +## Updating dependencies |
| 65 | + |
| 66 | +From within the Nix flake: |
| 67 | + |
| 68 | +```bash |
| 69 | +go get -u ./... |
| 70 | +go mod tidy |
| 71 | +``` |
| 72 | + |
| 73 | +Then go to [`default.nix`](https://github.com/TraceMachina/nativelink/blob/main/native-cli/default.nix) |
| 74 | +and adjust the `vendorHash` field: |
| 75 | + |
| 76 | +import { Steps } from "@astrojs/starlight/components"; |
| 77 | + |
| 78 | +<Steps> |
| 79 | + |
| 80 | +1. Change one character in the hash to invalidate it. Otherwise nix would |
| 81 | + wrongly reuse locally cached go modules the package updates. |
| 82 | +2. Run `nix develop` |
| 83 | +3. You should see an error message like: |
| 84 | + |
| 85 | + ```txt |
| 86 | + error: hash mismatch in fixed-output derivation ... |
| 87 | + specified: XXX |
| 88 | + got: YYY |
| 89 | + ``` |
| 90 | + |
| 91 | +4. Substitute the old `vendorHash` value with `YYY`. |
| 92 | +5. Re-run `nix develop`. It should now build. |
| 93 | + |
| 94 | +</Steps> |
| 95 | + |
| 96 | +## Making code changes |
| 97 | + |
| 98 | +Ensure that the entire application remains self-contained. This means that no |
| 99 | +dynamic paths should point into the `nativelink` repository. Instead, use the |
| 100 | +[`//go:embed`](https://pkg.go.dev/embed) directive to embed for example |
| 101 | +templates into the executable rather than reading them disk at runtime. |
| 102 | + |
| 103 | +The same applies to the packaging logic in [`default.nix`](https://github.com/TraceMachina/nativelink/blob/main/native-cli/default.nix). |
| 104 | +Pulumi should be bundled via a nix wrapper so that we don't rely on a user's |
| 105 | +local Pulumi installation. |
0 commit comments