From 8acb376e3768b67701bf8738789683c59b41ba0f Mon Sep 17 00:00:00 2001 From: Jeff Klukas Date: Fri, 17 Aug 2018 10:44:52 -0400 Subject: [PATCH] Copy source into image rather than mount in container @acmiyaguchi reported that with the source mounted into the container, cache files were written to the local file system that then couldn't be removed without sudo on an Ubuntu host. This change should make sure all cache files are written inside the container so they don't hit the local filesystem. --- .dockerignore | 4 ++-- Dockerfile | 6 ++++++ bin/test | 7 ++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.dockerignore b/.dockerignore index eb8e7ba..56bac12 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,5 @@ # Files/directories matching the patterns here will not be included # in the Docker context when you run `docker build`. -# The tox caches can be large; we ignore them to speed up builds. -.*tox/ +.* +*.egg* diff --git a/Dockerfile b/Dockerfile index cdb1570..df252a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,3 +7,9 @@ FROM python:$PYTHON_VERSION RUN apt-get update && apt-get install -y libsnappy-dev openjdk-8-jre-headless RUN pip install tox + +WORKDIR /python_moztelemetry + +# Copy the current directory as is to the workdir; +# Relies on the .dockerignore file to prune out large files we don't want to include. +COPY . . diff --git a/bin/test b/bin/test index 3031315..920c874 100755 --- a/bin/test +++ b/bin/test @@ -8,7 +8,7 @@ cd $(git rev-parse --show-toplevel) # Set default variables if not already present in the environment. : ${PYTHON_VERSION:=3.6} -: ${WORKDIR:=.dockertox} # Prevents the circleci cli from picking up the env +: ${TOXDIR:=.dockertox} # Prevents the circleci cli from picking up the env : ${TOXENV:="py${PYTHON_VERSION/./}"} # Set some derived variables. @@ -22,7 +22,8 @@ docker build -t moztelemetry:"$TOXENV" --build-arg PYTHON_VERSION="$PYTHON_VERSI # We mount the current directory to the container and run tox inside it. docker run -it --rm \ - --volume "$(pwd)":/python_moztelemetry \ + --volume "$(pwd)/$TOXDIR":/python_moztelemetry/"$TOXDIR" \ + --volume "$(pwd)"/.git:/python_moztelemetry/.git \ --workdir /python_moztelemetry \ moztelemetry:"$TOXENV" \ - tox --workdir $WORKDIR -e "$TOXENV" -- $@ + tox --workdir "$TOXDIR" -e "$TOXENV" -- $@