Skip to content

Commit

Permalink
Use one Yarn cache per build
Browse files Browse the repository at this point in the history
fixes #72
fixes #71
  • Loading branch information
csweichel committed Dec 5, 2021
1 parent 6340960 commit f023318
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/leeway/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package leeway

import (
"context"
"crypto/rand"
"encoding/base64"
"encoding/json"
"fmt"
Expand All @@ -13,6 +14,7 @@ import (
"regexp"
"strings"
"sync"
"time"

"github.com/gitpod-io/leeway/pkg/gokart"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -45,6 +47,7 @@ const (
type buildContext struct {
buildOptions
buildDir string
buildID string

mu sync.Mutex
newlyBuiltPackages map[string]*Package
Expand Down Expand Up @@ -99,9 +102,17 @@ func newBuildContext(options buildOptions) (ctx *buildContext, err error) {
buildLimit = semaphore.NewWeighted(options.MaxConcurrentTasks)
}

b := make([]byte, 4)
_, err = rand.Read(b)
if err != nil {
return nil, xerrors.Errorf("cannot produce random build ID: %w", err)
}
buildID := fmt.Sprintf("%d-%x", time.Now().UnixNano(), b)

ctx = &buildContext{
buildOptions: options,
buildDir: buildDir,
buildID: buildID,
newlyBuiltPackages: make(map[string]*Package),
pkgLockCond: sync.NewCond(&sync.Mutex{}),
pkgLocks: make(map[string]struct{}),
Expand Down Expand Up @@ -808,7 +819,7 @@ func (p *Package) buildYarn(buildctx *buildContext, wd, result string) (err erro
log.Debugf("%s is not set, defaulting to \"network\"", EnvvarYarnMutex)
yarnMutex = "network"
}
yarnCache := filepath.Join(buildctx.BuildDir(), "yarn-cache")
yarnCache := filepath.Join(buildctx.BuildDir(), fmt.Sprintf("yarn-cache-%s", buildctx.buildID))
if len(cfg.Commands.Install) == 0 {
commands = append(commands, []string{"yarn", "install", "--mutex", yarnMutex, "--cache-folder", yarnCache})
} else {
Expand Down

0 comments on commit f023318

Please sign in to comment.