Skip to content

Speed up dockerized builds#30787

Merged
k8s-github-robot merged 8 commits intokubernetes:masterfrom
jbeda:rsync
Oct 6, 2016
Merged

Speed up dockerized builds#30787
k8s-github-robot merged 8 commits intokubernetes:masterfrom
jbeda:rsync

Conversation

@jbeda
Copy link
Contributor

@jbeda jbeda commented Aug 17, 2016

This PR speeds up dockerized builds. First, we make sure that we are as incremental as possible. The bigger change is that now we use rsync to move sources into the container and get data back out.

To do yet:

  • Add a random password to rsync. This is 128bit MD4, but it is better than nothing.
  • Lock down rsync to only come from the host.
  • Deal with remote docker engines -- this should be necessary for docker-machine on the mac.
  • Allow users to specify the port for the rsync daemon. Perhaps randomize this or let docker pick an ephemeral port and detect the port?
  • Copy back generated files so that users can check them in. This is done for zz_generated.* files generated by make generated_files
    • This should include generated proto files so that we can remove the hack-o-rama that is hack/hack/update-*-dockerized.sh
  • Start "versioning" the build container and the data container so that the CI system doesn't have to be manually kicked.
  • Get some benchmarks to qualify how much faster.

This replaces #28518 and is related to #30600.

cc @thockin @spxtr @david-mcmahon @MHBauer

Benchmarks by running make clean ; sync ; time bash -xc 'time build/make-build-image.sh ; time sync ; time build/run.sh make ; time sync; time build/run.sh make' on a GCE n1-standard-8 with PD-SSD.

setup build image sync first build sync second build total
baseline 0m11.420s 0m0.812s 7m2.353s 0m42.380s 7m8.381s 15m5.348s
this pr 0m10.977s 0m15.168s 7m31.096s 1m55.692s 0m16.514s 10m9.449s

This change is Reviewable

@k8s-github-robot k8s-github-robot added kind/design Categorizes issue or PR as related to design. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-label-needed labels Aug 17, 2016
@spxtr
Copy link
Contributor

spxtr commented Aug 19, 2016

Roughly how much faster is it?

@jbeda
Copy link
Contributor Author

jbeda commented Aug 19, 2016

I'll pull together some benchmarks before I remove the WIP label.

build/common.sh Outdated
chown -R $(id -u).$(id -g) "${REMOTE_OUTPUT_ROOT}"
chown -R $(id -u).$(id -g)
"${REMOTE_ROOT}"
/usr/local/go/pkg/linux_386_cgo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just do all of /usr/local/go/pkg/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That ends up whiting out the compiler:

$ make WHAT='cmd/kubectl'
+++ [0820 16:28:15] Generating bindata:
    /go/src/k8s.io/kubernetes/test/e2e/framework/gobindata_util.go
../../../hack/../test/e2e/generated/bindata.go.tmp ../../../hack/../test/e2e/generated/bindata.go differ: char 1523, line 29
+++ [0820 16:28:16] Building the toolchain targets:
    k8s.io/kubernetes/hack/cmd/teststale
go tool: no such tool "compile"
Makefile.generated_files:279: recipe for target '_output/bin/deepcopy-gen' failed
make[1]: *** [_output/bin/deepcopy-gen] Error 1
Makefile:281: recipe for target 'generated_files' failed
make: *** [generated_files] Error 2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to just chown? Or is that from volume mounting on pkg, which I could understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler itself is under /usr/local/go/pkg. If we make that a volume it gets whited out. Not sure what else to do there.

We could do something where we move it aside when building the image and then copy it back as part of the chown step, but that seems complicated too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant just to chmod/chown the whole thing, not to volume mount the whole
thing.

On Mon, Aug 22, 2016 at 2:24 PM, Joe Beda notifications@github.com wrote:

