|
| 1 | +# Developer guide for (post)startup script |
| 2 | + |
| 3 | +Verily Workbench provisions VMs post-creation to install workbench specific tools (such as CLI, gcsfuse, ssh-keys for git). |
| 4 | + |
| 5 | +Currently there are three flavors of startup.script: |
| 6 | + |
| 7 | +- vertex AI user-managed notebook |
| 8 | +- dataproc cluster |
| 9 | +- general gce instance (in the startupscript/ folder) |
| 10 | + |
| 11 | +## How to test your change? |
| 12 | + |
| 13 | +### Option 1 |
| 14 | + |
| 15 | +If it's a single line change, you can just create an environment in the devel environment and run the command. |
| 16 | + |
| 17 | +### Option 2 |
| 18 | + |
| 19 | +If it's a complex change, you can point the VM to your new script and test it end-to-end. |
| 20 | + |
| 21 | +#### Vertex AI |
| 22 | + |
| 23 | +- Step 1 |
| 24 | + |
| 25 | +Make your change and push to a branch. |
| 26 | + |
| 27 | +- Step 2 |
| 28 | + |
| 29 | +```text |
| 30 | +wb resource create gcp-notebook --id=jupyterNotebookForTesting --post-startup-script=https://raw.githubusercontent.com/verily-src/workbench-app-devcontainers/<your-branch>/startupscript/vertex-ai-user-managed-notebook/post-startup.sh |
| 31 | +``` |
| 32 | + |
| 33 | +- Step 3 |
| 34 | + Go to the UI and wait till the notebook spins up and verify that it is running. |
| 35 | + |
| 36 | +#### Dataproc |
| 37 | + |
| 38 | +- Step 1 |
| 39 | + |
| 40 | +Make your change and push to a branch. |
| 41 | + |
| 42 | +- Step 2 |
| 43 | + |
| 44 | +```text |
| 45 | +wb resource create dataproc-cluster --name=dataprocForTesting --metadata=startup-script-url=https://raw.githubusercontent.com/verily-src/workbench-app-devcontainers/<your-branch>/startupscript/dataproc/startup.sh |
| 46 | +``` |
| 47 | + |
| 48 | +Pick a workspace that you have previously created a dataproc cluster so you can reuse the buckets. |
| 49 | + |
| 50 | +- Step 3 |
| 51 | + Go to the UI and wait till the notebook spins up and verify that it is running. |
| 52 | + |
| 53 | +#### GCE |
| 54 | + |
| 55 | +- Step 1 |
| 56 | + |
| 57 | +Clone this repo and put it in a public repo you own. Make the change |
| 58 | + |
| 59 | +- Step 2 |
| 60 | + In the UI, create a custom r-analysis app pointing at your personal repo. |
| 61 | + |
| 62 | +- Step 3 |
| 63 | + Wait for the notebook to spin up and go to the instance. Check .workbench/post-startup-output.txt to see if it succeeds. |
| 64 | + |
| 65 | +## Linting and Style |
| 66 | + |
| 67 | +Shell code in this repo will be checked with `shellcheck` as part of pull request testing. |
| 68 | + |
| 69 | +The `shellcheck` tool [can be installed locally](https://github.com/koalaman/shellcheck?tab=readme-ov-file#installing). |
| 70 | +Additionally, VSCode has a [ShellCheck extension](https://marketplace.visualstudio.com/items?itemName=timonwong.shellcheck). |
| 71 | + |
| 72 | +To configure `shellcheck` locally with the same configuration as the PR lint tasks, create a |
| 73 | +`~/.shellcheckrc` file with the following content: |
| 74 | + |
| 75 | +```shell |
| 76 | +disable=SC1090,SC1091 |
| 77 | +``` |
| 78 | + |
| 79 | +This disables checks [SC1090](https://www.shellcheck.net/wiki/SC1090) and |
| 80 | +[SC1091](https://www.shellcheck.net/wiki/SC1091), to work around limitations in |
| 81 | +`shellcheck` around dynamic file handling. |
| 82 | + |
| 83 | +In addition to `shellcheck`-enforced logic, it is highly recommended that variables and functions |
| 84 | +be made `readonly` to prevent overriding or unsetting. |
| 85 | + |
| 86 | +For trivial variable assignment this can be done on a single line: |
| 87 | + |
| 88 | +```shell |
| 89 | +readonly FOO="foo" |
| 90 | +``` |
| 91 | + |
| 92 | +However, for assignments that involve calling a command, `readonly` can mask error responses; in |
| 93 | +these cases the variable should be marked `readonly` as a subsequent step. This is enforced by |
| 94 | +`shellcheck` rule [SC2155](https://www.shellcheck.net/wiki/SC2155). |
| 95 | + |
| 96 | +```shell |
| 97 | +FOO="$(command)" |
| 98 | +readonly FOO |
| 99 | +``` |
| 100 | + |
| 101 | +Functions follow this syntax: |
| 102 | + |
| 103 | +```shell |
| 104 | +function my_function { |
| 105 | + # ... function logic ... |
| 106 | +} |
| 107 | +readonly -f my_func |
| 108 | +``` |
| 109 | + |
| 110 | +## General debugging tips |
| 111 | + |
| 112 | +- Check /home/**\<user\>**/.workbench/post-startup-output.txt to see where the script failed. |
| 113 | + The user is jupyter for vertex AI, dataproc for dataproc cluster, and varies by app for gce instance. |
| 114 | + |
| 115 | +- If the proxy url doesn't work, you can ssh to the VM. |
0 commit comments