Handle an edge case when using bin/web (#1075)

* Handle an edge case when using bin/web

There's a weird error running `bin/web dev` if you don't have conduit installed on a kubernetes cluster. Nothing in the docs mention that you need to work on this.

Output a user friendly error when we can't find a pod and update the docs to remind folks to install conduit first. Fixes #1070

* Wrap text, send to stderr, fail when missing
This commit is contained in:
Thomas Rampelberg 2018-06-06 16:44:28 -07:00 committed by GitHub
parent bd6b5d0944
commit 9889597c29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 32 deletions

View File

@ -251,8 +251,9 @@ bin/web run
The web server will be running on `localhost:8084`. The web server will be running on `localhost:8084`.
Note the `web` process depends on a `public-api` server, for which you have Note: by default, this requires a `public-api` server and assumes that it is
three options: running in a Kubernetes cluster. If that isn't the case, you have some other
options:
#### 1. Connect to `public-api` locally #### 1. Connect to `public-api` locally
@ -270,29 +271,6 @@ docker-compose stop web
bin/web run --api-addr=$DOCKER_IP:8085 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 ### Webpack dev server
To develop with a webpack dev server, run: To develop with a webpack dev server, run:
@ -301,6 +279,8 @@ To develop with a webpack dev server, run:
bin/web dev bin/web dev
``` ```
Note: you'll want to install conduit on a Kubernetes cluster first.
To add a JS dependency: To add a JS dependency:
```bash ```bash

27
bin/web
View File

@ -23,6 +23,15 @@ USAGE: web <command>
USAGE USAGE
}; function --help { -h ;} }; 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 { function dev {
build build
@ -32,7 +41,7 @@ function dev {
esac esac
done done
port-forward & check-for-conduit && (port-forward &)
cd $ROOT/web/app && yarn webpack-dev-server --port $DEV_PORT & cd $ROOT/web/app && yarn webpack-dev-server --port $DEV_PORT &
cd $ROOT/web && \ cd $ROOT/web && \
@ -44,18 +53,22 @@ function build {
yarn webpack 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 { function port-forward {
nc -z localhost 8085 || kubectl --namespace=conduit port-forward $( nc -z localhost 8085 || \
kubectl --namespace=conduit get po \ kubectl --namespace=conduit port-forward $(get-pod) 8085:8085
--selector=conduit.io/control-plane-component=controller \
-o jsonpath='{.items[*].metadata.name}'
) 8085:8085
} }
function run { function run {
build build
port-forward & check-for-conduit && (port-forward &)
cd $ROOT/web cd $ROOT/web
../bin/go-run . $* ../bin/go-run . $*