In build/common.sh
#30787 (comment)
:

   --volume "${REMOTE_OUTPUT_GOPATH}" # make a non-root owned mountpoint
   "${KUBE_BUILD_IMAGE}"
  •  chown -R $(id -u).$(id -g) "${REMOTE_OUTPUT_ROOT}"
    
  •  chown -R $(id -u).$(id -g)
    
  •    "${REMOTE_ROOT}"
    
  •    /usr/local/go/pkg/linux_386_cgo
    

The compiler itself is under /usr/local/go/pkg. If we make that a volume
it gets whited out. Not sure what else to do there.

We could do something where we move it aside when building the image and
then copy it back as part of the chown step, but that seems complicated too.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/kubernetes/kubernetes/pull/30787/files/c0ba418d1f5f07f74ae8e9aa392e7ddbcfa0a144#r75761703,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFVgVEMQP4zlhDmbqAsqoZD3z7Rl7Y3Yks5qihN5gaJpZM4Jmt7e
.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems to work. Latest versions have that.

@k8s-github-robot k8s-github-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 20, 2016
if !pkgNeedsGeneration {
glog.V(5).Infof(" no viable conversions, not generating for this package")
continue
glog.Errorf("Package %v has 'k8s:conversion-gen' tags but no viable conversions", i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems unrelated...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that this wasn't outputting a file was confusing your generated files make system. I wasn't able to get to a "no op" make without some sort of fix here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?? How do I repro that at head?

On Mon, Aug 22, 2016 at 6:18 AM, Joe Beda notifications@github.com wrote:

In cmd/libs/go2idl/conversion-gen/generators/conversion.go
#30787 (comment)
:

@@ -280,8 +280,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
}
}
if !pkgNeedsGeneration {

  •       glog.V(5).Infof("  no viable conversions, not generating for this package")
    
  •       continue
    
  •       glog.Errorf("Package %v has 'k8s:conversion-gen' tags but no viable conversions", i)
    

The fact that this wasn't outputting a file was confusing your generated
files make system. I wasn't able to get to a "no op" make without some sort
of fix here.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/kubernetes/kubernetes/pull/30787/files/9269652b4fc9760754e0b4e47cc2cb995f9d3e24#r75674739,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFVgVM2XusCz26zLyZDn5qPbaCQ91KPbks5qiaGdgaJpZM4Jmt7e
.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's pretty fast but still extra work.

repo

[jbeda@k8s-build:~/src/kubernetes] (master)$ make clean
+++ [0822 18:08:36] Verifying Prerequisites....
!!! [0822 18:08:36] Build image not built.  Cannot clean via docker build image.
+++ [0822 18:08:36] Removing data container kube-build-data-27932f596f
+++ [0822 18:08:36] Removing _output directory
+++ [0822 18:08:36] Deleting docker image kube-build:build-27932f596f
+++ [0822 18:08:36] Cleaning all other untagged docker images
:) Mon Aug 22 18:08:36
[jbeda@k8s-build:~/src/kubernetes] (master)$ make generated_files
+++ [0822 18:08:49] Generating bindata:
    /home/jbeda/src/kubernetes/test/e2e/framework/gobindata_util.go
+++ [0822 18:08:49] Building the toolchain targets:
    k8s.io/kubernetes/hack/cmd/teststale
+++ [0822 18:08:50] Building go targets for linux/amd64:
    cmd/libs/go2idl/deepcopy-gen
+++ [0822 18:08:55] Generating bindata:
    /home/jbeda/src/kubernetes/test/e2e/framework/gobindata_util.go
+++ [0822 18:08:56] Building the toolchain targets:
    k8s.io/kubernetes/hack/cmd/teststale
+++ [0822 18:08:56] Building go targets for linux/amd64:
    cmd/libs/go2idl/conversion-gen
