Skip to content

Commit

Permalink
Merge pull request #948 from traPtitech/fix/buildkit/deprected-SolvOp…
Browse files Browse the repository at this point in the history
…t-field

fix: use LocalMounts in buildkit SolveOpt
  • Loading branch information
pirosiki197 authored Aug 5, 2024
2 parents 80de948 + 25d04b8 commit 59b03f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/tonistiigi/fsutil v0.0.0-20240424095704-91a3fc46842c
github.com/traefik/traefik/v3 v3.1.1
github.com/volatiletech/null/v8 v8.1.2
github.com/volatiletech/sqlboiler/v4 v4.16.2
Expand Down Expand Up @@ -171,7 +172,6 @@ require (
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tonistiigi/fsutil v0.0.0-20240424095704-91a3fc46842c // indirect
github.com/tonistiigi/go-csvvalue v0.0.0-20240710180619-ddb21b71c0b4 // indirect
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea // indirect
github.com/tonistiigi/vt100 v0.0.0-20240514184818-90bafcd6abab // indirect
Expand Down
17 changes: 13 additions & 4 deletions pkg/usecase/builder/build_buildkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/moby/buildkit/util/progress/progressui"
"github.com/samber/lo"
log "github.com/sirupsen/logrus"
"github.com/tonistiigi/fsutil"
"golang.org/x/sync/errgroup"

"github.com/traPtitech/neoshowcase/pkg/domain"
Expand Down Expand Up @@ -114,6 +115,14 @@ func (s *builderService) solveDockerfile(
env map[string]string,
ch chan *buildkit.SolveStatus,
) error {
ctxMount, err := fsutil.NewFS(contextDir)
if err != nil {
return errors.Wrap(err, "invalid context mount dir")
}
dockerfileMount, err := fsutil.NewFS(dockerfileDir)
if err != nil {
return errors.Wrap(err, "invalid dockerfile mount dir")
}
opts := buildkit.SolveOpt{
Exports: []buildkit.ExportEntry{{
Type: buildkit.ExporterImage,
Expand All @@ -122,9 +131,9 @@ func (s *builderService) solveDockerfile(
"push": "true",
},
}},
LocalDirs: map[string]string{
"context": contextDir,
"dockerfile": dockerfileDir,
LocalMounts: map[string]fsutil.FS{
"context": ctxMount,
"dockerfile": dockerfileMount,
},
Frontend: "dockerfile.v0",
FrontendAttrs: ds.MergeMap(
Expand All @@ -135,7 +144,7 @@ func (s *builderService) solveDockerfile(
),
Session: s.authSessions(),
}
_, err := s.buildkit.Solve(ctx, nil, opts, ch)
_, err = s.buildkit.Solve(ctx, nil, opts, ch)
return err
}

Expand Down
9 changes: 7 additions & 2 deletions pkg/usecase/builder/build_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
buildkit "github.com/moby/buildkit/client"
"github.com/moby/buildkit/client/llb"
"github.com/regclient/regclient/types/ref"
"github.com/tonistiigi/fsutil"
)

func (s *builderService) buildStaticExtract(
Expand All @@ -28,13 +29,17 @@ func (s *builderService) buildStaticExtract(
if err != nil {
return errors.Wrap(err, "failed to marshal llb")
}
mount, err := fsutil.NewFS(st.repositoryTempDir)
if err != nil {
return errors.Wrap(err, "invalid mount dir")
}
_, err = s.buildkit.Solve(ctx, def, buildkit.SolveOpt{
Exports: []buildkit.ExportEntry{{
Type: buildkit.ExporterTar,
Output: func(_ map[string]string) (io.WriteCloser, error) { return st.artifactTempFile, nil },
}},
LocalDirs: map[string]string{
"local-src": st.repositoryTempDir,
LocalMounts: map[string]fsutil.FS{
"local-src": mount,
},
Session: s.authSessions(),
}, ch)
Expand Down

0 comments on commit 59b03f4

Please sign in to comment.