Skip to content

Commit

Permalink
check if img is available
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Dec 19, 2023
1 parent 1dda76c commit c39518f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ const (

// Per https://github.com/hashicorp/waypoint/pull/1937/files
buildkitSessionSharedKey = ""

// NOTE: this regex only accounts for image builds with latest tag
// this will need to be changed whenever configuring labels on image builds is enabled
successfulImageBuildRegexStr = "{\"stream\":\"Successfully tagged (.+):latest\\\\n\"\\}"
)

type RestartPolicy string
Expand Down Expand Up @@ -1395,12 +1391,13 @@ func (manager *DockerManager) BuildImage(ctx context.Context, imageName string,
}
imageBuildResponseBodyStr := imageBuildResponseBuffer.String()

// ImageBuildResponse has no notion of success or error builds, so must manually parse the response body for error
isSuccessfulImageBuild, err := regexp.MatchString(successfulImageBuildRegexStr, imageBuildResponseBodyStr)
// ImageBuildResponse has no notion of success or error builds, so we check if the image is available locally and return the
// response body if it is not found
isImageAvailable, err := manager.isImageAvailableLocally(imageName)
if err != nil {
return "", stacktrace.NewError("An error occurred attempting to match successful image build regex '%v' with image build output:\n%v", successfulImageBuildRegexStr, imageBuildResponseBodyStr)
return "", stacktrace.Propagate(err, "Failed to check if '%v' was built and available locally.", imageName)
}
if !isSuccessfulImageBuild {
if !isImageAvailable {
return "", stacktrace.NewError("Image build for '%s' failed with the following output:\n%v", imageName, imageBuildResponseBodyStr)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package docker_manager

import (
"regexp"
"testing"

"github.com/docker/docker/api/types"
Expand Down Expand Up @@ -183,39 +182,3 @@ func TestBuildImage(t *testing.T) {
//_, err = dockerManager.BuildImage(ctx, "foobar", imageBuildSpec)
//require.NoError(t, err)
}

func TestSuccessfulImageBuildRegex(t *testing.T) {
imageBuildResponseBodyStr := `
{"id":"moby.buildkit.trace","aux":"Cm8KR3NoYTI1Njo3ZWFiZDFlODNlMWUwZmI1MDNjOWQ0MjdiNzFlNTQxY2VjODFkNDFiN2I0Mjk3NjhhMjdhZmYyM2VhNzRkMDZhGiRbaW50ZXJuYWxdIGxvYWQgcmVtb3RlIGJ1aWxkIGNvbnRleHQ="}
{"id":"moby.buildkit.trace","aux":"Cn0KR3NoYTI1Njo3ZWFiZDFlODNlMWUwZmI1MDNjOWQ0MjdiNzFlNTQxY2VjODFkNDFiN2I0Mjk3NjhhMjdhZmYyM2VhNzRkMDZhGiRbaW50ZXJuYWxdIGxvYWQgcmVtb3RlIGJ1aWxkIGNvbnRleHQqDAiF/ferBhCLzIGyAg=="}
{"stream":"Successfully tagged foobar:latest\n"}
`

successfulImageBuild, err := regexp.MatchString(successfulImageBuildRegexStr, imageBuildResponseBodyStr)
require.NoError(t, err)
require.True(t, successfulImageBuild)
}

func TestSuccessfulImageBuildRegexWithLongerImageName(t *testing.T) {
imageBuildResponseBodyStr := `
{"id":"moby.buildkit.trace","aux":"Cm8KR3NoYTI1Njo3ZWFiZDFlODNlMWUwZmI1MDNjOWQ0MjdiNzFlNTQxY2VjODFkNDFiN2I0Mjk3NjhhMjdhZmYyM2VhNzRkMDZhGiRbaW50ZXJuYWxdIGxvYWQgcmVtb3RlIGJ1aWxkIGNvbnRleHQ="}
{"id":"moby.buildkit.trace","aux":"Cn0KR3NoYTI1Njo3ZWFiZDFlODNlMWUwZmI1MDNjOWQ0MjdiNzFlNTQxY2VjODFkNDFiN2I0Mjk3NjhhMjdhZmYyM2VhNzRkMDZhGiRbaW50ZXJuYWxdIGxvYWQgcmVtb3RlIGJ1aWxkIGNvbnRleHQqDAiF/ferBhCLzIGyAg=="}
{"stream":"Successfully tagged kurtosis/backend-server:latest\n"}
`

successfulImageBuild, err := regexp.MatchString(successfulImageBuildRegexStr, imageBuildResponseBodyStr)
require.NoError(t, err)
require.True(t, successfulImageBuild)
}

func TestSuccessfulImageBuildRegexFailure(t *testing.T) {
imageBuildResponseBodyStr := `
{"id":"moby.buildkit.trace","aux":"Cm8KR3NoYTI1Njo4ZDZjNTBkZDU3ZGM1N2Y3YWFhN2ZkYTQ5NjFlMDc3YjYyYjJkMTIxYmRlM2RmZmEzYWI5MDJkOGI4NDc3NDE3GiRbaW50ZXJuYWxdIGxvYWQgcmVtb3RlIGJ1aWxkIGNvbnRleHQ="}
{"id":"moby.buildkit.trace","aux":"Cn0KR3NoYTI1Njo4ZDZjNTBkZDU3ZGM1N2Y3YWFhN2ZkYTQ5NjFlMDc3YjYyYjJkMTIxYmRlM2RmZmEzYWI5MDJkOGI4NDc3NDE3GiRbaW50ZXJuYWxdIGxvYWQgcmVtb3RlIGJ1aWxkIGNvbnRleHQqDAiu/PerBhCYsc3wAQ=="}
{"errorDetail":{"message":"failed to compute cache key: \"/kurtosis-cloud-admin-backend-server\" not found: not found"},"error":"failed to compute cache key: \"/kurtosis-cloud-admin-backend-server\" not found: not found"}
`

successfulImageBuild, err := regexp.MatchString(successfulImageBuildRegexStr, imageBuildResponseBodyStr)
require.NoError(t, err)
require.False(t, successfulImageBuild)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const (

ServiceNameArgName = "name"
ServiceConfigArgName = "config"

testRootModuleLocator = "./"
)

func NewAddService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/starlark_warning"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_errors"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages"
"github.com/sirupsen/logrus"
"go.starlark.net/starlark"
"math"
"path"
Expand Down Expand Up @@ -598,7 +597,6 @@ func convertImage(
if interpretationErr != nil {
return "", nil, interpretationErr
}
logrus.Debugf("CONVERT IMAGE ATTRIBUTE: %v %v", imageName, imageBuildSpec)
return imageName, imageBuildSpec, nil
} else {
imageName, interpretationErr := kurtosis_types.SafeCastToString(image, ImageAttr)
Expand Down

0 comments on commit c39518f

Please sign in to comment.