diff options
author | humper <humper@google.com> | 2014-10-01 14:27:31 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-01 14:27:31 -0700 |
commit | b77955e1b1b94f5a472b4f5fc620d5dc83425a1f (patch) | |
tree | 0c8a9358ce4a2bf6d6d347ce35cb15c94f528eab /experimental | |
parent | 4942e7550ec80796132ab1ce2cc935a5dd1b464c (diff) |
complete overhaul of webtry work partition between jail and host
BUG=skia:
Review URL: https://codereview.chromium.org/619943002
Diffstat (limited to 'experimental')
-rwxr-xr-x | experimental/webtry/build | 5 | ||||
-rwxr-xr-x | experimental/webtry/scripts/fiddle_gyp | 14 | ||||
-rwxr-xr-x | experimental/webtry/scripts/fiddle_ninja | 14 | ||||
-rwxr-xr-x | experimental/webtry/scripts/fiddle_run | 15 | ||||
-rwxr-xr-x | experimental/webtry/scripts/fiddle_wrapper | 19 | ||||
-rwxr-xr-x | experimental/webtry/setup/continue_install | 61 | ||||
-rwxr-xr-x | experimental/webtry/setup/continue_install.sh | 32 | ||||
-rwxr-xr-x | experimental/webtry/setup/continue_install_jail.sh | 42 | ||||
-rwxr-xr-x | experimental/webtry/setup/setup_jail.sh | 6 | ||||
-rwxr-xr-x | experimental/webtry/setup/webtry_setup.sh | 48 | ||||
-rw-r--r-- | experimental/webtry/sys/webtry_schroot | 3 | ||||
-rw-r--r-- | experimental/webtry/templates/template.gyp | 16 | ||||
-rw-r--r-- | experimental/webtry/webtry.go | 60 |
13 files changed, 201 insertions, 134 deletions
diff --git a/experimental/webtry/build b/experimental/webtry/build index 44791a21ef..8536dbce16 100755 --- a/experimental/webtry/build +++ b/experimental/webtry/build @@ -11,6 +11,11 @@ [ -z "$SKIA_ROOT" ] && SKIA_ROOT="../.." [ -z "$WEBTRY_ROOT" ] && WEBTRY_ROOT=`pwd` +[ -z "$GOROOT" ] && export GOROOT=/home/webtry/go +[ -z "$GOPATH" ] && export GOPATH=/home/webtry/golib + +PATH=$PATH:$GOROOT/bin + cd ${SKIA_ROOT}/include echo "Creating compile template..." find core effects pathops -maxdepth 1 -name "*.h" | sed "s#^[^\/]*\/##g" | sed "s/\(.*\)/#include \"\1\"/" | sort > ${WEBTRY_ROOT}/templates/template.cpp diff --git a/experimental/webtry/scripts/fiddle_gyp b/experimental/webtry/scripts/fiddle_gyp new file mode 100755 index 0000000000..93f9943365 --- /dev/null +++ b/experimental/webtry/scripts/fiddle_gyp @@ -0,0 +1,14 @@ +#!/bin/bash + +# fiddle_gyp will copy the fiddle-specific gyp file from the cache +# into the local skia tree, and generate the necessary ninja build +# files. +# +# Because gyp is really picky about directory structures, this is +# necessary to avoid re-building the entire skia library every time. + +[ -z "$SKIA_ROOT" ] && SKIA_ROOT="../../../" +[ -z "$WEBTRY_CACHE_DIR" ] && WEBTRY_CACHE_DIR="../../../../cache" + +cp $WEBTRY_CACHE_DIR/$1.gyp $SKIA_ROOT/gyp +(cd $SKIA_ROOT ; ./gyp_skia gyp/$1.gyp gyp/most.gyp -D skia_gpu=0) diff --git a/experimental/webtry/scripts/fiddle_ninja b/experimental/webtry/scripts/fiddle_ninja new file mode 100755 index 0000000000..2a3e58000b --- /dev/null +++ b/experimental/webtry/scripts/fiddle_ninja @@ -0,0 +1,14 @@ +#!/bin/bash + +# fiddle_ninja simply builds a Release version of the +# provided fiddle into the local skia tree's out/Release +# directory. +# +# This script must be run after fiddle_gyp + +[ -z $SKIA_ROOT ] && SKIA_ROOT="/skia_build/skia" + +PATH=$PATH:/skia_build/depot_tools + +ninja -C $SKIA_ROOT/out/Release $1 + diff --git a/experimental/webtry/scripts/fiddle_run b/experimental/webtry/scripts/fiddle_run new file mode 100755 index 0000000000..f07c04df54 --- /dev/null +++ b/experimental/webtry/scripts/fiddle_run @@ -0,0 +1,15 @@ +#!/bin/bash + +# fiddle_run executes the build fiddle (from the local +# skia tree's out/Release directory) and places the output +# png into the inout directory so it can be seen +# outside the chroot jail and served back to the user. + +[ -z $SKIA_ROOT ] && SKIA_ROOT="/skia_build/skia" +[ -z $WEBTRY_INOUT ] && WEBTRY_INOUT="/skia_build/inout" + +if [ "$#" -eq 2 ]; then + FIDDLE_SOURCE_ARGS="--source $WEBTRY_INOUT/$2" +fi + +$SKIA_ROOT/out/Release/$1 --out $WEBTRY_INOUT/$1.png $FIDDLE_SOURCE_ARGS diff --git a/experimental/webtry/scripts/fiddle_wrapper b/experimental/webtry/scripts/fiddle_wrapper new file mode 100755 index 0000000000..a68b360015 --- /dev/null +++ b/experimental/webtry/scripts/fiddle_wrapper @@ -0,0 +1,19 @@ +#!/bin/bash + +# fiddle_wrapper takes the hash of the fiddle as its first argument, and a source image to include as an +# optional second. Then it: +# +# 1) runs fiddle_gyp to create the gyp file +# 2) runs fiddle_ninja to build the executable +# 3) runs fiddle_run to generate the output .png file. +# +# the output PNG file goes into the inout directory, which is shared between the chroot +# jail and the webserver environment. + +[ -z "$SKIA_ROOT" ] && SKIA_ROOT="/skia_build/skia" + +cd $SKIA_ROOT/experimental/webtry/scripts + +./fiddle_gyp $1 +./fiddle_ninja $1 +./fiddle_run $1 $2 diff --git a/experimental/webtry/setup/continue_install b/experimental/webtry/setup/continue_install deleted file mode 100755 index 405d0dc3d9..0000000000 --- a/experimental/webtry/setup/continue_install +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash -# -# Don't execute this script directly, instead it is copied into the webtry -# user's directory and executed as the user webtry by the webtry_setup.sh -# script. -# -# See the README file for detailed installation instructions. -cd -pwd - -# Install depot_tools. -if [ -d depot_tools ]; then - (cd depot_tools && git pull); -else - git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git; -fi -export PATH=$PATH:$HOME/depot_tools - -# Install Go -if [ -d go ]; then - echo Go already installed. -else - wget https://go.googlecode.com/files/go1.2.1.linux-amd64.tar.gz - tar -xzf go1.2.1.linux-amd64.tar.gz -fi -export GOROOT=$HOME/go -mkdir=$HOME/golib -export GOPATH=$HOME/golib - -export PATH=$PATH:$GOROOT/bin - -mkdir /home/webtry/cache -mkdir /home/webtry/cache/src -mkdir /home/webtry/inout -chmod 777 /home/webtry/inout - -# Sometimes you need to test patches on the server, to do that uncomment -# the following commented out lines and update the PATCH env variable to the -# name of the codereview to use. - -# rm -rf skia - -# Checkout the skia code and dependencies. -mkdir skia -cd skia -gclient config --name . https://skia.googlesource.com/skia.git -gclient sync -git checkout master - -# PATCH=issue196723021_100001.diff -# rm $PATCH -# wget https://codereview.chromium.org/download/$PATCH -# git apply $PATCH - -GYP_GENERATORS=ninja ./gyp_skia gyp/webtry.gyp gyp/most.gyp -Dskia_gpu=0 -ninja -C out/Release webtry - -cd experimental/webtry - -go get -d -./build
\ No newline at end of file diff --git a/experimental/webtry/setup/continue_install.sh b/experimental/webtry/setup/continue_install.sh new file mode 100755 index 0000000000..3cf54570cc --- /dev/null +++ b/experimental/webtry/setup/continue_install.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# The continue_install script updates the jail's copy of depot tools and the latest +# verion of skia. It then builds the skia libraries inside the jail, and builds the webtry +# server outside the jail. +# +# See the README file for detailed installation instructions. + +CHROOT_JAIL=/srv/chroot/webtry_gyp +sudo cp continue_install_jail.sh ${CHROOT_JAIL}/bin/continue_install_jail.sh +sudo chmod 755 ${CHROOT_JAIL}/bin/continue_install_jail.sh +sudo chroot ${CHROOT_JAIL} /bin/continue_install_jail.sh +sudo chown -R webtry:webtry ${CHROOT_JAIL}/skia_build/skia +cd + +# Install Go +if [ -d go ]; then + echo Go already installed. +else + wget https://storage.googleapis.com/golang/go1.3.3.linux-amd64.tar.gz + tar -xzf go1.3.3.linux-amd64.tar.gz +fi + +mkdir ${HOME}/golib +export GOROOT=${HOME}/go +export GOPATH=${HOME}/golib +export PATH=$PATH:$GOROOT/bin + +cd skia/experimental/webtry + +go get -d +./build diff --git a/experimental/webtry/setup/continue_install_jail.sh b/experimental/webtry/setup/continue_install_jail.sh new file mode 100755 index 0000000000..7c303bb96f --- /dev/null +++ b/experimental/webtry/setup/continue_install_jail.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# this script runs as root inside the chroot environment and updates the depot tools, go environment, +# and skia source. + +# need to mount /dev/shm first so that python will execute properly. + +mount /dev/shm + +SKIA_BUILD=/skia_build +cd ${SKIA_BUILD} + +# Install depot_tools. +if [ -d depot_tools ]; then + (cd depot_tools && git pull); +else + git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git; +fi +export PATH=$PATH:${SKIA_BUILD}/depot_tools + +# Sometimes you need to test patches on the server, to do that uncomment +# the following commented out lines and update the PATCH env variable to the +# name of the codereview to use. + +# rm -rf skia + +# Checkout the skia code and dependencies. +mkdir skia +cd skia +gclient config --name . https://skia.googlesource.com/skia.git +gclient sync +git checkout master + +# PATCH=issue196723021_100001.diff +# rm $PATCH +# wget https://codereview.chromium.org/download/$PATCH +# git apply $PATCH + +SKIA_GYP_OUTPUT_DIR=${SKIA_BUILD}/skia/out GYP_GENERATORS=ninja ./gyp_skia -Dskia_gpu=0 + +ninja -C ${SKIA_BUILD}/skia/out/Release skia_lib libjpeg libSkKTX libetc1 flags + diff --git a/experimental/webtry/setup/setup_jail.sh b/experimental/webtry/setup/setup_jail.sh new file mode 100755 index 0000000000..6b50c3bf5d --- /dev/null +++ b/experimental/webtry/setup/setup_jail.sh @@ -0,0 +1,6 @@ +apt-get install -y g++ libfreetype6 libfreetype6-dev libpng12-0 libpng12-dev libglu1-mesa-dev mesa-common-dev freeglut3-dev libgif-dev libfontconfig libfontconfig-dev git python wget + +mkdir /skia_build +chmod 777 /skia_build + +mkdir /skia_build/bin diff --git a/experimental/webtry/setup/webtry_setup.sh b/experimental/webtry/setup/webtry_setup.sh index 3a8e063231..818135276c 100755 --- a/experimental/webtry/setup/webtry_setup.sh +++ b/experimental/webtry/setup/webtry_setup.sh @@ -3,32 +3,48 @@ # Script to setup a GCE instance to run the webtry server. # For full instructions see the README file. sudo apt-get install schroot debootstrap monit squid3 -sudo apt-get install g++ libfreetype6 libfreetype6-dev libpng12-0 libpng12-dev libglu1-mesa-dev mesa-common-dev freeglut3-dev libgif-dev libfontconfig libfontconfig-dev + +# although aufs is being replaced by overlayfs, it's not clear +# to me if overlayfs is completely supported by schroot yet. +sudo apt-get install aufs-tools echo "Adding the webtry user account" sudo adduser webtry -sudo cp continue_install /home/webtry/continue_install -sudo chmod 766 /home/webtry/continue_install -sudo chown webtry:webtry /home/webtry/continue_install -sudo su webtry -c /home/webtry/continue_install +sudo mkdir /home/webtry/cache +sudo mkdir /home/webtry/cache/src +sudo mkdir /home/webtry/inout +sudo chmod 777 /home/webtry/inout +sudo chmod 777 /home/webtry/cache +sudo chmod 777 /home/webtry/cache/src + +sudo cp ../sys/webtry_schroot /etc/schroot/chroot.d/webtry -sudo mkdir -p /srv/chroot/webtry -sudo cp /home/webtry/skia/experimental/webtry/sys/webtry_schroot /etc/schroot/chroot.d/webtry +CHROOT_JAIL=/srv/chroot/webtry_gyp +# Build the chroot environment +if [ ! -d ${CHROOT_JAIL} ]; then + sudo mkdir -p ${CHROOT_JAIL} -sudo mkdir /srv/chroot/webtry/etc -sudo mkdir /srv/chroot/webtry/bin -sudo cp /bin/sh /srv/chroot/webtry/bin/sh + sudo debootstrap --variant=minbase wheezy ${CHROOT_JAIL} + sudo cp setup_jail.sh ${CHROOT_JAIL}/bin + sudo chmod 755 ${CHROOT_JAIL}/bin/setup_jail.sh + sudo chroot ${CHROOT_JAIL} /bin/setup_jail.sh + sudo echo "none /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0" >> ${CHROOT_JAIL}/etc/fstab +fi -# Copy all the dependent libraries into the schroot. -sudo cp --parents `ldd /home/webtry/skia/out/Debug/webtry | cut -d " " -f 3` /srv/chroot/webtry -sudo cp --parents `ldd /bin/sh | cut -d " " -f 3` /srv/chroot/webtry +# the continue_install script will fetch the latest versions of +# skia and depot_tools. We split up the installation process into +# two pieces like this so that the continue_install script can +# be run independently of this one to fetch and build the latest skia. -sudo cp /home/webtry/skia/experimental/webtry/sys/webtry_init /etc/init.d/webtry -sudo cp /home/webtry/skia/experimental/webtry/sys/webtry_monit /etc/monit/conf.d/webtry -sudo cp /home/webtry/skia/experimental/webtry/sys/webtry_squid /etc/squid3/squid.conf +./continue_install.sh + +sudo cp ../sys/webtry_init /etc/init.d/webtry +sudo cp ../sys/webtry_monit /etc/monit/conf.d/webtry +sudo cp ../sys/webtry_squid /etc/squid3/squid.conf sudo chmod 744 /etc/init.d/webtry # Confirm that monit is happy. + sudo monit -t sudo monit reload diff --git a/experimental/webtry/sys/webtry_schroot b/experimental/webtry/sys/webtry_schroot index c2bdfd320d..bbc7f07afc 100644 --- a/experimental/webtry/sys/webtry_schroot +++ b/experimental/webtry/sys/webtry_schroot @@ -1,9 +1,10 @@ [webtry] description=Chroot jail for webtry runs. type=directory -directory=/srv/chroot/webtry +directory=/srv/chroot/webtry_gyp users=default,webtry root-groups=default personality=linux preserve-environment=false profile=minimal +union-type=aufs diff --git a/experimental/webtry/templates/template.gyp b/experimental/webtry/templates/template.gyp index d0486dced4..7ba40eaf78 100644 --- a/experimental/webtry/templates/template.gyp +++ b/experimental/webtry/templates/template.gyp @@ -11,14 +11,14 @@ 'target_name': '{{.Hash}}', 'type': 'executable', 'dependencies': [ - '../skia/gyp/skia_lib.gyp:skia_lib', - '../skia/gyp/flags.gyp:flags' + 'skia_lib.gyp:skia_lib', + 'flags.gyp:flags' ], 'include_dirs': [ - '../skia/include/config', - '../skia/include/core', - '../skia/tools/flags', - '../skia/src/core', + '../include/config', + '../include/core', + '../tools/flags', + '../src/core', ], 'conditions': [ ['skia_os == "mac"', { @@ -26,8 +26,8 @@ }] ], 'sources': [ - 'src/{{.Hash}}.cpp', - '../skia/experimental/webtry/main.cpp' + '../../cache/src/{{.Hash}}.cpp', + '../experimental/webtry/main.cpp' ], } ] diff --git a/experimental/webtry/webtry.go b/experimental/webtry/webtry.go index a4fe9e0ef5..ce144b93e0 100644 --- a/experimental/webtry/webtry.go +++ b/experimental/webtry/webtry.go @@ -36,8 +36,6 @@ import ( ) const ( - RUN_GYP = `../../experimental/webtry/gyp_for_webtry %s -Dskia_gpu=0` - RUN_NINJA = `ninja -C ../../../inout/Release %s` DEFAULT_SAMPLE = `void draw(SkCanvas* canvas) { SkPaint p; @@ -200,7 +198,7 @@ func init() { // // f672cead70404080a991ebfb86c38316a4589b23 2014-04-27 19:21:51 +0000 // - logOutput, err := doCmd(`git log --format=%H%x20%ai HEAD^..HEAD`, true) + logOutput, err := doCmd(`git log --format=%H%x20%ai HEAD^..HEAD`) if err != nil { panic(err) } @@ -394,9 +392,10 @@ type response struct { Hash string `json:"hash"` } -// doCmd executes the given command line string in either the out/Debug -// directory or the inout directory. Returns the stdout and stderr. -func doCmd(commandLine string, moveToDebug bool) (string, error) { +// doCmd executes the given command line string; the command being +// run is expected to not care what its current working directory is. +// Returns the stdout and stderr. +func doCmd(commandLine string) (string, error) { log.Printf("Command: %q\n", commandLine) programAndArgs := strings.SplitN(commandLine, " ", 2) program := programAndArgs[0] @@ -405,20 +404,6 @@ func doCmd(commandLine string, moveToDebug bool) (string, error) { args = strings.Split(programAndArgs[1], " ") } cmd := exec.Command(program, args...) - abs, err := filepath.Abs("../../out/Debug") - if err != nil { - return "", fmt.Errorf("Failed to find absolute path to Debug directory.") - } - if moveToDebug { - cmd.Dir = abs - } else if !*useChroot { // Don't set cmd.Dir when using chroot. - abs, err := filepath.Abs("../../../inout") - if err != nil { - return "", fmt.Errorf("Failed to find absolute path to inout directory.") - } - cmd.Dir = abs - } - log.Printf("Run in directory: %q\n", cmd.Dir) message, err := cmd.CombinedOutput() log.Printf("StdOut + StdErr: %s\n", string(message)) if err != nil { @@ -829,37 +814,17 @@ func mainHandler(w http.ResponseWriter, r *http.Request) { reportTryError(w, r, err, "Failed to write the gyp file.", hash) return } - message, err := doCmd(fmt.Sprintf(RUN_GYP, hash), true) - if err != nil { - message = cleanCompileOutput(message, hash) - reportTryError(w, r, err, message, hash) - return - } - linkMessage, err := doCmd(fmt.Sprintf(RUN_NINJA, hash), true) - if err != nil { - linkMessage = cleanCompileOutput(linkMessage, hash) - reportTryError(w, r, err, linkMessage, hash) - return - } - message += linkMessage - cmd := hash + " --out " + hash + ".png" - if request.Source > 0 { - cmd += fmt.Sprintf(" --source image-%d.png", request.Source) - } + cmd := "scripts/fiddle_wrapper " + hash if *useChroot { - cmd = "schroot -c webtry --directory=/inout -- /inout/Release/" + cmd - } else { - abs, err := filepath.Abs("../../../inout/Release") - if err != nil { - reportTryError(w, r, err, "Failed to find executable directory.", hash) - return - } - cmd = abs + "/" + cmd + cmd = "schroot -c webtry --directory=/ -- /skia_build/skia/experimental/webtry/" + cmd + } + if request.Source > 0 { + cmd += fmt.Sprintf(" image-%d.png", request.Source) } - execMessage, err := doCmd(cmd, false) + message, err := doCmd(cmd) if err != nil { - reportTryError(w, r, err, "Failed to run the code:\n"+execMessage, hash) + reportTryError(w, r, err, "Failed to run the code:\n"+message, hash) return } png, err := ioutil.ReadFile("../../../inout/" + hash + ".png") @@ -870,7 +835,6 @@ func mainHandler(w http.ResponseWriter, r *http.Request) { m := response{ Message: message, - StdOut: execMessage, Img: base64.StdEncoding.EncodeToString([]byte(png)), Hash: hash, } |