Blรคddra i kรคllkod

scripts: add dev-setup.sh

Change-Id: Idc11a193674616b4c07e0faed84c1b1dee24cbf2
Leo 4 รฅr sedan
fรถrรคlder
incheckning
845055f87b
2 รคndrade filer med 162 tillรคgg och 3 borttagningar
  1. 55 3
      DEVELOP.md
  2. 107 0
      scripts/dev-setup.sh

+ 55 - 3
DEVELOP.md

@@ -65,6 +65,54 @@ Tear down cluster:
 
 Once you're done, press Ctrl-C. Run `tilt down` to tear down the devnet.
 
+## Getting started on a development VM
+
+This tutorial assumes a clean Debian >=10 VM. We recommend at least **16 vCPU, 64G of RAM and 500G of disk**.
+Rust eats CPU for breakfast, so the more CPUs, the nicer your Solana compilation experience will be.
+
+Install Git first:
+
+    sudo apt-get install -y git
+
+First, create an SSH key in your shell:
+
+    ssh-keygen -t ed25519
+    cat .ssh/id_ed25519.pub
+
+You can then [add your public key on Gerrit](https://forge.certus.one/settings/#SSHKeys) and [clone the repository](https://forge.certus.one/admin/repos/wormhole) in your shell. The clone command should look like this:
+
+```shell
+# don't copy this - copy it from Gerrit instead
+git clone "ssh://yourusername@forge.certus.one:30322/wormhole" && scp -p -P 30322 yourusername@forge.certus.one:hooks/commit-msg "wormhole/.git/hooks/"
+```
+
+Configure your Git identity to match your Gerrit name and email:
+
+    git config --global user.name "Your Name"
+    git config --global user.email "yourname@company.com"
+
+*If you are a Jump Crypto employee, make sure to log into Gerrit using Azure SSO using your
+jumptrading.com email address and request Gerrit review permissions in #wormhole-dev on Slack.*
+
+You can then use our regular Git and Gerrit workflow as detailed in [Submit change for review](./CONTRIBUTING.md#Submit change for review).
+
+### Set up devnet on the VM
+
+After cloning the repo, run the setup script:
+
+    scripts/devnet-setup.sh
+
+You then need to close and re-open your session to apply the new environment.
+If you use persistent SSH sessions, make sure to kill the session before reconnecting.
+
+You can then run tilt normally (see above).
+
+The easiest way to get access to the Tilt UI is to simply run Tilt on a public port, and use a firewall
+of your choice to control access:
+
+    tilt up --host=0.0.0.0 --port=8080
+
+## Tips and tricks
 
 ### Post messages
 
@@ -77,21 +125,25 @@ To Solana as CPI instruction:
     kubectl exec solana-devnet-0 -c setup -- client post-message --proxy CP1co2QMMoDPbsmV7PGcUTLFwyhgCgTXt25gLQ5LewE1 Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o 1 confirmed ffff
 
 
-## IntelliJ Protobuf Autocompletion
+### IntelliJ Protobuf Autocompletion
+
+Locally compile protos to populate the buf cache:
+
+    make generate
 
 Set the include path:
 
 ![](https://i.imgur.com/bDij6Cu.png)
 
 
-## BigTable event persistence
+### BigTable event persistence
 
 Guardian events can be persisted to a cloud BigTable instance by passing a GCP project and service account key to Tilt.
 Launch the devnet with flags supplying your database info to forward events to your cloud BigTable, rather than the local devnet BigTable emulator:
 
     tilt up -- --num=1  --gcpProject=your-project-id --bigTableKeyPath=./your-service-account-key.json
 
-## bridge UI
+### bridge UI
 
 Run the bridge UI in devnet by supplying the `--bridge_ui` flag:
 

+ 107 - 0
scripts/dev-setup.sh

@@ -0,0 +1,107 @@
+#!/usr/bin/env bash
+#
+# This script provisions a working Wormhole dev environment on a blank Debian VM.
+# It expects to run as a user without root permissions.
+#
+# Can safely run multiple times to update to the latest versions.
+#
+
+# Make sure this is Debian 10 or 11
+if [ "$(lsb_release -rs)" != "10" ] && [ "$(lsb_release -rs)" != "11" ]; then
+  echo "This script is only for Debian 10 or 11"
+  exit 1
+fi
+
+# Refuse to run as root
+if [[ $EUID -eq 0 ]]; then
+    echo "This script must not be run as root" 1>&2
+    exit 1
+fi
+
+# Check if we can use sudo to get root
+if ! sudo -n true; then
+    echo "This script requires sudo to run."
+    exit 1
+fi
+
+# Make sure Docker Debian package isn't installed
+if dpkg -s docker.io &>/dev/null; then
+    echo "Docker is already installed from Debian's repository. Please uninstall it first."
+    exit 1
+fi
+
+# Upgrade everything
+# (this ensures that an existing Docker CE installation is up to date before continuing)
+sudo apt-get upgrade -y
+
+# Install dependencies
+sudo apt-get update && sudo apt-get -y install bash-completion git git-review vim
+
+# Install Go
+ARCH=amd64
+GO=1.17.3
+
+(
+  if [[ -d /usr/local/go ]]; then
+    sudo rm -rf /usr/local/go
+  fi
+
+  TMP=$(mktemp -d)
+
+  (
+    cd "$TMP"
+    curl -OJ "https://dl.google.com/go/go${GO}.linux-${ARCH}.tar.gz"
+    sudo tar -C /usr/local -xzf "go${GO}.linux-${ARCH}.tar.gz"
+
+    echo 'PATH=/usr/local/go/bin:$PATH' | sudo tee /etc/profile.d/local_go.sh
+  )
+
+  rm -rf "$TMP"
+)
+
+. /etc/profile.d/local_go.sh
+
+# Install Docker and add ourselves to Docker group
+if [[ ! -d /var/lib/docker ]]; then
+  curl -fsSL https://get.docker.com -o get-docker.sh
+  sudo sh get-docker.sh
+  sudo gpasswd -a $USER docker
+fi
+
+sudo systemctl enable --now docker
+
+# Install Minikube
+curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
+sudo dpkg -i minikube_latest_amd64.deb
+
+# Install tilt
+curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | sudo bash
+
+# Shell aliases
+cat <<'EOF' | sudo tee /etc/profile.d/wormhole_aliases.sh
+alias kubectl="minikube kubectl --"
+alias vi=vim
+alias kc=kubectl
+
+. <(kubectl completion bash)
+. <(minikube completion bash)
+complete -F __start_kubectl kc
+
+function use-namespace {
+  kubectl config set-context --current --namespace=$1
+}
+
+export DOCKER_BUILDKIT=1
+
+alias start-recommended-minikube="minikube start --driver=docker --kubernetes-version=v1.22.3 --cpus=16 --memory=16G --disk-size=120g"
+EOF
+
+cat <<EOF
+โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”‘
+โ”‚                                                                 โ”‚
+โ”‚                            SUCCESS                              โ”‚
+โ”‚                                                                 โ”‚
+โ”‚           Re-log into your session to apply changes.            โ”‚
+โ”‚                                                                 โ”‚
+โ””โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”˜
+EOF