docker: Add Dockerfile for Pigweed

At container build time this will clone Pigweed and initialize CIPD.
It also sets CIPD_CACHE_DIR and PW_ENVIRONMENT_ROOT. When running within
the container projects just need to bootstrap as normal and Pigweed will
use the CIPD cache and installed files. If there are updates it will
make them over top of the image and still have a substantial speed
improvement over starting from scratch.

Change-Id: I2889d8844acc7e4b308e93ca20a366ad0a6bfec9
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/14000
Commit-Queue: Rob Mohr <mohrr@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
diff --git a/docker/BUILD.gn b/docker/BUILD.gn
new file mode 100644
index 0000000..601472c
--- /dev/null
+++ b/docker/BUILD.gn
@@ -0,0 +1,21 @@
+# Copyright 2020 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pw_docgen/docs.gni")
+pw_doc_group("docs") {
+  sources = [ "docs.rst" ]
+}
diff --git a/docker/Dockerfile b/docker/Dockerfile
new file mode 100644
index 0000000..cfa0d17
--- /dev/null
+++ b/docker/Dockerfile
@@ -0,0 +1,36 @@
+# Copyright 2020 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+FROM ubuntu:19.10
+RUN apt-get update &&\
+    apt-get install -y \
+        python \
+        git
+
+ENV CIPD_CACHE_DIR /pigweed-cache/cipd-cache-dir
+# This is only for seeding the environment, not meant to be used. Running
+# bootstrap inside another checkout will reset PW_ROOT but leave
+# PW_ENVIRONMENT_ROOT alone.
+ENV PW_ROOT /pigweed-cache/pigweed
+ENV PW_ENVIRONMENT_ROOT /pigweed-cache/environment
+ENV PW_CIPD_PACKAGE_FILES "$PW_ROOT/pw_env_setup/py/pw_env_setup/cipd_setup/*.json"
+
+# --shell-file is required, but we're going to ignore it.
+RUN git clone https://pigweed.googlesource.com/pigweed/pigweed $PW_ROOT && \
+    $PW_ROOT/pw_env_setup/py/pw_env_setup/env_setup.py \
+    --shell-file $PW_ROOT/init.sh \
+    --pw-root $PW_ROOT \
+    --install-dir $PW_ENVIRONMENT_ROOT
+
+CMD /bin/bash
diff --git a/docker/docs.rst b/docker/docs.rst
new file mode 100644
index 0000000..3c25edc
--- /dev/null
+++ b/docker/docs.rst
@@ -0,0 +1,12 @@
+.. _chapter-docker:
+
+------
+docker
+------
+The Dockerfile in this directory simplifies creating a container with cached
+CIPD packages for use in continuous integration.
+
+To create a container run ``docker build --tag <tag> $PW_ROOT/docker``. To run
+this image run ``docker run -it <tag>``.
+
+Details of Docker use are unfinished.
diff --git a/docs/BUILD.gn b/docs/BUILD.gn
index 9bbfa88..0560e15 100644
--- a/docs/BUILD.gn
+++ b/docs/BUILD.gn
@@ -58,6 +58,7 @@
   deps = [
     ":core_docs",
     ":target_docs",
+    "$dir_docker:docs",
     "$dir_pw_allocator:docs",
     "$dir_pw_assert:docs",
     "$dir_pw_assert_basic:docs",
diff --git a/modules.gni b/modules.gni
index eb659b1..41e0731 100644
--- a/modules.gni
+++ b/modules.gni
@@ -16,6 +16,7 @@
   # This file defines a directory variable for each of Pigweed's modules. This
   # allows modules to be moved or swapped out without breaking existing builds.
   # All module variables are prefixed with dir_.
+  dir_docker = get_path_info("docker", "abspath")
   dir_pw_allocator = get_path_info("pw_allocator", "abspath")
   dir_pw_assert = get_path_info("pw_assert", "abspath")
   dir_pw_assert_basic = get_path_info("pw_assert_basic", "abspath")