veyron/tools/playground/compilerd: Support CORS requests, update Dockerfile, add README.
(Copied from https://veyron-review.googlesource.com/#/c/3978/)
This CL adds support for CORS requests, so the playground client can
talk directly to the compile backend.
It also updates the Dockerfile to work with the new "veyron" tool
version, and it adds a README about how to run the compile server
locally.
NOTE: The new playground does not actually work, because the arguments
to the identity command line tool have changed. The call to "identity"
in builder/vbuild.go will need to be updated before this will work.
Change-Id: Ie513127b173025dd73e67f047edcb839c2747f63
diff --git a/tools/playground/README.md b/tools/playground/README.md
new file mode 100644
index 0000000..4bfb1ea
--- /dev/null
+++ b/tools/playground/README.md
@@ -0,0 +1,31 @@
+# Running the playground compile server locally
+
+WARNING: Currently, this will cause your machine to power down after one hour,
+so you probably don't want to do this!
+
+TODO(ribrdb): Provide some simple way to run the Docker image locally for
+development purposes.
+
+Install Docker:
+
+ $ sudo apt-get install lxc-docker-1.1.0
+
+Build the playground Docker image (this will take a while...):
+
+ $ cp ~/.netrc $VEYRON_ROOT/veyron/go/src/veyron/tools/playground/builder/netrc
+
+ $ sudo docker build -t playground $VEYRON_ROOT/veyron/go/src/veyron/tools/playground/builder/.
+
+Install the playground binaries:
+
+ $ go install veyron/tools/playground/...
+
+Run the compiler binary as root:
+
+ $ sudo compilerd
+
+The server should now be running at http://localhost:8181, and responding to
+compile requests at http://localhost:8181/compile.
+
+Note that the server will automatically power down the machine after one hour.
+(It will tell you this when it starts.)
diff --git a/tools/playground/builder/Dockerfile b/tools/playground/builder/Dockerfile
index e1ffcb8..f846ab1 100644
--- a/tools/playground/builder/Dockerfile
+++ b/tools/playground/builder/Dockerfile
@@ -1,11 +1,11 @@
FROM ubuntu
RUN apt-get update
-RUN apt-get install -y curl git
+RUN apt-get install -y curl git golang
ENV HOME /root
ENV VEYRON_ROOT /usr/local/veyron
ADD netrc /root/.netrc
RUN curl -u veyron:D6HT]P,LrJ7e https://www.envyor.com/noproxy/veyron-setup.sh | bash
-RUN /usr/local/veyron/bin/veyron setup proximity
+RUN /usr/local/veyron/bin/veyron profile setup core
RUN rm /root/.netrc
WORKDIR /usr/local/veyron/veyron
@@ -13,7 +13,7 @@
RUN go install veyron/tools/identity veyron/services/mounttable/mounttabled veyron2/vdl/vdl
RUN go install veyron/tools/playground/builder veyron/tools/playground/compilerd
-RUN adduser --quiet --disabled-password playground
+RUN /usr/sbin/useradd -d /home/playground -m playground
USER playground
WORKDIR /home/playground
diff --git a/tools/playground/compilerd/main.go b/tools/playground/compilerd/main.go
index 83f778e..fceef3b 100644
--- a/tools/playground/compilerd/main.go
+++ b/tools/playground/compilerd/main.go
@@ -37,10 +37,25 @@
}
func handler(w http.ResponseWriter, r *http.Request) {
+ // CORS headers.
+ // TODO(nlacasse): Fill the origin header in with actual playground origin
+ // before going to production.
+ w.Header().Set("Access-Control-Allow-Origin", "*")
+ w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
+ w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding")
+
+ // CORS sends an OPTIONS pre-flight request to make sure the request will be
+ // allowed.
+ if r.Method == "OPTIONS" {
+ w.WriteHeader(http.StatusOK)
+ return
+ }
+
if r.Body == nil || r.Method != "POST" {
w.WriteHeader(http.StatusBadRequest)
return
}
+
id := <-uniq
cmd := Docker("run", "-i", "--name", id, "playground")
cmd.Stdin = r.Body