Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cache From feature #467

Merged
merged 4 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions provider/cmd/pulumi-resource-docker/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3033,14 +3033,14 @@
]
},
"docker:index/cacheFrom:CacheFrom": {
"description": "Specifies information about where to obtain a cache",
"description": "Contains a list of images to reference when building using a cache",
"properties": {
"stages": {
"images": {
"type": "array",
"items": {
"type": "string"
},
"description": "A list of cached build stages"
"description": "Specifies cached images"
}
},
"type": "object"
Expand All @@ -3061,15 +3061,8 @@
"default": "BuilderBuildKit"
},
"cacheFrom": {
"oneOf": [
{
"type": "boolean"
},
{
"$ref": "#/types/docker:index/cacheFrom:CacheFrom"
}
],
"description": "A cached image or list of build stages to use as build cache"
"$ref": "#/types/docker:index/cacheFrom:CacheFrom",
"description": "A list of images to use as build cache"
},
"context": {
"type": "string",
Expand Down
31 changes: 14 additions & 17 deletions provider/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ func (p *dockerNativeProvider) dockerBuild(ctx context.Context,
Dockerfile: img.Build.Dockerfile,
Tags: []string{img.Name}, //this should build the image locally, sans registry info
Remove: true,
//CacheFrom: img.Build.CachedImages, // TODO: this needs a login, so needs to be handled differently.
BuildArgs: build.Args,
Version: build.BuilderVersion,
CacheFrom: img.Build.CachedImages,
BuildArgs: build.Args,
Version: build.BuilderVersion,

AuthConfigs: authConfigs,
}
Expand Down Expand Up @@ -332,18 +332,10 @@ func marshalCachedImages(img Image, b resource.PropertyValue) []string {
if c.IsNull() {
return cacheImages
}
latest := img.Registry.Username + "/" + img.Name
// if we specify cacheFrom as True, we pull the latest build+push of our image implicitly, i.e. registry/image
if c.IsBool() {
useCache := c.BoolValue()
if useCache {
cacheImages = append(cacheImages, latest)
}
return cacheImages
}

// if we specify a list of stages, then we only pull those
cacheFrom := c.ObjectValue()
stages := cacheFrom["stages"].ArrayValue()
stages := cacheFrom["images"].ArrayValue()
for _, img := range stages {
stage := img.StringValue()
cacheImages = append(cacheImages, stage)
Expand Down Expand Up @@ -527,16 +519,21 @@ func processLogLine(msg string) (string, error) {
info += "failed to parse aux message: " + err.Error()
}
for _, vertex := range resp.Vertexes {
info += fmt.Sprintf("layer: %+v\n", vertex.Digest)
info += fmt.Sprintf("digest: %+v\n", vertex.Digest)
info += fmt.Sprintf("%s\n", vertex.Name)
if vertex.Error != "" {
info += fmt.Sprintf("error: %s\n", vertex.Error)
}
}
for _, status := range resp.Statuses {
info += fmt.Sprintf("status: %s\n", status.GetID())
info += fmt.Sprintf("%s\n", status.GetID())
}
for _, log := range resp.Logs {
info += fmt.Sprintf("log: %+v\n", log.GetMsg())
info += fmt.Sprintf("%s\n", string(log.Msg))

}
for _, warn := range resp.Warnings {
info += fmt.Sprintf("warning: %+v\n", warn.GetShort())
info += fmt.Sprintf("%s\n", string(warn.Short))
}

} else {
Expand Down
2 changes: 1 addition & 1 deletion provider/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func TestMarshalCachedImages(t *testing.T) {
"context": resource.NewStringProperty("/twilight/sparkle/bin"),

"cacheFrom": resource.NewObjectProperty(resource.PropertyMap{
"stages": resource.NewArrayProperty([]resource.PropertyValue{
"images": resource.NewArrayProperty([]resource.PropertyValue{
resource.NewStringProperty("apple"),
resource.NewStringProperty("banana"),
resource.NewStringProperty("cherry"),
Expand Down
17 changes: 5 additions & 12 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,9 @@ func Provider() tfbridge.ProviderInfo {
Default: "Dockerfile",
},
"cacheFrom": {
Description: "A cached image or list of build stages to use as build cache",
Description: "A list of images to use as build cache",
TypeSpec: schema.TypeSpec{
OneOf: []schema.TypeSpec{
{
Type: "boolean",
},
{
Ref: "#/types/docker:index/cacheFrom:CacheFrom",
},
},
Ref: "#/types/docker:index/cacheFrom:CacheFrom",
},
},
"env": {
Expand Down Expand Up @@ -211,10 +204,10 @@ func Provider() tfbridge.ProviderInfo {
dockerResource(dockerMod, "CacheFrom").String(): {
ObjectTypeSpec: schema.ObjectTypeSpec{
Type: "object",
Description: "Specifies information about where to obtain a cache",
Description: "Contains a list of images to reference when building using a cache",
Properties: map[string]schema.PropertySpec{
"stages": {
Description: "A list of cached build stages",
"images": {
Description: "Specifies cached images",
TypeSpec: schema.TypeSpec{
Type: "array",
Items: &schema.TypeSpec{
Expand Down
14 changes: 7 additions & 7 deletions sdk/dotnet/Inputs/CacheFromArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ namespace Pulumi.Docker.Inputs
{

/// <summary>
/// Specifies information about where to obtain a cache
/// Contains a list of images to reference when building using a cache
/// </summary>
public sealed class CacheFromArgs : global::Pulumi.ResourceArgs
{
[Input("stages")]
private InputList<string>? _stages;
[Input("images")]
private InputList<string>? _images;

/// <summary>
/// A list of cached build stages
/// Specifies cached images
/// </summary>
public InputList<string> Stages
public InputList<string> Images
{
get => _stages ?? (_stages = new InputList<string>());
set => _stages = value;
get => _images ?? (_images = new InputList<string>());
set => _images = value;
}

public CacheFromArgs()
Expand Down
4 changes: 2 additions & 2 deletions sdk/dotnet/Inputs/DockerBuildArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public InputMap<string> Args
public Input<Pulumi.Docker.BuilderVersion>? BuilderVersion { get; set; }

/// <summary>
/// A cached image or list of build stages to use as build cache
/// A list of images to use as build cache
/// </summary>
[Input("cacheFrom")]
public InputUnion<bool, Inputs.CacheFromArgs>? CacheFrom { get; set; }
public Input<Inputs.CacheFromArgs>? CacheFrom { get; set; }

/// <summary>
/// The path to the build context to use.
Expand Down
121 changes: 104 additions & 17 deletions sdk/go/docker/pulumiTypes.go

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

Loading