E0822 18:09:00.238473    8625 conversion.go:589] Warning: could not generate autoConvert functions for k8s.io/kubernetes/pkg/apis/apps/v1alpha1.PetSetSpec <-> k8s.io/kubernetes/pkg/apis/apps.PetSetSpec
E0822 18:09:00.258650    8625 conversion.go:589] Warning: could not generate autoConvert functions for k8s.io/kubernetes/pkg/apis/extensions/v1beta1.HorizontalPodAutoscalerSpec <-> k8s.io/kubernetes/pkg/apis/autoscaling.HorizontalPodAutoscalerSpec
E0822 18:09:00.266875    8625 conversion.go:589] Warning: could not generate autoConvert functions for k8s.io/kubernetes/pkg/apis/extensions/v1beta1.JobSpec <-> k8s.io/kubernetes/pkg/apis/batch.JobSpec
E0822 18:09:00.282497    8625 conversion.go:589] Warning: could not generate autoConvert functions for k8s.io/kubernetes/pkg/apis/extensions/v1beta1.RollingUpdateDeployment <-> k8s.io/kubernetes/pkg/apis/extensions.RollingUpdateDeployment
E0822 18:09:00.285592    8625 conversion.go:589] Warning: could not generate autoConvert functions for k8s.io/kubernetes/pkg/apis/extensions/v1beta1.ScaleStatus <-> k8s.io/kubernetes/pkg/apis/extensions.ScaleStatus
:) Mon Aug 22 18:09:00
[jbeda@k8s-build:~/src/kubernetes] (master)$ make generated_files --debug=b
GNU Make 4.0
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating goal targets....
 File 'generated_files' does not exist.
Must remake target 'generated_files'.
GNU Make 4.0
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating goal targets....
 File 'generated_files' does not exist.
   File 'gen_deepcopy' does not exist.
  Must remake target 'gen_deepcopy'.
  Successfully remade target file 'gen_deepcopy'.
   File 'gen_conversion' does not exist.
     File 'federation/apis/core/v1/zz_generated.conversion.go' does not exist.
    Must remake target 'federation/apis/core/v1/zz_generated.conversion.go'.
    Successfully remade target file 'federation/apis/core/v1/zz_generated.conversion.go'.
  Must remake target 'gen_conversion'.
  Successfully remade target file 'gen_conversion'.
Must remake target 'generated_files'.
Successfully remade target file 'generated_files'.
Successfully remade target file 'generated_files'.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. Good catch.

On Mon, Aug 22, 2016 at 11:13 AM, Joe Beda notifications@github.com wrote:

In cmd/libs/go2idl/conversion-gen/generators/conversion.go
#30787 (comment)
:

