TL;DR
I had some issues building the "echo" example. This ticket documents some of my feedback so far.
- A recent Closure compiler release seems to cause failures on Ubuntu 14.04.
- The Pre-Requisites section says the build scripts will be sufficient, but they aren't.
- The instructions for using the Ubuntu 14.04 Docker container are never stated.
- The instructions for running the example have a minor issue with the stated path.
- When running from Docker, need to find the ip address manually.
Some of my confusion may be due to the fact that the Docker container is built in the initial steps, but after that the assumption seems to be that you're running on Ubuntu 14.04 natively. Should I be running inside Docker? If so, a Dockerfile for the example would be a great way to streamline the setup process.
The Narrative
In the "Pre-Requisites" section, the examples document states:
Use the build scripts or follow the step-by-step instruction.
I installed Docker and ran the build script, ./ubuntu_14_04.sh
. With the container created, I used docker run -it ubuntu_14_04
to enter the container and changed to /github/grpc-web
to prepare to build the example from the container. That last bit wasn't quite documented, but I figured it out. So far so good.
Following through the example README, I would expect that at this point the whole pre-requisites section would be done, since I used the build script. However, I don't see the closure compiler in the /github/grpc-web
directory. That's not so bad though, I can go through the steps manually. Most of it should be redundant, but no biggie. I went through all the steps manually, skipping, of course, the MacOS instructions and skipping cloning the repo (since it has already been cloned).
sudo apt-get install autoconf automake build-essential curl git \
default-jdk default-jre libtool libpcre3 libpcre3-dev libssl-dev \
make wget zip
cd third_party/grpc
git submodule update --init
cd third_party/protobuf
./autogen.sh && ./configure && make
sudo make install # install protobuf
cd ../..
EMBED_OPENSSL=false make
sudo EMBED_OPENSSL=false make install # install gRPC
cd /github/grpc-web # go to repo root
wget https://dl.google.com/closure-compiler/compiler-latest.zip -O compiler-latest.zip # I used https instead of http
I didn't notice any errors in the above steps, so at this point all of the pre-requisite steps should definitely be done. Time to build the example:
make example
After chugging for a while, the output yields the following error:
../../../../../third_party/closure-library/closure/bin/build/closurebuilder.py: Compiling with the following command: java -client -jar ../../../../../closure-compiler.jar --flagfile /tmp/tmp1wXE8h
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/google/javascript/jscomp/CommandLineRunner : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:442)
at java.net.URLClassLoader.access$100(URLClassLoader.java:64)
at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:312)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Traceback (most recent call last):
File "../../../../../third_party/closure-library/closure/bin/build/closurebuilder.py", line 293, in <module>
main()
File "../../../../../third_party/closure-library/closure/bin/build/closurebuilder.py", line 282, in main
compiler_flags=options.compiler_flags)
File "/github/grpc-web/third_party/closure-library/closure/bin/build/jscompiler.py", line 160, in Compile
raise JsCompilerError('JavaScript compilation failed.')
jscompiler.JsCompilerError: JavaScript compilation failed.
make[1]: *** [compiled-js] Error 1
make[1]: Leaving directory `/github/grpc-web/net/grpc/gateway/examples/echo'
make: *** [example] Error 2
I inspected the closure compiler, and it seems to be using Java 8, as version "52.0" would imply. The default java version for Ubuntu 14.04 is Java 7 and upgrading it to Java 8 requires a PPA. The most logical cause of this issue I could come up with was the fact that we downloaded the latest closure compiler, which may have introduced this problem since the original example instructions were written.
Reading through the Closure compiler release notes I noted that the Sept 10th 2017 release version says "Building the compiler and its tests now requires Java 8." OK, so we're not building the compiler itself, but it seem plausible that that version may have introduced a backwards compatibility issue for us.
So, I tried downloading the compiler version for Aug 6th 2017, which came just before that Sept 10th release:
rm closer-compiler.jar
wget https://dl.google.com/closure-compiler/compiler-20170806.zip
unzip -p -qq -o compiler-20170806.zip *.jar > closure-compiler.jar
make example
Success! No version error. Now installing and running the script:
sudo make install-example
cd net/grpc/gateway/examples/echo && ./echo_server &
cd gConnector && ./nginx.sh & # This fails! Need to go back to /github/grpc-web first
Since I'm running all this inside the docker container, I grabbed the IP address of the container ("inet addr" from ifconfig eth0
) and opened the web page from the Docker host operating system, in my case it looked like this: http://172.17.0.2:8080/net/grpc/gateway/examples/echo/echotest.html
.
Success! I can send messages and receive the echo from the server.
Next Steps
The Closure compiler is the main issue here. Do we hard-code the August 6th release for now? Do we upgrade Java to Java 8 with a PPA? Upgrade Ubuntu 14.04 to 14.10 or 16.04?
Personally I think it'd be helpful to deal with this at the Dockerfile level. If we created a Dockerfile for the "echo" example, it'd really help new users of the project to get started quickly.