From fc9bd7c7a76d62041c2a69b2ed7b0d31335c9756 Mon Sep 17 00:00:00 2001 From: Greg Cobb Date: Tue, 11 Jun 2024 17:06:04 -0700 Subject: [PATCH] Small UI improvements to scripts --- README.md | 327 ++++++++++++++++++++++++++++--------- lib/claim-bosh-lite.bash | 2 +- lib/target-bosh.bash | 10 +- lib/unclaim-bosh-lite.bash | 2 +- 4 files changed, 255 insertions(+), 86 deletions(-) diff --git a/README.md b/README.md index 0ee49b4..cc9f76e 100644 --- a/README.md +++ b/README.md @@ -1,68 +1,10 @@ -## capi workstation setup 🐋 +## CAPI Workstation Helpers 🐋 -Hello there! This repo is intended to provide light-weight setup to developing on CAPI projects. +Hello there! This repo is intended to help with development work on CAPI +projects. ![capi](https://im-01.gifer.com/9Y0s.gif) -## Dependencies -* Mac OSX Sierra -* pip - -## Installation - -``` - mkdir -p ~/workspace && cd ~/workspace - git clone git@github.com:cloudfoundry/capi-workspace.git && cd capi-workspace -``` - -You can now either install via `./install.sh` or `./install-core.sh`. - -Or curl the bootstrap script, which will create the `workspace` directory and clone this repo for you. -This is primarily intended for quickly setting up virtual workstations. - -``` -bash <(curl -s https://raw.githubusercontent.com/cloudfoundry/capi-workspace/main/bootstrap.sh) -``` -**Make sure you ssh in as the "pivotal" user** - -## Manual steps (to be automated later) -* Open System Preferences / Users & Groups / / Login Items - * Add `flycut` from Applications - * Add `spectacle` from Applications -* Log out/Log in - * This will cause Flycut and Spectacle to run and ask for permissions -* Open up Rubymine manually and select `License Server` and copy in the the rubymine license from the labs license server (http://omaha.pivotallabs.com:8080/licenseServer in the SF office) - - If you are not on a Pivotal Network, you need to VPN into one in order to access this server. -* Install the `mine` cli shortcut (RubyMine -> Tools -> Create Command-line Launcher...) -* If you are using Goland do the same two previous steps for Goland -* If you have access to the private CAPI backlog, add a secure note called `tracker_api_token` to LastPass with your Pivotal Tracker API token. This token will be used in scripts such as `claim_bosh_lite` to pull story titles currently in flight. - -## Contributing to this repo - -* kindly consider when a change is worth making to `install-core.sh` versus `install.sh`. -* [bash-it](https://github.com/Bash-it/bash-it) We use bash-it to organize and streamline our bash settings. This includes stuff like color schemes, aliases, shell settings, and the shell prompt formatting. Adding "plugins" to `custom-bash-it-plugins` will cause them to be installed in every new shell. - -## What this installation does - -`install-core.sh`: intended to be more friendly for developers who don't want this repository to take over their machine. This is intended to be the minimal set of things required for working with a CAPI repository. -* Only installs core utilities, languages, services, and binaries. -* Is NOT responsible for installing & configuring any editors (nvim/vscode/intellij) -* Is NOT responsible for installing tools for improving developer workflows (jq/rg) -* Is NOT responsible for applying any git configuration -* Is NOT responsible for loading in scripts that need to be `source`'d. -* Is NOT responsible for modifying your `$PATH` to include `script` - -`./install.sh`: runs `install-core.sh` and configures the machine with many more packages/preferences - -## install.sh or install-core.sh ? - -`install-core.sh` is a subset of `install.sh` and is intended to be less invasive to the machine, without compromising on provisioning a workstation suitable to working on CAPI projects. - -For fresh workstations && full-time CAPI developers, install.sh might make more sense. - -For folks working on multiple projects, `install-core.sh` might make more sense. - -For folks with existing workstations & configuration, `install-core.sh` might make more sense. ## Directory Overview @@ -71,31 +13,27 @@ Description of the folders in this project: Folder | Description ---------------- | ----------- assets | random static files -bash-it | all the bash-it stuff, only bash-it stuff +bash-it | all the [bash-it](https://github.com/Bash-it/bash-it) stuff, only bash-it stuff helpers | random helper files lib | scripts that could be sourced into your shell bin | scripts that can be added to your `$PATH` install-scripts | executable scripts that install a thing or two -Why is `lib` separate from `bash-it`? Not everyone uses bash-it, so `lib` is similar to `scripts`, giving people a way to manually load the things they care about in. For example, one may manually (and minimally) load in capi-workspace content by sourcing a file like this in their `.bash_profile`: +Why is `lib` separate from `bash-it`? Not everyone uses bash-it, so `lib` is +similar to `scripts`, giving people a way to manually load the things they care +about in. + +## Minimal Install + +One may manually (and minimally) load in capi-workspace content by including +the following in their `~/.zshrc` (or equivalent): ```bash -❯ bat bash_sources/load_capi_workspace.zsh -───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── - │ File: bash_sources/load_capi_workspace.zsh -───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── - 1 │ - 2 │ source ~/workspace/capi-workspace/lib/pullify.bash >/dev/null - 3 │ source ~/workspace/capi-workspace/lib/target-bosh.bash >/dev/null - 4 │ source ~/workspace/capi-workspace/lib/claim-bosh-lite.bash >/dev/null - 5 │ source ~/workspace/capi-workspace/lib/unclaim-bosh-lite.bash >/dev/null - 6 │ source ~/workspace/capi-workspace/lib/deploy_only_new_capi.bash >/dev/null - 7 │ - 8 │ export PATH="$PATH:$HOME/workspace/capi-workspace/bin" -───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── -``` - -## CAPI Commands +source <(cat $HOME/workspace/capi-workspace/lib/*) > /dev/null +path+=("$HOME/workspace/capi-workspace/bin") +``` + +## CAPI Helper Commands This table is generated from `assets/capidoc.yml`. It is dynamically available in your terminal using the `capi` command. @@ -161,3 +99,234 @@ workspaces capi-workspaces List and connect to existing K8s CAPI workspaces create-capi-workspace Create a CAPI workspace in K8s cluster ``` + +## Using the Bosh Lite Pool + +As a perk, [CAPI +approvers](https://github.com/cloudfoundry/community/blob/main/toc/working-groups/app-runtime-interfaces.md) +get access to a pool of cf-deployment environments, deployed on bosh lites in a +CFF-managed IaaS account. These environments are displosable, and are only +intended for development use. + +Though it is technically possible to use the pool without them, there are a +number of convenience scripts provided by capi-workspace that make the pool +usable by humans. + +### Prerequisites + +- git +- Clone capi-workspace (this repo) +- Add capi-workspace scripts/functions to your shell (see installation instructions above (or below)) +- Clone https://github.com/cloudfoundry/capi-env-pool + +### Example Pool Dev Workflow + +Claim an environment from the pool: +``` +❯ claim_bosh_lite +Claiming 'distaffs'... +Writing out .envrc... +Pushing reservation to capi-env-pool... +Use 'target_bosh distaffs' to set bosh environment variables. +``` + +Observe that you successfully claimed the environment: +``` +❯ print_env_info +Rounding up claimed environments... + +* ENV * * CLAIMED BY * * CLAIMED ON * * CLAIMED SINCE * +apologia Tim Downey tdowney.hostname 3 weeks ago +distaffs Greg Cobb gcobb.hostname 2 minutes ago +riskier Greg Cobb gcobb.hostname 13 days ago +zoned Seth Boyles capi-ws-cc-203 3 weeks ago +``` + +Set bosh environment variables in your shell to "target" that environment: +``` +❯ target_bosh distaffs + +Refreshing bosh lite pool state... +Already up to date. + +Sourcing /.../capi-env-pool/bosh-lites/claimed/distaffs to set bosh environment variables... + +Writing a capi-specific integration_config.json... +Generated /.../capi-env-pool/distaffs/integration_config.json. Enjoy! + +Writing a bosh gateway ssh key... +Generated /.../capi-env-pool/distaffs/bosh.pem. Enjoy! + +Setting BOSH_GW_PRIVATE_KEY, BOSH_ALL_PROXY, and CONFIG environment variables... +Success! +``` + +Log in to the environment with the `cf` CLI: +``` +❯ target_cf +Getting CF admin password from credhub... +Setting API endpoint to https://api.distaffs.app-runtime-interfaces.ci.cloudfoundry.org... +OK + +API endpoint: https://api.distaffs.app-runtime-interfaces.ci.cloudfoundry.org +API version: 3.166.0 + +Not logged in. Use 'cf login' or 'cf login --sso' to log in. +API endpoint: https://api.distaffs.app-runtime-interfaces.ci.cloudfoundry.org + +Authenticating... +OK + +Use 'cf target' to view or set your target org and space. +``` + +Create a default Organization and Space: +``` +❯ bootstrap_cf +Getting CF admin password from credhub... +Setting API endpoint to https://api.distaffs.app-runtime-interfaces.ci.cloudfoundry.org... +OK + +API endpoint: https://api.distaffs.app-runtime-interfaces.ci.cloudfoundry.org +API version: 3.166.0 + +Not logged in. Use 'cf login' or 'cf login --sso' to log in. +API endpoint: https://api.distaffs.app-runtime-interfaces.ci.cloudfoundry.org + +Authenticating... +OK + +Use 'cf target' to view or set your target org and space. +Creating org org as admin... +OK + +TIP: Use 'cf target -o "org"' to target new org +API endpoint: https://api.distaffs.app-runtime-interfaces.ci.cloudfoundry.org +API version: 3.166.0 +user: admin +org: org +No space targeted, use 'cf target -s SPACE' +Creating space space in org org as admin... +OK + +Assigning role SpaceManager to user admin in org org / space space as admin... +OK + +Assigning role SpaceDeveloper to user admin in org org / space space as admin... +OK + +TIP: Use 'cf target -o "org" -s "space"' to target new space +API endpoint: https://api.distaffs.app-runtime-interfaces.ci.cloudfoundry.org +API version: 3.166.0 +user: admin +org: org +space: space +``` + +Deploy the cf-deployment and capi-release versions from your dev machine: +``` +❯ deploy +Uploading new release to 35.185.252.196. + +Syncing bosh blobs... +bosh sync-blobs +... + +Creating bosh release... +create-release --force --name capi +... + +Uploading release to bosh director... +bosh upload-release --rebase +... + +Deploying uploaded release... +bosh deploy cf-deployment.yml -o... +... +Succeeded +``` + +Make local changes and deploy a new CAPI version: +``` +❯ deploy_only_new_capi +Building a new CAPI from local filesystem and deploying to 35.185.252.196. +bosh deploy <(bosh manifest) -o ...use-created-capi.yml ... +... +Succeeded +``` + +Release the environment for deletion, once you are done with it: +``` +❯ unclaim_bosh_lite riskier +Refreshing bosh lite pool state... +Hit enter to release 'riskier' +rm 'riskier/.envrc' +Pushing the release commit to capi-env-pool... +Done! +``` + +## Automated Workstation Setup + +If you want, there are also some opinionated scripts you can run to set up a +new computer for CAPI development. These may be useful if you are dynamically +provisioning remote workstations, or something like that. + +### Dependencies +* MacOS +* pip + +### Running the Installer + +``` + mkdir -p ~/workspace && cd ~/workspace + git clone git@github.com:cloudfoundry/capi-workspace.git && cd capi-workspace +``` + +You can now either install via `./install.sh` or `./install-core.sh`. + +Or curl the bootstrap script, which will create the `workspace` directory and clone this repo for you. +This is primarily intended for quickly setting up virtual workstations. + +``` +bash <(curl -s https://raw.githubusercontent.com/cloudfoundry/capi-workspace/main/bootstrap.sh) +``` +**Make sure you ssh in as the "pivotal" user** + +## Manual steps (to be automated later) +* Open System Preferences / Users & Groups / / Login Items + * Add `flycut` from Applications + * Add `spectacle` from Applications +* Log out/Log in + * This will cause Flycut and Spectacle to run and ask for permissions +* Open up Rubymine manually and select `License Server` and copy in the the rubymine license from the labs license server (http://omaha.pivotallabs.com:8080/licenseServer in the SF office) + - If you are not on a Pivotal Network, you need to VPN into one in order to access this server. +* Install the `mine` cli shortcut (RubyMine -> Tools -> Create Command-line Launcher...) +* If you are using Goland do the same two previous steps for Goland +* If you have access to the private CAPI backlog, add a secure note called `tracker_api_token` to LastPass with your Pivotal Tracker API token. This token will be used in scripts such as `claim_bosh_lite` to pull story titles currently in flight. + +## Contributing to this repo + +* kindly consider when a change is worth making to `install-core.sh` versus `install.sh`. +* [bash-it](https://github.com/Bash-it/bash-it) We use bash-it to organize and streamline our bash settings. This includes stuff like color schemes, aliases, shell settings, and the shell prompt formatting. Adding "plugins" to `custom-bash-it-plugins` will cause them to be installed in every new shell. + +## What this installation does + +`install-core.sh`: intended to be more friendly for developers who don't want this repository to take over their machine. This is intended to be the minimal set of things required for working with a CAPI repository. +* Only installs core utilities, languages, services, and binaries. +* Is NOT responsible for installing & configuring any editors (nvim/vscode/intellij) +* Is NOT responsible for installing tools for improving developer workflows (jq/rg) +* Is NOT responsible for applying any git configuration +* Is NOT responsible for loading in scripts that need to be `source`'d. +* Is NOT responsible for modifying your `$PATH` to include `script` + +`./install.sh`: runs `install-core.sh` and configures the machine with many more packages/preferences + +## install.sh or install-core.sh ? + +`install-core.sh` is a subset of `install.sh` and is intended to be less invasive to the machine, without compromising on provisioning a workstation suitable to working on CAPI projects. + +For fresh workstations && full-time CAPI developers, install.sh might make more sense. + +For folks working on multiple projects, `install-core.sh` might make more sense. + +For folks with existing workstations & configuration, `install-core.sh` might make more sense. diff --git a/lib/claim-bosh-lite.bash b/lib/claim-bosh-lite.bash index a52d492..2acf911 100755 --- a/lib/claim-bosh-lite.bash +++ b/lib/claim-bosh-lite.bash @@ -24,7 +24,7 @@ function claim_bosh_lite() { for f in $(ls -tr ./bosh-lites/unclaimed/*); do test -f "$f" || continue - msg "Claiming $( basename $f )..." + msg "Claiming '$( basename $f )'..." claim_specific_environment $(basename $f) return $? done diff --git a/lib/target-bosh.bash b/lib/target-bosh.bash index 8288769..c2b78cc 100755 --- a/lib/target-bosh.bash +++ b/lib/target-bosh.bash @@ -21,20 +21,20 @@ target_bosh() { env_integration_config_path="${env_pool}/${1}/integration_config.json" if [ ! -f "${env_integration_config_path}" ]; then - echo "\nWriting a capi-specific integration_config.json...\n" + echo "Writing a capi-specific integration_config.json..." generate_integration_config > "${env_integration_config_path}" - echo -e "\tGenerated ${env_integration_config_path}. Enjoy!" + echo -e "Generated ${env_integration_config_path}. Enjoy!\n" fi env_ssh_key_path="${env_pool}/${1}/bosh.pem" if [ ! -f "${env_ssh_key_path}" ]; then - printf "\nWriting a bosh gateway ssh key...\n" + echo "Writing a bosh gateway ssh key..." echo "${BOSH_GW_PRIVATE_KEY_CONTENTS}" > "${env_ssh_key_path}" chmod 0600 "${env_ssh_key_path}" - echo -e "\tGenerated ${env_ssh_key_path}. Enjoy!" + echo -e "Generated ${env_ssh_key_path}. Enjoy!\n" fi - printf "\nSetting BOSH_GW_PRIVATE_KEY, BOSH_ALL_PROXY, and CONFIG environment variables...\n" + printf "Setting BOSH_GW_PRIVATE_KEY, BOSH_ALL_PROXY, and CONFIG environment variables...\n" export BOSH_GW_PRIVATE_KEY="${env_ssh_key_path}" export BOSH_ALL_PROXY=ssh+socks5://${BOSH_GW_USER}@${BOSH_ENVIRONMENT}:22?private-key=${BOSH_GW_PRIVATE_KEY} export CONFIG="${env_integration_config_path}" diff --git a/lib/unclaim-bosh-lite.bash b/lib/unclaim-bosh-lite.bash index 3e5a39d..2eaebc5 100755 --- a/lib/unclaim-bosh-lite.bash +++ b/lib/unclaim-bosh-lite.bash @@ -38,7 +38,7 @@ function unclaim_bosh_lite() { return 1 fi - printf "Hit enter to release ${env} " + printf "Hit enter to release '${env}' " read -r git mv "${file}" "${broken_pool}/unclaimed/"