Skip to content

Commit

Permalink
AVRO-2609 Send Minimal Build Context to Docker (#694)
Browse files Browse the repository at this point in the history
* AVRO-2609: Avoid Unused Docker Build Context
* AVRO-2609: Move COPY to End of Dockerfile
  • Loading branch information
kojiromike committed Oct 31, 2019
1 parent 7d87cde commit cfc8041
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
42 changes: 18 additions & 24 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -e # exit on error
set -xe
cd "${0%/*}"

cd `dirname "$0"` # connect to root

VERSION=`cat share/VERSION.txt`
VERSION=$(<share/VERSION.txt)
DOCKER_XTRA_ARGS=""

function usage {
usage() {
echo "Usage: $0 {lint|test|dist|sign|clean|veryclean|docker [--args \"docker-args\"]|rat|githooks|docker-test}"
exit 1
}

if [ $# -eq 0 ]
then
usage
fi

set -x # echo commands
(( $# == 0 )) && usage

while (( "$#" ))
do
Expand Down Expand Up @@ -260,9 +254,7 @@ do
DOCKER_XTRA_ARGS=$2
shift 2
fi
docker build -t avro-build-ci -f share/docker/Dockerfile .
docker build -t avro-build -f share/docker/DockerfileLocal .
if [ "$(uname -s)" == "Linux" ]; then
if [[ "$(uname -s)" = Linux ]]; then
USER_NAME=${SUDO_USER:=$USER}
USER_ID=$(id -u $USER_NAME)
GROUP_ID=$(id -g $USER_NAME)
Expand All @@ -271,12 +263,15 @@ do
USER_ID=1000
GROUP_ID=50
fi
docker build -t avro-build-${USER_NAME} - <<UserSpecificDocker
FROM avro-build
RUN groupadd -g ${GROUP_ID} ${USER_NAME} || true
RUN useradd -g ${GROUP_ID} -u ${USER_ID} -k /root -m ${USER_NAME} || true
ENV HOME /home/${USER_NAME}
UserSpecificDocker
{
cat share/docker/Dockerfile
grep -vF 'FROM avro-build-ci' share/docker/DockerfileLocal
echo "ENV HOME /home/$USER_NAME"
echo "RUN getent group $GROUP_ID || groupadd -g $GROUP_ID $USER_NAME"
echo "RUN getent passwd $USER_ID || useradd -g $GROUP_ID -u $USER_ID -k /root -m $USER_NAME"
} > Dockerfile
tar -cf- lang/ruby/Gemfile Dockerfile | docker build -t "avro-build-$USER_NAME" -
rm Dockerfile
# By mapping the .m2 directory you can do an mvn install from
# within the container and use the result on your normal
# system. And this also is a significant speedup in subsequent
Expand Down Expand Up @@ -308,15 +303,14 @@ UserSpecificDocker
;;

docker-test)
docker build -t avro-test -f share/docker/Dockerfile .
tar -cf- share/docker/Dockerfile \
lang/ruby/Gemfile |
docker build -t avro-test -f share/docker/Dockerfile -
docker run --rm -v ${PWD}:/avro/ avro-test
;;

*)
usage
;;
esac

done

exit 0
8 changes: 4 additions & 4 deletions share/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ RUN python2 -m pip install --upgrade pip setuptools \
RUN python3 -m pip install --upgrade pip setuptools \
&& python3 -m pip install zstandard

# Install Ruby modules
COPY lang/ruby/Gemfile /tmp
RUN bundle install --gemfile=/tmp/Gemfile

# Install .NET SDK
RUN curl -sSLO https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb \
&& dpkg -i packages-microsoft-prod.deb \
Expand All @@ -139,3 +135,7 @@ RUN curl -sSLO https://packages.microsoft.com/config/ubuntu/16.04/packages-micro
&& apt-get -qqy install --no-install-recommends dotnet-sdk-2.2 \
&& apt-get -qqy clean \
&& rm -rf /var/lib/apt/lists

# Install Ruby modules
COPY lang/ruby/Gemfile /tmp
RUN bundle install --gemfile=/tmp/Gemfile

0 comments on commit cfc8041

Please sign in to comment.