From df9dd388310e385f0ad0869fd553dc540ce078e7 Mon Sep 17 00:00:00 2001 From: bryk Date: Wed, 2 Mar 2016 12:21:04 +0100 Subject: [PATCH] Make docker build pipeline always use clean env and actaully work Previously it didn't always work because my local env was overriding what was previously baked into image. Now the image bases only on source code and is brand new each time. It is also a lot faster when dockerignore excludes more files. --- .dockerignore | 24 ++++++++++++++++++++++++ Dockerfile => build/Dockerfile | 21 ++++++++------------- build/run-gulp-in-docker.sh | 6 ++++-- 3 files changed, 36 insertions(+), 15 deletions(-) rename Dockerfile => build/Dockerfile (76%) diff --git a/.dockerignore b/.dockerignore index 6b8710a711f3..bfcf9392df3c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,25 @@ +# Copyright 2015 Google Inc. All Rights Reserved. +# +# 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 +# +# http://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. + +# Do not include the Docker build pipeline itself. +build/Dockerfile +build/run-gulp-in-docker.sh + +# Ignore all development artifacts so that the build is always clean. .git +.tmp/ +.tools/ +bower_components/ +dist/ +node_modules/ diff --git a/Dockerfile b/build/Dockerfile similarity index 76% rename from Dockerfile rename to build/Dockerfile index 4c725f53b286..01bdfeca8c51 100644 --- a/Dockerfile +++ b/build/Dockerfile @@ -14,17 +14,17 @@ # This is a Dockerfile for running and building Kubernetes dashboard # It installs all deps in the container and adds the dashboard source -# This way it abstracts all required build tools away and lets the user run gulp tasks on the code with only docker installed +# This way it abstracts all required build tools away and lets the user +# run gulp tasks on the code with only docker installed # golang is based on debian:jessie -FROM golang:1.5.3 +FROM golang -# Install python, java and nodejs. go is already installed -# A small tweak, apt-get update is already run by the nodejs setup script, so there's no need to run it again +# Install java and nodejs. go is already installed +# A small tweak, apt-get update is already run by the nodejs setup script, +# so there's no need to run it again RUN curl -sL https://deb.nodesource.com/setup_5.x | bash - \ && apt-get install -y --no-install-recommends \ - file \ - python \ openjdk-7-jre \ nodejs \ && rm -rf /var/lib/apt/lists/* \ @@ -37,13 +37,8 @@ RUN curl -sSL https://get.docker.com/builds/Linux/x86_64/docker-1.9.1 > /usr/bin # Current directory is always /dashboard WORKDIR /dashboard -# Copy over package.json bower.json and postinstall.sh. -# Why? Because of docker caching, npm install will only run again if one of these have changed -COPY package.json bower.json ./ -COPY build/postinstall.sh build/ +# Copy entire source tree. +COPY ./ ./ # Install all npm deps, bower deps and godep. This will take a while. RUN npm install --unsafe-perm - -# Copy over the rest of the source -COPY ./ ./ diff --git a/build/run-gulp-in-docker.sh b/build/run-gulp-in-docker.sh index e5cd9cf1cd38..55f18fe32719 100755 --- a/build/run-gulp-in-docker.sh +++ b/build/run-gulp-in-docker.sh @@ -19,9 +19,11 @@ DOCKER_RUN_OPTS=${DOCKER_RUN_OPTS:-} DASHBOARD_IMAGE_NAME="kubernetes-dashboard-build-image" DEFAULT_COMMAND=${DEFAULT_COMMAND:-"node_modules/.bin/gulp"} +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -# Always test if the image is up-to-date. If nothing has changed since last build, it'll just use the already-built image -docker build -t ${DASHBOARD_IMAGE_NAME} . +# Always test if the image is up-to-date. If nothing has changed since last build, +# it'll just use the already-built image +docker build -t ${DASHBOARD_IMAGE_NAME} -f ${DIR}/Dockerfile ${DIR}/../ # Run gulp in the container in interactive mode and expose necessary ports automatically docker run \