Skip to content

Commit

Permalink
workable
Browse files Browse the repository at this point in the history
  • Loading branch information
blampe committed Jan 24, 2024
1 parent 45bd3d7 commit a5c4552
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 76 deletions.
9 changes: 2 additions & 7 deletions provider/cmd/pulumi-resource-docker/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@
},
"size": {
"type": "integer"
},
"urls": {
"type": "array",
"items": {
"type": "string"
}
}
},
"type": "object",
Expand Down Expand Up @@ -2174,7 +2168,8 @@
}
},
"required": [
"tags"
"tags",
"manifests"
],
"inputProperties": {
"buildArgs": {
Expand Down
3 changes: 2 additions & 1 deletion provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ require (
github.com/moby/patternmatcher v0.6.0
github.com/muesli/reflow v0.3.0
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc5
github.com/otiai10/copy v1.14.0
github.com/pkg/errors v0.9.1
github.com/pulumi/pulumi-go-provider v0.14.0
github.com/pulumi/pulumi-go-provider/integration v0.10.0
Expand Down Expand Up @@ -229,7 +231,6 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/natefinch/atomic v1.0.1 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/opencontainers/runc v1.1.9 // indirect
github.com/opentracing/basictracer-go v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions provider/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,10 @@ github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxS
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
github.com/ovh/go-ovh v1.1.0/go.mod h1:AxitLZ5HBRPyUd+Zl60Ajaag+rNTdVXWIkzfrVuTXWA=
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
Expand Down
3 changes: 2 additions & 1 deletion provider/hybrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func (dp dockerHybridProvider) Call(ctx context.Context, request *rpc.CallReques
}

func (dp dockerHybridProvider) Cancel(ctx context.Context, e *empty.Empty) (*empty.Empty, error) {
return &empty.Empty{}, nil
// Only buildx implements Cancel.
return dp.buildxProvider.Cancel(ctx, e)
}

func (dp dockerHybridProvider) GetSchema(ctx context.Context, request *rpc.GetSchemaRequest) (
Expand Down
34 changes: 19 additions & 15 deletions provider/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/util/progress/progressui"
cp "github.com/otiai10/copy"

"github.com/pulumi/pulumi-docker/provider/v4/internal/properties"
)
Expand All @@ -28,13 +29,15 @@ import (
type Client interface {
Auth(ctx context.Context, creds properties.RegistryAuth) error
Build(ctx context.Context, opts controllerapi.BuildOptions) (*client.SolveResponse, error)
Close(ctx context.Context) error
BuildKitEnabled() (bool, error)
Inspect(ctx context.Context, id string) ([]manifesttypes.ImageManifest, error)
Delete(ctx context.Context, id string) ([]types.ImageDeleteResponseItem, error)
}

type docker struct {
cli *command.DockerCli
dir string
}

var _ Client = (*docker)(nil)
Expand All @@ -47,29 +50,26 @@ func newDockerClient() (*docker, error) {
return nil, err
}

// We need to load the host's configuration before we call Initialize
// because it sets some global state.
hostcfg := config.LoadDefaultConfigFile(nil)

// We create a temporary directory for our config to not disturb the host's
// existing settings.
dir, err := os.MkdirTemp("", "pulumi-docker-")
if err != nil {
return nil, err
}
// Attempt to copy the host's existing config, if it exists, over to our
// temporary config directory. This ensures we preserve things like
// credential helpers, builders, etc.
if _, serr := os.Stat(config.Dir()); serr == nil {
_ = cp.Copy(config.Dir(), dir)
}

opts := &flags.ClientOptions{
ConfigDir: dir,
// TODO(github.com/pulumi/pulumi-docker/issues/946): Support TLS options
}
err = cli.Initialize(opts)

// Attempt to copy the host's existing cred helpers over to our temporary
// config directory. This ensures we preserve things like credentialHelpers.
if content, err := os.ReadFile(hostcfg.Filename); err == nil {
_ = os.WriteFile(cli.ConfigFile().Filename, content, 0o600)
}

return &docker{cli: cli}, err
return &docker{cli: cli, dir: dir}, err
}

func (d *docker) Auth(ctx context.Context, creds properties.RegistryAuth) error {
Expand All @@ -90,17 +90,16 @@ func (d *docker) Auth(ctx context.Context, creds properties.RegistryAuth) error
}

// Workaround for https://github.com/docker/docker-credential-helpers/issues/37.
if existing, err := cfg.GetAuthConfig(creds.Address); err == nil && existing.ServerAddress != "" {
if existing, err := cfg.GetAuthConfig(creds.Address); err == nil {
// Confirm the auth is still valid. Otherwise we'll set it to the
// provided config.
// TODO: Only do this on preview?
_, err = d.cli.Client().RegistryLogin(ctx, registrytypes.AuthConfig{
Auth: existing.Auth,
Email: existing.Email,
IdentityToken: existing.IdentityToken,
Password: existing.Password,
RegistryToken: existing.RegistryToken,
ServerAddress: existing.ServerAddress,
ServerAddress: creds.Address, // ServerAddress is sometimes empty.
Username: existing.Username,
})
if err == nil {
Expand All @@ -110,7 +109,7 @@ func (d *docker) Auth(ctx context.Context, creds properties.RegistryAuth) error

err := cfg.GetCredentialsStore(creds.Address).Store(auth)
if err != nil {
return fmt.Errorf("storing auth: %w", err)
return fmt.Errorf("%q: %w", creds.Address, err)
}
return nil
}
Expand All @@ -136,6 +135,11 @@ func (d *docker) BuildKitEnabled() (bool, error) {
return d.cli.BuildKitEnabled()
}

// Close cleans up temporary configs.
func (d *docker) Close(_ context.Context) error {
return os.RemoveAll(d.dir)
}

// Inspect inspects an image.
func (d *docker) Inspect(ctx context.Context, id string) ([]manifesttypes.ImageManifest, error) {
ref, err := normalizeReference(id)
Expand Down
10 changes: 7 additions & 3 deletions provider/internal/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (ia *ImageArgs) Annotate(a infer.Annotator) {
type ImageState struct {
ImageArgs

Manifests []properties.Manifest `pulumi:"manifests,optional" provider:"output"`
Manifests []properties.Manifest `pulumi:"manifests" provider:"output"`
}

// Annotate describes outputs of the Image resource.
Expand Down Expand Up @@ -321,12 +321,11 @@ func (*Image) Read(
},
Ref: m.Ref.String(),
Size: m.Descriptor.Size,
URLs: m.Descriptor.URLs,
})
}
}
case "docker":
//
// TODO: Inspect local image and munge it into a manifest.
default:
// Other export types (e.g. file) are not supported.
continue
Expand Down Expand Up @@ -366,3 +365,8 @@ func (*Image) Delete(

return err
}

func (*Image) Cancel(ctx provider.Context) error {
cfg := infer.GetConfig[Config](ctx)
return cfg.client.Close(ctx)
}
1 change: 0 additions & 1 deletion provider/internal/properties/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ type Manifest struct {
Platform Platform `pulumi:"platform"`
Ref string `pulumi:"ref"`
Size int64 `pulumi:"size"`
URLs []string `pulumi:"urls,optional"`
}

type Platform struct {
Expand Down
6 changes: 1 addition & 5 deletions sdk/dotnet/Buildx/Outputs/Manifest.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 4 additions & 10 deletions sdk/go/docker/buildx/pulumiTypes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/java/src/main/java/com/pulumi/docker/buildx/Image.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/nodejs/buildx/image.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion sdk/nodejs/types/output.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/python/pulumi_docker/buildx/image.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a5c4552

Please sign in to comment.