Skip to content

Commit 09d4542

Browse files
author
Christian Weichel
committed
Make yarn mutex configurable
1 parent 64d01e4 commit 09d4542

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

cmd/root.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"strings"
77

8+
"github.com/gookit/color"
89
log "github.com/sirupsen/logrus"
910
"github.com/spf13/cobra"
1011
"github.com/typefox/leeway/pkg/leeway"
@@ -29,25 +30,27 @@ var (
2930
var rootCmd = &cobra.Command{
3031
Use: "leeway",
3132
Short: "A caching meta-build system",
32-
Long: `Leeway is a heavily caching build system for Go, Typescript and Docker projects. It knows three core concepts:
33+
Long: color.Render(`<light_yellow>Leeway is a heavily caching build system</> for Go, Typescript and Docker projects. It knows three core concepts:
3334
Workspace: the workspace is the root of all operations. All component names are relative to this path. No relevant
3435
file must be placed outside the workspace. The workspace root is marked with a WORKSPACE file.
3536
Component: a component is single piece of standalone software. Every folder in the workspace which contains a BUILD file
3637
is a component. Components are identifed by their path relative to the workspace root.
3738
Package: packages are the buildable unit in leeway. Every component can define multiple packages in its build file.
3839
Packages are identified by their name prefixed with the component name, e.g. some-component:pkg
3940
40-
Configuration
41+
<white>Configuration</>
4142
Leeway is configured exclusively through the WORKSPACE/BUILD files and environment variables. The following environment
4243
variables have an effect on leeway:
43-
LEEWAY_WORKSPACE_ROOT Contains the path where to look for a WORKSPACE file. Can also be set using --workspace.
44-
LEEWAY_REMOTE_CACHE_BUCKET Enables remote caching using GCP buckets. Set this variable to the bucket name used for caching.
44+
<light_blue>LEEWAY_WORKSPACE_ROOT</> Contains the path where to look for a WORKSPACE file. Can also be set using --workspace.
45+
<light_blue>LEEWAY_REMOTE_CACHE_BUCKET</> Enables remote caching using GCP buckets. Set this variable to the bucket name used for caching.
4546
When this variable is set, leeway expects "gsutil" in the path configured and authenticated so
46-
that it can work with the bucket.
47-
LEEWAY_CACHE_DIR Location of the local build cache. The directory does not have to exist yet.
48-
LEEWAY_BUILD_DIR Working location of leeway (i.e. where the actual builds happen). This location will see heavy I/O
47+
that it can work with the bucket.
48+
<light_blue>LEEWAY_CACHE_DIR</> Location of the local build cache. The directory does not have to exist yet.
49+
<light_blue>LEEWAY_BUILD_DIR</> Working location of leeway (i.e. where the actual builds happen). This location will see heavy I/O
4950
which makes it advisable to place this on a fast SSD or in RAM.
50-
`,
51+
<light_blue>LEEWAY_YARN_MUTEX</> Configures the mutex flag leeway will pass to yarn. Defaults to "network".
52+
See https://yarnpkg.com/lang/en/docs/cli/#toc-concurrency-and-mutex for possible values.
53+
`),
5154
PersistentPreRun: func(cmd *cobra.Command, args []string) {
5255
if verbose {
5356
log.SetLevel(log.DebugLevel)

pkg/leeway/build.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ const (
6565
// EnvvarBuildDir names the environment variable we take the build dir location from
6666
EnvvarBuildDir = "LEEWAY_BUILD_DIR"
6767

68+
// EnvvarYarnMutex configures the mutex flag leeway will pass to yarn.
69+
// See https://yarnpkg.com/lang/en/docs/cli/#toc-concurrency-and-mutex for possible values.
70+
// Defaults to "network".
71+
EnvvarYarnMutex = "LEEWAY_YARN_MUTEX"
72+
6873
// dockerImageNamesFiles is the name of the file store in poushed Docker build artifacts
6974
// which contains the names of the Docker images we just pushed
7075
dockerImageNamesFiles = "imgnames.txt"
@@ -162,7 +167,7 @@ func Build(pkg *Package, localCache Cache, remoteCache RemoteCache) error {
162167
allpkg := append(requirements, pkg)
163168

164169
ctx, err := newBuildContext(localCache)
165-
var errs []string
170+
unresolvedArgs := make(map[string][]string)
166171
for _, dep := range allpkg {
167172
_, exists := ctx.LocalCache.Location(dep)
168173
if exists {
@@ -171,14 +176,24 @@ func Build(pkg *Package, localCache Cache, remoteCache RemoteCache) error {
171176

172177
ua, err := FindUnresolvedArguments(dep)
173178
if err != nil {
174-
errs = append(errs, err.Error())
179+
return err
175180
}
176-
if len(ua) != 0 {
177-
errs = append(errs, fmt.Sprintf("%s: cannot build with unresolved arguments: %s", dep.FullName(), strings.Join(ua, ", ")))
181+
for _, arg := range ua {
182+
pkgs, ok := unresolvedArgs[arg]
183+
if !ok {
184+
pkgs = []string{}
185+
}
186+
pkgs = append(pkgs, dep.FullName())
187+
unresolvedArgs[arg] = pkgs
178188
}
179189
}
180-
if len(errs) != 0 {
181-
return xerrors.Errorf(strings.Join(errs, "\n"))
190+
if len(unresolvedArgs) != 0 {
191+
var msg string
192+
for arg, pkgs := range unresolvedArgs {
193+
cleanArg := strings.TrimSuffix(strings.TrimPrefix(arg, "${"), "}")
194+
msg += fmt.Sprintf("cannot build with unresolved argument \"%s\": use -D%s=value to set the argument\n\t%s appears in %s\n\n", arg, cleanArg, arg, strings.Join(pkgs, ", "))
195+
}
196+
return xerrors.Errorf(msg)
182197
}
183198

184199
err = remoteCache.Download(ctx.LocalCache, requirements)
@@ -431,7 +446,11 @@ func (p *Package) buildTypescript(buildctx *buildContext, wd, result string) (er
431446

432447
// The yarn cache cannot handly conccurency proplery and needs to be looked.
433448
// Make sure that all our yarn install calls lock the yarn cache.
434-
yarnMutex := "file://" + filepath.Join(buildctx.BuildDir(), "yarn-mutex")
449+
yarnMutex := os.Getenv(EnvvarYarnMutex)
450+
if yarnMutex == "" {
451+
log.Debug("%s is not set, defaulting to \"network\"", EnvvarYarnMutex)
452+
yarnMutex = "network"
453+
}
435454
yarnCache := filepath.Join(buildctx.BuildDir(), "yarn-cache")
436455
commands = append(commands, []string{"yarn", "install", "--mutex", yarnMutex, "--cache-folder", yarnCache})
437456
if len(cfg.BuildCmd) == 0 {

0 commit comments

Comments
 (0)