Skip to content

Commit

Permalink
set -j to GOMAXPROCS at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh committed Aug 10, 2021
1 parent d8a6e65 commit 5413ef4
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion doc/ko_apply.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ko apply -f FILENAME [flags]
--image-label strings Which labels (key=value) to add to the image.
--insecure-registry Whether to skip TLS verification on the registry
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
-j, --jobs int The maximum number of concurrent builds (default 8)
-j, --jobs int The maximum number of concurrent builds (default GOMAXPROCS)
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
-L, --local Load into images to local docker daemon.
-n, --namespace string If present, the namespace scope for this CLI request
Expand Down
2 changes: 1 addition & 1 deletion doc/ko_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ko create -f FILENAME [flags]
--image-label strings Which labels (key=value) to add to the image.
--insecure-registry Whether to skip TLS verification on the registry
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
-j, --jobs int The maximum number of concurrent builds (default 8)
-j, --jobs int The maximum number of concurrent builds (default GOMAXPROCS)
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
-L, --local Load into images to local docker daemon.
-n, --namespace string If present, the namespace scope for this CLI request
Expand Down
2 changes: 1 addition & 1 deletion doc/ko_publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ko publish IMPORTPATH... [flags]
-h, --help help for publish
--image-label strings Which labels (key=value) to add to the image.
--insecure-registry Whether to skip TLS verification on the registry
-j, --jobs int The maximum number of concurrent builds (default 8)
-j, --jobs int The maximum number of concurrent builds (default GOMAXPROCS)
-L, --local Load into images to local docker daemon.
--oci-layout-path string Path to save the OCI image layout of the built images
--platform string Which platform to use when pulling a multi-platform base. Format: all | <os>[/<arch>[/<variant>]][,platform]*
Expand Down
2 changes: 1 addition & 1 deletion doc/ko_resolve.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ko resolve -f FILENAME [flags]
-h, --help help for resolve
--image-label strings Which labels (key=value) to add to the image.
--insecure-registry Whether to skip TLS verification on the registry
-j, --jobs int The maximum number of concurrent builds (default 8)
-j, --jobs int The maximum number of concurrent builds (default GOMAXPROCS)
-L, --local Load into images to local docker daemon.
--oci-layout-path string Path to save the OCI image layout of the built images
--platform string Which platform to use when pulling a multi-platform base. Format: all | <os>[/<arch>[/<variant>]][,platform]*
Expand Down
2 changes: 1 addition & 1 deletion doc/ko_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ko run IMPORTPATH [flags]
-h, --help help for run
--image-label strings Which labels (key=value) to add to the image.
--insecure-registry Whether to skip TLS verification on the registry
-j, --jobs int The maximum number of concurrent builds (default 8)
-j, --jobs int The maximum number of concurrent builds (default GOMAXPROCS)
-L, --local Load into images to local docker daemon.
--oci-layout-path string Path to save the OCI image layout of the built images
--platform string Which platform to use when pulling a multi-platform base. Format: all | <os>[/<arch>[/<variant>]][,platform]*
Expand Down
6 changes: 2 additions & 4 deletions pkg/commands/options/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package options

import (
"runtime"

"github.com/spf13/cobra"
)

Expand All @@ -44,8 +42,8 @@ type BuildOptions struct {
}

func AddBuildOptions(cmd *cobra.Command, bo *BuildOptions) {
cmd.Flags().IntVarP(&bo.ConcurrentBuilds, "jobs", "j", runtime.GOMAXPROCS(0),
"The maximum number of concurrent builds")
cmd.Flags().IntVarP(&bo.ConcurrentBuilds, "jobs", "j", 0,
"The maximum number of concurrent builds (default GOMAXPROCS)")
cmd.Flags().BoolVar(&bo.DisableOptimizations, "disable-optimizations", bo.DisableOptimizations,
"Disable optimizations when building Go code. Useful when you want to interactively debug the created container.")
cmd.Flags().StringVar(&bo.Platform, "platform", "",
Expand Down
4 changes: 4 additions & 0 deletions pkg/commands/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"log"
"os"
"path"
"runtime"
"strings"
"sync"

Expand Down Expand Up @@ -127,6 +128,9 @@ func makeBuilder(ctx context.Context, bo *options.BuildOptions) (*build.Caching,
return nil, err
}

if bo.ConcurrentBuilds == 0 {
bo.ConcurrentBuilds = runtime.GOMAXPROCS(0)
}
innerBuilder = build.NewLimiter(innerBuilder, bo.ConcurrentBuilds)

// tl;dr Wrap builder in a caching builder.
Expand Down

0 comments on commit 5413ef4

Please sign in to comment.