docker: cache env_setup bootstrap

- add empty commit (required by env_setup)
- copy env_setup from the build context first
- run/cache env_setup bootstrap
- copy remaining pigweed sources from the build context

Bug: 216
Change-Id: If1ad1cc7da3c0f1bccfe1cacbcf93e876206fc47
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/14241
Commit-Queue: Johan Euphrosine <proppy@google.com>
Reviewed-by: Rob Mohr <mohrr@google.com>
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 4493851..c968582 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -26,11 +26,17 @@
 ENV PW_ENVIRONMENT_ROOT /pigweed-cache/environment
 ENV PW_CIPD_PACKAGE_FILES "$PW_ROOT/pw_env_setup/py/pw_env_setup/cipd_setup/*.json"
 
-COPY . $PW_ROOT
+WORKDIR $PW_ROOT
+# env_setup requires .git for determining top-level directory with git rev-parse
+ENV EMAIL "docker-build <>"
+RUN git init
+RUN git commit --allow-empty --allow-empty-message -m ''
+COPY pw_env_setup/ $PW_ROOT/pw_env_setup/
 # --shell-file is required, but we're going to ignore it.
 RUN $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
+COPY . $PW_ROOT
 
 CMD /bin/bash