summaryrefslogtreecommitdiffstats
path: root/blimp
diff options
context:
space:
mode:
authormaniscalco <maniscalco@chromium.org>2015-10-05 12:30:22 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-05 19:32:05 +0000
commit91be48ce93f2cef2a78157a0af2fbbfb3d6ea687 (patch)
tree9a3af07ad06653dc7a8fae434f408a37cd4aa099 /blimp
parent49d1d6354eeec0eed524cde21ab49991aa6d534d (diff)
downloadchromium_src-91be48ce93f2cef2a78157a0af2fbbfb3d6ea687.zip
chromium_src-91be48ce93f2cef2a78157a0af2fbbfb3d6ea687.tar.gz
chromium_src-91be48ce93f2cef2a78157a0af2fbbfb3d6ea687.tar.bz2
Add script to bundle blimp engine into a Docker image
The blimp engine will run as a Docker container, and this CL adds the tools to be able to do that. There are three main parts: - The Dockerfile: Defines what should be part of the Docker image. - bundle-engine.py: Bundles the blimp engine and all its runtime dependencies into a tarball. This tarball also contains the Dockerfile itself. - Building a Docker image. This can easily be done by using the tarball that bundle-engine.py generates. This part is only documented and is not itself packaged into a script. To create the tarball, you execute: $ ./blimp/tools/bundle-engine.py \ --build-dir ./out-linux/Debug \ --dockerfile ./blimp/engine/Dockerfile \ --target blimp/engine:blimp_engine \ --output ./out-linux/Debug/blimp_engine_deps.tar You can then build the Docker image with: $ docker build -t blimp_engine - < ./out-linux/Debug/blimp_engine_deps.tar You can then run your Docker container with: $ docker run blimp_engine --with-my-flags BUG=538353 Review URL: https://codereview.chromium.org/1380123004 Cr-Commit-Position: refs/heads/master@{#352386}
Diffstat (limited to 'blimp')
-rw-r--r--blimp/BUILD.gn7
-rw-r--r--blimp/README.md2
-rw-r--r--blimp/docs/container.md69
-rw-r--r--blimp/docs/running.md4
-rw-r--r--blimp/engine/BUILD.gn17
-rw-r--r--blimp/engine/Dockerfile23
-rwxr-xr-xblimp/tools/bundle-engine.py72
7 files changed, 193 insertions, 1 deletions
diff --git a/blimp/BUILD.gn b/blimp/BUILD.gn
index d3da27a..13b8e29 100644
--- a/blimp/BUILD.gn
+++ b/blimp/BUILD.gn
@@ -3,6 +3,9 @@
# found in the LICENSE file.
group("blimp") {
+ # TODO(maniscalco): Remove the testonly attribute once blimp_engine no longer
+ # depends on content_shell (crbug.com/538353).
+ testonly = true
deps = [
"//blimp/client:blimp_client",
"//blimp/common:blimp_common",
@@ -11,6 +14,10 @@ group("blimp") {
if (is_android) {
deps += [ "//blimp/client:blimp_apk" ]
}
+
+ if (is_linux) {
+ deps += [ "//blimp/engine:blimp_engine" ]
+ }
}
group("blimp_tests") {
diff --git a/blimp/README.md b/blimp/README.md
index 3336fb9..e9f4cb2 100644
--- a/blimp/README.md
+++ b/blimp/README.md
@@ -12,4 +12,4 @@ For testing blimp, read more at [testing](docs/test.md).
## Running Blimp
-For running blimp, read more at [running](docs/running.md). \ No newline at end of file
+For running blimp, read more at [running](docs/running.md).
diff --git a/blimp/docs/container.md b/blimp/docs/container.md
new file mode 100644
index 0000000..0150e2a
--- /dev/null
+++ b/blimp/docs/container.md
@@ -0,0 +1,69 @@
+# Running the engine in a Docker container
+
+For local development and testing, you can run the engine in a Docker
+container.
+
+The steps are:
+
+1. Bundle the engine and its dependencies using
+[`bundle-engine.py`](../tools/bundle-engine.py).
+
+1. Build a Docker image.
+
+1. Create a Docker container.
+
+
+## About Docker
+
+To get a high-level overview of Docker, please read [Understand the
+architecture](https://docs.docker.com/introduction/understanding-docker/).
+Optional reading includes reference guides for
+[`docker run`](https://docs.docker.com/reference/run/) and
+[Dockerfile](https://docs.docker.com/reference/builder/).
+
+
+### Installation
+
+For Googlers running Goobuntu wanting to install Docker, see
+[go/installdocker](https://goto.google.com/installdocker). For other
+contributors using Ubuntu, see [official Docker
+installation instructions](https://docs.docker.com/installation/ubuntulinux/).
+
+
+## Bundle Engine
+
+Assuming the current directory is `src/` and you've already built the engine,
+you can bundle it into a tarfile by running:
+
+```bash
+./blimp/tools/bundle-engine.py \
+ --build-dir ./out-linux/Debug \
+ --dockerfile ./blimp/engine/Dockerfile \
+ --target blimp/engine:blimp_engine \
+ --output ./out-linux/Debug/blimp_engine_deps.tar
+```
+
+## Build Docker Image
+
+Using the tarfile you can create a Docker image:
+
+```bash
+docker build -t blimp_engine - < ./out-linux/Debug/blimp_engine_deps.tar
+```
+
+## Create Docker Container
+
+From the Docker image you can create a Docker container (i.e. run the engine):
+
+```bash
+docker run blimp_engine
+```
+
+You can also pass additional flags:
+
+```bash
+docker run blimp_engine --with-my-flags
+```
+
+See the [blimp engine `Dockerfile`](../engine/Dockerfile) to find out what flags
+are passed by default.
diff --git a/blimp/docs/running.md b/blimp/docs/running.md
index f42b51a..494beea 100644
--- a/blimp/docs/running.md
+++ b/blimp/docs/running.md
@@ -30,3 +30,7 @@ adb_run_blimp_client
### Linux Client
TBD
+
+## Running the engine
+
+For running the engine in a container, see [container](docs/container.md).
diff --git a/blimp/engine/BUILD.gn b/blimp/engine/BUILD.gn
new file mode 100644
index 0000000..849b3ce
--- /dev/null
+++ b/blimp/engine/BUILD.gn
@@ -0,0 +1,17 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+if (is_linux) {
+ # A stand-in for the Blimp Engine so we can get the Docker packaging working.
+ #
+ # TODO(maniscalco): Update to use the real engine once it's ready and remove
+ # the testonly attribute (crbug.com/538353).
+ group("blimp_engine") {
+ testonly = true
+ data_deps = [
+ "//content/shell:content_shell",
+ "//content/shell:pak",
+ ]
+ }
+}
diff --git a/blimp/engine/Dockerfile b/blimp/engine/Dockerfile
new file mode 100644
index 0000000..766193c
--- /dev/null
+++ b/blimp/engine/Dockerfile
@@ -0,0 +1,23 @@
+FROM ubuntu:trusty
+
+RUN apt-get update && \
+ apt-get install -yq libasound2 libatk1.0-0 libavahi-client3 libavahi-common3 \
+ libcairo2 libcups2 libdatrie1 libdbus-glib-1-2 libffi6 libfontconfig1 \
+ libgconf-2-4 libglib2.0-0 libgnutls26 libgraphite2-3 libgssapi-krb5-2 \
+ libk5crypto3 libkrb5-3 libkrb5support0 libnspr4 libnss3 libotf0 libp11-kit0 \
+ libpango1.0-0 libpixman-1-0 libstdc++6 libtasn1-6 libthai0 libx11-6 libxau6 \
+ libxcb1 libxcb-render0 libxcb-shm0 libxcomposite1 libxcursor1 libxdamage1 \
+ libxdmcp6 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
+ xvfb
+
+RUN mkdir /engine
+
+RUN useradd -ms /bin/bash blimp_user
+
+ADD * /engine/
+RUN chown -R blimp_user /engine
+
+USER blimp_user
+WORKDIR "/engine"
+ENTRYPOINT [ "/usr/bin/xvfb-run", "--server-args=-screen 0 1600x1200x24", \
+ "./content_shell", "--no-sandbox" ]
diff --git a/blimp/tools/bundle-engine.py b/blimp/tools/bundle-engine.py
new file mode 100755
index 0000000..ee2c6a0
--- /dev/null
+++ b/blimp/tools/bundle-engine.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+'''Bundles the Blimp Engine and its runtime dependencies into a tarball.
+
+ The created bundle can be passed as input to docker build. E.g.
+ docker build - < ../../out-linux/Debug/blimp_engine_deps.tar
+'''
+
+
+import argparse
+import errno
+import os
+import subprocess
+import tarfile
+
+def GetDependencies(build_dir, target):
+ """Return the list of target's dependencies.
+ :raises CalledProcessError: if the dependency list could not be determined.
+ """
+ # Get the list of runtime dependencies from the already built target.
+ deps = subprocess.check_output(['gn', 'desc', build_dir, target,
+ 'runtime_deps']).split('\n')
+ # Remove any empty strings.
+ deps = filter(bool, deps)
+ # Exclude any deps aren't under the build_dir. They are not needed.
+ return [dep for dep in deps if not dep.startswith('..')]
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--build-dir',
+ help=('build output directory (e.g. out/Debug)'),
+ required=True,
+ metavar='DIR')
+ parser.add_argument('--dockerfile',
+ help=('Dockerfile to add to the bundle'),
+ required=True,
+ metavar='FILE')
+ parser.add_argument('--target',
+ help=('build target of engine'),
+ required=True)
+ parser.add_argument('--output',
+ help=('name and path of bundle to create'),
+ required=True,
+ metavar='FILE')
+ args = parser.parse_args()
+
+ # Get the list of runtime dependencies from the already built target.
+ try:
+ deps = GetDependencies(args.build_dir, args.target)
+ except subprocess.CalledProcessError as e:
+ print "Error: " + ' '.join(e.cmd)
+ print e.output
+ exit(1)
+
+ # Add the deps to the tarball along with the Dockerfile.
+ with tarfile.open(args.output, 'w') as tarball:
+ tarball.add(args.dockerfile, arcname='Dockerfile')
+ os.chdir(args.build_dir)
+ for dep in deps:
+ try:
+ tarball.add(dep)
+ except OSError as e:
+ if e.errno == errno.ENOENT:
+ print dep + " not found (did you build " + args.target + "?)"
+ exit(1)
+ print 'Created ' + args.output
+
+if __name__ == "__main__":
+ main()