Skip to content

Commit

Permalink
fix: pass loop variable as a function parameter (#1470)
Browse files Browse the repository at this point in the history
Signed-off-by: Zhizhen He <hezhizhen.yi@gmail.com>
  • Loading branch information
hezhizhen committed Feb 9, 2023
1 parent 23e4fa9 commit ae3a1e5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 71 deletions.
50 changes: 22 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ go 1.18

require (
github.com/Pallinder/go-randomdata v1.2.0
github.com/bcicen/ctop v0.7.7
github.com/charmbracelet/bubbletea v0.23.1
github.com/charmbracelet/lipgloss v0.6.0
github.com/cockroachdb/errors v1.9.1
github.com/containerd/console v1.0.3
github.com/containerd/containerd v1.6.16
github.com/creack/pty v1.1.18
github.com/docker/cli v23.0.0-rc.3+incompatible
github.com/docker/docker v23.0.0-rc.1+incompatible
github.com/docker/go-connections v0.4.0
github.com/docker/go-units v0.5.0
Expand All @@ -17,6 +20,7 @@ require (
github.com/go-git/go-git/v5 v5.4.2
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
github.com/mattn/go-isatty v0.0.17
github.com/moby/buildkit v0.11.0-rc3.0.20230112115050-60e82c1bcdd7
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
github.com/morikuni/aec v1.0.0
Expand All @@ -25,7 +29,9 @@ require (
github.com/onsi/gomega v1.26.0
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc2
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.13.5
github.com/schollz/progressbar/v3 v3.13.0
github.com/segmentio/analytics-go/v3 v3.2.1
github.com/sirupsen/logrus v1.9.0
github.com/spf13/viper v1.15.0
Expand All @@ -41,46 +47,21 @@ require (
golang.org/x/time v0.1.0
)

require (
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/moby/patternmatcher v0.5.0 // indirect
github.com/schollz/progressbar/v3 v3.13.0 // indirect
)

require (
github.com/aymanbagabas/go-osc52 v1.0.3 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/charmbracelet/bubbletea v0.23.1
github.com/containerd/ttrpc v1.1.0 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.17
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.13.0 // indirect
github.com/op/go-logging v0.0.0-20160211212156-b2cb9fa56473 // indirect
github.com/pkg/errors v0.9.1
github.com/rivo/uniseg v0.4.3 // indirect
github.com/segmentio/backo-go v1.0.0 // indirect
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/bcicen/ctop v0.7.7
github.com/aymanbagabas/go-osc52 v1.0.3 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/containerd/continuity v0.3.0 // indirect
github.com/containerd/ttrpc v1.1.0 // indirect
github.com/containerd/typeurl v1.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/cli v23.0.0-rc.3+incompatible
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
Expand All @@ -102,20 +83,33 @@ require (
github.com/imdario/mergo v0.3.13 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/patternmatcher v0.5.0 // indirect
github.com/moby/sys/signal v0.7.0 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.13.0 // indirect
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d // indirect
github.com/op/go-logging v0.0.0-20160211212156-b2cb9fa56473 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/segmentio/backo-go v1.0.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/kataras/golog v0.0.9/go.mod h1:12HJgwBIZFNGL0EJnMRhmvGA0PQGx8VFwrZtM4CqbAk=
github.com/kataras/golog v0.0.10/go.mod h1:yJ8YKCmyL+nWjERB90Qwn+bdyBZsaQwU3bTVFgkFIp8=
github.com/kataras/iris/v12 v12.1.8/go.mod h1:LMYy4VlP67TQ3Zgriz8RE2h2kMZV2SgMYbq3UhfoFmE=
github.com/kataras/neffos v0.0.14/go.mod h1:8lqADm8PnbeFfL7CLXh1WHw53dG27MC3pgi2R1rmoTE=
Expand Down Expand Up @@ -516,7 +515,6 @@ github.com/prometheus/procfs v0.0.0-20180125133057-cb4147076ac7/go.mod h1:c3At6R
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
Expand All @@ -533,7 +531,6 @@ github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFo
github.com/schollz/closestmatch v2.1.0+incompatible/go.mod h1:RtP1ddjLong6gTkbtmuhtR2uUrrJOpYzYRvbcPAid+g=
github.com/schollz/progressbar/v3 v3.13.0 h1:9TeeWRcjW2qd05I8Kf9knPkW4vLM/hYoa6z9ABvxje8=
github.com/schollz/progressbar/v3 v3.13.0/go.mod h1:ZBYnSuLAX2LU8P8UiKN/KgF2DY58AJC8yfVYLPC8Ly4=
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=
github.com/secure-systems-lab/go-securesystemslib v0.4.0 h1:b23VGrQhTA8cN2CbBw7/FulN9fTtqYUdS5+Oxzt+DUE=
github.com/segmentio/analytics-go/v3 v3.2.1 h1:G+f90zxtc1p9G+WigVyTR0xNfOghOGs/PYAlljLOyeg=
Expand Down
73 changes: 33 additions & 40 deletions pkg/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,7 @@ func (b generalBuilder) build(ctx context.Context, pw progresswriter.Writer) err
}
}
defer pipeW.Close()
solveOpt := client.SolveOpt{
CacheExports: ce,
Exports: []client.ExportEntry{entry},
LocalDirs: map[string]string{
flag.FlagCacheDir: home.GetManager().CacheDir(),
flag.FlagBuildContext: b.BuildContextDir,
},
Session: attachable,
}
if b.UseHTTPProxy {
solveOpt.FrontendAttrs = map[string]string{
"build-arg:HTTPS_PROXY": os.Getenv("HTTPS_PROXY"),
"build-arg:HTTP_PROXY": os.Getenv("HTTP_PROXY"),
"build-arg:NO_PROXY": os.Getenv("NO_PROXY"),
}
}
solveOpt := constructSolveOpt(ce, entry, b, attachable)
_, err := b.Client.Build(ctx, solveOpt, "envd", b.BuildFunc(), pw.Status())
if err != nil {
err = errors.Wrap(&BuildkitdErr{err: err}, "Buildkit error")
Expand All @@ -270,31 +255,18 @@ func (b generalBuilder) build(ctx context.Context, pw progresswriter.Writer) err
return nil
})
default:
eg.Go(func() error {
solveOpt := client.SolveOpt{
CacheExports: ce,
Exports: []client.ExportEntry{entry},
LocalDirs: map[string]string{
flag.FlagCacheDir: home.GetManager().CacheDir(),
flag.FlagBuildContext: b.BuildContextDir,
},
Session: attachable,
}
if b.UseHTTPProxy {
solveOpt.FrontendAttrs = map[string]string{
"build-arg:HTTPS_PROXY": os.Getenv("HTTPS_PROXY"),
"build-arg:HTTP_PROXY": os.Getenv("HTTP_PROXY"),
"build-arg:NO_PROXY": os.Getenv("NO_PROXY"),
func(entry client.ExportEntry) {
eg.Go(func() error {
solveOpt := constructSolveOpt(ce, entry, b, attachable)
_, err := b.Client.Build(ctx, solveOpt, "envd", b.BuildFunc(), pw.Status())
if err != nil {
err = errors.Wrap(err, "failed to solve LLB")
return err
}
}
_, err := b.Client.Build(ctx, solveOpt, "envd", b.BuildFunc(), pw.Status())
if err != nil {
err = errors.Wrap(err, "failed to solve LLB")
return err
}
b.logger.Debug("llb def is solved successfully")
return nil
})
b.logger.Debug("llb def is solved successfully")
return nil
})
}(entry)
}
}

Expand All @@ -319,3 +291,24 @@ func (b generalBuilder) build(ctx context.Context, pw progresswriter.Writer) err
b.logger.Debug("build successfully")
return nil
}

func constructSolveOpt(ce []client.CacheOptionsEntry, entry client.ExportEntry,
b generalBuilder, attachable []session.Attachable) client.SolveOpt {
opt := client.SolveOpt{
CacheExports: ce,
Exports: []client.ExportEntry{entry},
LocalDirs: map[string]string{
flag.FlagCacheDir: home.GetManager().CacheDir(),
flag.FlagBuildContext: b.BuildContextDir,
},
Session: attachable,
}
if b.UseHTTPProxy {
opt.FrontendAttrs = map[string]string{
"build-arg:HTTPS_PROXY": os.Getenv("HTTPS_PROXY"),
"build-arg:HTTP_PROXY": os.Getenv("HTTP_PROXY"),
"build-arg:NO_PROXY": os.Getenv("NO_PROXY"),
}
}
return opt
}

0 comments on commit ae3a1e5

Please sign in to comment.