@@ -280,8 +280,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
}
}
if !pkgNeedsGeneration {

  •       glog.V(5).Infof("  no viable conversions, not generating for this package")
    
  •       continue
    
  •       glog.Errorf("Package %v has 'k8s:conversion-gen' tags but no viable conversions", i)
    

It's pretty fast but still extra work.

repo

jbeda@k8s-build:~/src/kubernetes$ make clean
+++ [0822 18:08:36] Verifying Prerequisites....
!!! [0822 18:08:36] Build image not built. Cannot clean via docker build image.
+++ [0822 18:08:36] Removing data container kube-build-data-27932f596f
+++ [0822 18:08:36] Removing _output directory
+++ [0822 18:08:36] Deleting docker image kube-build:build-27932f596f
+++ [0822 18:08:36] Cleaning all other untagged docker images
:) Mon Aug 22 18:08:36
jbeda@k8s-build:~/src/kubernetes$ make generated_files
+++ [0822 18:08:49] Generating bindata:
/home/jbeda/src/kubernetes/test/e2e/framework/gobindata_util.go
+++ [0822 18:08:49] Building the toolchain targets:
k8s.io/kubernetes/hack/cmd/teststale
+++ [0822 18:08:50] Building go targets for linux/amd64:
cmd/libs/go2idl/deepcopy-gen
+++ [0822 18:08:55] Generating bindata:
/home/jbeda/src/kubernetes/test/e2e/framework/gobindata_util.go
+++ [0822 18:08:56] Building the toolchain targets:
k8s.io/kubernetes/hack/cmd/teststale
+++ [0822 18:08:56] Building go targets for linux/amd64:
cmd/libs/go2idl/conversion-gen
E0822 18:09:00.238473 8625 conversion.go:589] Warning: could not generate autoConvert functions for k8s.io/kubernetes/pkg/apis/apps/v1alpha1.PetSetSpec <-> k8s.io/kubernetes/pkg/apis/apps.PetSetSpec
E0822 http://k8s.io/kubernetes/pkg/apis/apps.PetSetSpecE0822 18:09:00.258650 8625 conversion.go:589] Warning: could not generate autoConvert functions for k8s.io/kubernetes/pkg/apis/extensions/v1beta1.HorizontalPodAutoscalerSpec <-> k8s.io/kubernetes/pkg/apis/autoscaling.HorizontalPodAutoscalerSpec
E0822 http://k8s.io/kubernetes/pkg/apis/autoscaling.HorizontalPodAutoscalerSpecE0822 18:09:00.266875 8625 conversion.go:589] Warning: could not generate autoConvert functions for k8s.io/kubernetes/pkg/apis/extensions/v1beta1.JobSpec <-> k8s.io/kubernetes/pkg/apis/batch.JobSpec
E0822 http://k8s.io/kubernetes/pkg/apis/batch.JobSpecE0822 18:09:00.282497 8625 conversion.go:589] Warning: could not generate autoConvert functions for k8s.io/kubernetes/pkg/apis/extensions/v1beta1.RollingUpdateDeployment <-> k8s.io/kubernetes/pkg/apis/extensions.RollingUpdateDeployment
E0822 http://k8s.io/kubernetes/pkg/apis/extensions.RollingUpdateDeploymentE0822 18:09:00.285592 8625 conversion.go:589] Warning: could not generate autoConvert functions for k8s.io/kubernetes/pkg/apis/extensions/v1beta1.ScaleStatus <-> k8s.io/kubernetes/pkg/apis/extensions.ScaleStatus
:) Mon Aug 22 18:09:00
jbeda@k8s-build:~/src/kubernetes$ make generated_files --debug=b
GNU Make 4.0
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating goal targets....
File 'generated_files' does not exist.
Must remake target 'generated_files'.
GNU Make 4.0
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating goal targets....
File 'generated_files' does not exist.
File 'gen_deepcopy' does not exist.
Must remake target 'gen_deepcopy'.
Successfully remade target file 'gen_deepcopy'.
File 'gen_conversion' does not exist.
File 'federation/apis/core/v1/zz_generated.conversion.go' does not exist.
Must remake target 'federation/apis/core/v1/zz_generated.conversion.go'.
Successfully remade target file 'federation/apis/core/v1/zz_generated.conversion.go'.
Must remake target 'gen_conversion'.
Successfully remade target file 'gen_conversion'.
Must remake target 'generated_files'.
Successfully remade target file 'generated_files'.
Successfully remade target file 'generated_files'.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/kubernetes/kubernetes/pull/30787/files/9269652b4fc9760754e0b4e47cc2cb995f9d3e24#r75728857,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFVgVNEJWxeUo7Q5hXJa-bOF4I1RVespks5qiebagaJpZM4Jmt7e
.

@jbeda
Copy link
Contributor Author

jbeda commented Aug 23, 2016

To anyone watching from home, I'm fighting with Jenkins. I was using a Docker 1.12 feature and had to discover that Jenkins was using 1.9.1 and adjust. Now the verification test is failing (can't talk to the rsync container) and I'm trying to figure out why. The only way I have to test is to push a new change with debug commands. It is essentially printf debugging with a 15m+ delay.

I'll clean up the patch set after things look to be working reliably.

