Skip to content

Commit

Permalink
Use new design of isolator (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
outofforest committed Jul 29, 2023
1 parent ebbf282 commit 4defe76
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 246 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/google/uuid v1.3.0
github.com/outofforest/go-zfs/v3 v3.1.14
github.com/outofforest/ioc/v2 v2.5.2
github.com/outofforest/isolator v0.8.2
github.com/outofforest/isolator v0.12.0
github.com/outofforest/logger v0.4.0
github.com/outofforest/parallel v0.2.3
github.com/outofforest/run v0.6.0
Expand All @@ -40,6 +40,6 @@ require (
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
)
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ github.com/outofforest/go-zfs/v3 v3.1.14 h1:F0MosonFuGwiIotlMVKoMsvAmISnOWOAncev
github.com/outofforest/go-zfs/v3 v3.1.14/go.mod h1:H8SgVKbvhso4bQGQMn6P21mFEd3oDOIaBH2w0Bcsu3c=
github.com/outofforest/ioc/v2 v2.5.2 h1:4mNzLuzoZTXL/cO0qf1TrSYvejMgbZz5OUhdLzAUbek=
github.com/outofforest/ioc/v2 v2.5.2/go.mod h1:yI+FHuHchC/t6nVo3WJ96qEgCXdHQKFI/4wW2/75YcU=
github.com/outofforest/isolator v0.8.2 h1:QbNe1kD+ktdgN2Haps6Mx3r1vB0aJFHDLSm8C/WDZI0=
github.com/outofforest/isolator v0.8.2/go.mod h1:CWQkLwr3qXyXxouqvS1QDC1nfUQ2FCdcUJSMrZVikJc=
github.com/outofforest/isolator v0.12.0 h1:9t5MZGvyfoqsCtrXRTGJ13QPt9JMD67wTqcOzFItaIs=
github.com/outofforest/isolator v0.12.0/go.mod h1:vxqlNlksXSf6MZazVN4ltWL0fSEt4p7YFGB6tst5mQw=
github.com/outofforest/libexec v0.3.9 h1:KvVLuKDHqpydwNoKm+j36hi9DVPU61X4oHonlZ5cw88=
github.com/outofforest/libexec v0.3.9/go.mod h1:J2rUB/m0ER8UNOHd3/UQM55bvh1cbMwhb8gibeF/zyo=
github.com/outofforest/logger v0.3.3/go.mod h1:+M5sO17Va9V33t28Qs9VqRQ8bFV501Uhq2PtQY+R3Ms=
Expand Down Expand Up @@ -61,8 +61,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0=
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
Expand Down Expand Up @@ -95,8 +95,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
90 changes: 39 additions & 51 deletions infra/base/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/outofforest/isolator"
"github.com/outofforest/isolator/wire"
"github.com/outofforest/parallel"
"github.com/pkg/errors"

"github.com/outofforest/osman/infra/types"
Expand All @@ -22,61 +21,50 @@ type dockerInitializer struct {
}

// Init fetches image from docker registry and integrates it inside directory
func (f *dockerInitializer) Init(ctx context.Context, cacheDir, dir string, buildKey types.BuildKey) error {
return parallel.Run(ctx, func(ctx context.Context, spawn parallel.SpawnFn) error {
incoming := make(chan interface{})
outgoing := make(chan interface{})
func (f *dockerInitializer) Init(ctx context.Context, cacheDir, dir string, buildKey types.BuildKey) (retErr error) {
cacheDir = filepath.Join(cacheDir, "docker-images")
if err := os.MkdirAll(cacheDir, 0o700); err != nil {
return errors.WithStack(err)
}

cacheDir := filepath.Join(cacheDir, "docker-images")
if err := os.MkdirAll(cacheDir, 0o700); err != nil {
return errors.WithStack(err)
}

spawn("isolator", parallel.Fail, func(ctx context.Context) error {
return isolator.Run(ctx, isolator.Config{
Dir: dir,
Types: []interface{}{
wire.Result{},
return isolator.Run(ctx, isolator.Config{
Dir: dir,
Types: []interface{}{
wire.Result{},
},
Executor: wire.Config{
UseHostNetwork: true,
Mounts: []wire.Mount{
{
Host: cacheDir,
Namespace: "/.docker-cache",
Writable: true,
},
Executor: wire.Config{
NoStandardMounts: true,
Mounts: []wire.Mount{
{
Host: cacheDir,
Container: "/.docker-cache",
Writable: true,
},
},
},
Incoming: incoming,
Outgoing: outgoing,
})
})
spawn("init", parallel.Exit, func(ctx context.Context) error {
select {
case <-ctx.Done():
return errors.WithStack(ctx.Err())
case outgoing <- wire.InflateDockerImage{
CacheDir: "/.docker-cache",
Image: buildKey.Name,
Tag: string(buildKey.Tag),
}:
}
},
},
}, func(ctx context.Context, incoming <-chan interface{}, outgoing chan<- interface{}) error {
select {
case <-ctx.Done():
return errors.WithStack(ctx.Err())
case outgoing <- wire.InflateDockerImage{
CacheDir: "/.docker-cache",
Image: buildKey.Name,
Tag: string(buildKey.Tag),
}:
}

select {
case <-ctx.Done():
return errors.WithStack(ctx.Err())
case content := <-incoming:
result, ok := content.(wire.Result)
if !ok {
return errors.Errorf("expected Result, got: %T", content)
}
if result.Error != "" {
return errors.New(result.Error)
for content := range incoming {
switch m := content.(type) {
case wire.Result:
if m.Error != "" {
return errors.New(m.Error)
}
return nil
default:
return errors.New("unexpected message received")
}
})
return nil
}

return errors.WithStack(ctx.Err())
})
}
Loading

0 comments on commit 4defe76

Please sign in to comment.