GoogleContainerTools / skaffold

Easy and Repeatable Kubernetes Development
https://skaffold.dev/
Apache License 2.0
15k stars 1.62k forks source link

Slow Rebuilds Using Gradle+Skaffold+Buildpacks #6947

Open awesometown opened 2 years ago

awesometown commented 2 years ago

Expected behavior

When using "skaffold build" image rebuilds with buildpacks (after an initial successful build) should be fast (<10s ideally).

Actual behavior

Image rebuilds take 1m+. When switching to use the Jib builder, builds are consistently sub 10s.

Information

I have a Spring Boot-based application with a Gradle-based build process. The Spring Boot Gradle plug-in includes support for creating buildpacks based images, and these are what we are currently deploying into production. When adopting skaffold, we defaulted to using the buildpacks builder as well for consistency, but have found it to be noticeably slower than other options (specifically Jib, or rebuilding without skaffold).

Comparisons below. These are based on rebuilding the project with a minor code change (eg. changing a string from "Hello World!" to "Hello World!!"):

Further details:

apiVersion: skaffold/v2beta23
kind: Config
metadata:
  name: skaffold-boot

build:
  local:
    push: false
  artifacts:
    # - image: skaffold-boot
    #   context: .
    #   jib: {}
   - image: skaffold-boot
     buildpacks:
       builder: paketobuildpacks/builder:base

deploy:
  kubeContext: minikube
  kustomize:
    paths:
      - k8s/local

portForward:
  - resourceType: deployment
    resourceName: skaffold-boot
    namespace: default
    port: 8080
    localPort: 8080

Steps to reproduce the behavior

Sample project: https://github.com/awesometown/skaffold-boot

Logs for the various run types are in the linked repository.

The skaffold.yaml in the project contains two builder configs, one using buildpacks, one for jib. You can uncomment the appropriate one and re-run skaffold build after making a trivial change to the source code.

You can also see the performance of creating a buldpacks build without skaffold by running ./gradlew bootBuildImage

briandealwis commented 2 years ago

@awesometown would it be possible to include some logs to compare a 1st and 2nd run with skaffold build --timestamps?

awesometown commented 2 years ago

I added three logs to the linked repository:

briandealwis commented 2 years ago

@awesometown I don't see 1 minute or more:

awesometown commented 2 years ago

Hmm... you're right. Sorry; I'd run them in the background and not done the mental math myself.

I just re-ran two more builds, each after having made a single string change in the application. The logs are here and here and are more representative of what I was seeing before. I'm not actually sure how I achieved those 22s times now :S

The bulk of the slowdown is all in the gradle run (~45s).

Running the (I think?) same gradle command outside the Skaffold/buildpacks build (gradlew --no-daemon assemble) takes about ~8s.

tejal29 commented 2 years ago

related to #3665 mabye?