build/README.md Outdated
3. **Optional** [Google Cloud SDK](https://developers.google.com/cloud/sdk/)
1. Docker, using one of the following configurations:
1. **Mac OS X** You can either use Docker for Mac or docker-machine. See installation instructions [here](https://docs.docker.com/installation/mac/).
**Note**: You will want to set the Docker VM to have at least 3GB of initial memory or building will likely fail. (See: [#11852]( http://issue.k8s.io/11852)). https://github.com/kubernetes/kubernetes/issues/14773))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many closing parens on this line.

jbeda added 5 commits October 3, 2016 19:42
make-generated-{protobuf,runtime}.sh was doing some really nasty stuff with how
the build container was managed in order to copy results out.  Since we have
more flexibility to grab results out of the build container, we can now avoid
all of this.  Ideally we wouldn't have `hack` calling `build` at all, but we
aren't there yet.
We weren't getting incremental builds because of new test only subpackages.  Our
voodoo combo of 'go install' and 'go test -c' didn't cache things like
'test/e2e_node/services'.  Add the '-i' flag to 'go test' to install test only
dependencies too.
@jbeda
Copy link
Contributor Author

jbeda commented Oct 4, 2016

Okay! Please take another look. Hopefully we are there.

@ivan4th
Copy link
Contributor

ivan4th commented Oct 4, 2016

I have slightly unexpected possible use for remote docker mode: don't rsync back binaries after build, use them to start DIND cluster on remote docker instead. E.g. I'm on a not very fast 3G connection and want to use GCE for dev. How hard it's to do this? (at least opt out of rsyncing binaries back)

@jbeda
Copy link
Contributor Author

jbeda commented Oct 4, 2016

@ivan4th -- interesting case! Right now we always "copy back" to the host machine but we can explore making that optional after this gets in.

@ivan4th
Copy link
Contributor

ivan4th commented Oct 5, 2016

@jbeda actually it looks like KUBE_RUN_COPY_OUTPUT=n build/run.sh may do the trick.

Copy link
Contributor

@ixdy ixdy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woo! I'm fine with getting this in and then iterating with any additional fixes if necessary. two minor comments, neither of which is blocking.

LOCAL_OUTPUT_BUILD_CONTEXT="${LOCAL_OUTPUT_IMAGE_STAGING}/${KUBE_BUILD_IMAGE}"

kube::version::get_version_vars
kube::version::save_version_vars "${KUBE_ROOT}/.dockerized-kube-version-defs"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nonblocking suggestion: maybe clean deletes this?

# limitations under the License.

# This file creates release artifacts (tar files, container images) that are
# ready to distribute to install or distribute to end users.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "ready to distribute to install or distribute" seems awkward?

@ixdy ixdy added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 6, 2016
@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@duglin
Copy link

duglin commented Oct 6, 2016

woo hoo!

jbeda added a commit to jbeda/kubernetes that referenced this pull request Oct 6, 2016
This was broken by kubernetes#30787. A stray bash `source` caused an undefined variable reference.

Apparently the federation images have a parallel nad different "release" path
that isn't tested by the pre-checkin tests.
k8s-github-robot pushed a commit that referenced this pull request Oct 6, 2016
Automatic merge from submit-queue

Fix broken build/push-federation-images.sh

The federation CI build is broken by #30787. A stray bash `source` caused an undefined variable reference.

Apparently the federation images have a parallel nad different "release" path that isn't tested by the pre-checkin tests.
maxwell92 pushed a commit to maxwell92/kubernetes that referenced this pull request Oct 8, 2016
This was broken by kubernetes#30787. A stray bash `source` caused an undefined variable reference.

Apparently the federation images have a parallel nad different "release" path
that isn't tested by the pre-checkin tests.
@jbeda jbeda deleted the rsync branch October 13, 2016 18:42
k8s-github-robot pushed a commit that referenced this pull request Nov 8, 2016
Automatic merge from submit-queue

Make kubernetes-src.tar.gz contain source code again

**What this PR does / why we need it**: This PR fixes `kubernetes-src.tar.gz` by reviving the logic for `kube-source.tar.gz` from before #30787.

**Which issue this PR fixes**: fixes #36403

@saad-ali @jbeda @zmerlynn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/design Categorizes issue or PR as related to design. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.