diff --git a/BUILD.md b/BUILD.md index 9b658d55a..9abbc9992 100644 --- a/BUILD.md +++ b/BUILD.md @@ -251,8 +251,9 @@ bin/web run The web server will be running on `localhost:8084`. -Note the `web` process depends on a `public-api` server, for which you have -three options: +Note: by default, this requires a `public-api` server and assumes that it is +running in a Kubernetes cluster. If that isn't the case, you have some other +options: #### 1. Connect to `public-api` locally @@ -270,29 +271,6 @@ docker-compose stop web bin/web run --api-addr=$DOCKER_IP:8085 ``` -#### 3. Connect to `public-api` in Kubernetes - -If you are running the public API server in Kubernetes, forward `localhost:8085` -to the Conduit controller pod: - -```bash -kubectl --namespace=conduit port-forward $( - kubectl --namespace=conduit get po --selector=conduit.io/control-plane-component=controller -o jsonpath='{.items[*].metadata.name}' -) 8085:8085 -``` - -Note: you can also do this via: - -```bash -bin/web port-forward -``` - -Then connect the local web process to the forwarded port: - -```bash -bin/web run --api-addr=localhost:8085 -``` - ### Webpack dev server To develop with a webpack dev server, run: @@ -301,6 +279,8 @@ To develop with a webpack dev server, run: bin/web dev ``` +Note: you'll want to install conduit on a Kubernetes cluster first. + To add a JS dependency: ```bash diff --git a/bin/web b/bin/web index c9ac9904c..66e34bf12 100755 --- a/bin/web +++ b/bin/web @@ -23,6 +23,15 @@ USAGE: web USAGE }; function --help { -h ;} +function check-for-conduit { + pod=$(get-pod) + + if [[ -z "${pod// }" ]]; then + err "Controller is not running. Have you installed Conduit?" + exit 1 + fi +} + function dev { build @@ -32,7 +41,7 @@ function dev { esac done - port-forward & + check-for-conduit && (port-forward &) cd $ROOT/web/app && yarn webpack-dev-server --port $DEV_PORT & cd $ROOT/web && \ @@ -44,18 +53,22 @@ function build { yarn webpack } +function get-pod { + kubectl --namespace=conduit get po \ + --selector=conduit.io/control-plane-component=controller \ + --field-selector='status.phase==Running' \ + -o jsonpath='{.items[*].metadata.name}' +} + function port-forward { - nc -z localhost 8085 || kubectl --namespace=conduit port-forward $( - kubectl --namespace=conduit get po \ - --selector=conduit.io/control-plane-component=controller \ - -o jsonpath='{.items[*].metadata.name}' - ) 8085:8085 + nc -z localhost 8085 || \ + kubectl --namespace=conduit port-forward $(get-pod) 8085:8085 } function run { build - port-forward & + check-for-conduit && (port-forward &) cd $ROOT/web ../bin/go-run . $*