Skip to content

Commit

Permalink
chore: raise error when there is a multiplatform build without contai…
Browse files Browse the repository at this point in the history
…ner registry (#7786)

* chore: raise error when there is a multiplatform build without container registry

* chore: return actionable error when trying to build multi-platform image with local Docker daemon

* fix: PR comments

* fix: wrap actionable error to trigger the correct message

* fix: rebase against main and hack/generate-proto.sh run
  • Loading branch information
renzodavid9 committed Aug 22, 2022
1 parent 399ebac commit 0164731
Show file tree
Hide file tree
Showing 14 changed files with 499 additions and 378 deletions.
6 changes: 4 additions & 2 deletions docs-v2/content/en/api-v2/skaffold.swagger.json

Large diffs are not rendered by default.

45 changes: 30 additions & 15 deletions docs-v2/content/en/api/skaffold.swagger.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs-v2/content/en/docs/references/api-v2/grpc.md
Expand Up @@ -1095,6 +1095,7 @@ For Cancelled Error code, use range 800 to 850.<br>
| BUILD_GET_CLOUD_BUILD_CLIENT_ERR | 145 | GCB error to get cloud build client to perform GCB operations. |
| BUILD_UNKNOWN_PLATFORM_FLAG | 150 | Value provided to --platform flag cannot be parsed |
| BUILD_CROSS_PLATFORM_ERR | 151 | Cross-platform build failures |
| BUILD_CROSS_PLATFORM_NO_REGISTRY_ERR | 152 | Multi-platfor build fails due to no container registry set |
| STATUSCHECK_IMAGE_PULL_ERR | 300 | Container image pull error |
| STATUSCHECK_CONTAINER_CREATING | 301 | Container creating error |
| STATUSCHECK_RUN_CONTAINER_ERR | 302 | Container run error |
Expand Down Expand Up @@ -1266,6 +1267,7 @@ Enum for Suggestion codes
| SET_CLEANUP_FLAG | 116 | Set Cleanup flag for skaffold command. |
| BUILD_FIX_UNKNOWN_PLATFORM_FLAG | 117 | Check value provided to the `--platform` flag |
| BUILD_INSTALL_PLATFORM_EMULATORS | 118 | Check if QEMU platform emulators are installed |
| SET_PUSH_AND_CONTAINER_REGISTRY | 119 | Set --push and container registry to run a multi-platform build |
| CHECK_CLUSTER_CONNECTION | 201 | Check cluster connection |
| CHECK_MINIKUBE_STATUS | 202 | Check minikube status |
| INSTALL_HELM | 203 | Install helm tool |
Expand Down
2 changes: 2 additions & 0 deletions docs-v2/content/en/docs/references/api/grpc.md
Expand Up @@ -950,6 +950,7 @@ For Cancelled Error code, use range 800 to 850.<br>
| BUILD_GET_CLOUD_BUILD_CLIENT_ERR | 145 | GCB error to get cloud build client to perform GCB operations. |
| BUILD_UNKNOWN_PLATFORM_FLAG | 150 | Value provided to --platform flag cannot be parsed |
| BUILD_CROSS_PLATFORM_ERR | 151 | Cross-platform build failures |
| BUILD_CROSS_PLATFORM_NO_REGISTRY_ERR | 152 | Multi-platfor build fails due to no container registry set |
| STATUSCHECK_IMAGE_PULL_ERR | 300 | Container image pull error |
| STATUSCHECK_CONTAINER_CREATING | 301 | Container creating error |
| STATUSCHECK_RUN_CONTAINER_ERR | 302 | Container run error |
Expand Down Expand Up @@ -1121,6 +1122,7 @@ Enum for Suggestion codes
| SET_CLEANUP_FLAG | 116 | Set Cleanup flag for skaffold command. |
| BUILD_FIX_UNKNOWN_PLATFORM_FLAG | 117 | Check value provided to the `--platform` flag |
| BUILD_INSTALL_PLATFORM_EMULATORS | 118 | Check if QEMU platform emulators are installed |
| SET_PUSH_AND_CONTAINER_REGISTRY | 119 | Set --push and container registry to run a multi-platform build |
| CHECK_CLUSTER_CONNECTION | 201 | Check cluster connection |
| CHECK_MINIKUBE_STATUS | 202 | Check minikube status |
| INSTALL_HELM | 203 | Install helm tool |
Expand Down
6 changes: 4 additions & 2 deletions docs/content/en/api-v2/skaffold.swagger.json

Large diffs are not rendered by default.

45 changes: 30 additions & 15 deletions docs/content/en/api/skaffold.swagger.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/content/en/docs/references/api-v2/grpc.md
Expand Up @@ -1095,6 +1095,7 @@ For Cancelled Error code, use range 800 to 850.<br>
| BUILD_GET_CLOUD_BUILD_CLIENT_ERR | 145 | GCB error to get cloud build client to perform GCB operations. |
| BUILD_UNKNOWN_PLATFORM_FLAG | 150 | Value provided to --platform flag cannot be parsed |
| BUILD_CROSS_PLATFORM_ERR | 151 | Cross-platform build failures |
| BUILD_CROSS_PLATFORM_NO_REGISTRY_ERR | 152 | Multi-platfor build fails due to no container registry set |
| STATUSCHECK_IMAGE_PULL_ERR | 300 | Container image pull error |
| STATUSCHECK_CONTAINER_CREATING | 301 | Container creating error |
| STATUSCHECK_RUN_CONTAINER_ERR | 302 | Container run error |
Expand Down Expand Up @@ -1266,6 +1267,7 @@ Enum for Suggestion codes
| SET_CLEANUP_FLAG | 116 | Set Cleanup flag for skaffold command. |
| BUILD_FIX_UNKNOWN_PLATFORM_FLAG | 117 | Check value provided to the `--platform` flag |
| BUILD_INSTALL_PLATFORM_EMULATORS | 118 | Check if QEMU platform emulators are installed |
| SET_PUSH_AND_CONTAINER_REGISTRY | 119 | Set --push and container registry to run a multi-platform build |
| CHECK_CLUSTER_CONNECTION | 201 | Check cluster connection |
| CHECK_MINIKUBE_STATUS | 202 | Check minikube status |
| INSTALL_HELM | 203 | Install helm tool |
Expand Down
2 changes: 2 additions & 0 deletions docs/content/en/docs/references/api/grpc.md
Expand Up @@ -950,6 +950,7 @@ For Cancelled Error code, use range 800 to 850.<br>
| BUILD_GET_CLOUD_BUILD_CLIENT_ERR | 145 | GCB error to get cloud build client to perform GCB operations. |
| BUILD_UNKNOWN_PLATFORM_FLAG | 150 | Value provided to --platform flag cannot be parsed |
| BUILD_CROSS_PLATFORM_ERR | 151 | Cross-platform build failures |
| BUILD_CROSS_PLATFORM_NO_REGISTRY_ERR | 152 | Multi-platfor build fails due to no container registry set |
| STATUSCHECK_IMAGE_PULL_ERR | 300 | Container image pull error |
| STATUSCHECK_CONTAINER_CREATING | 301 | Container creating error |
| STATUSCHECK_RUN_CONTAINER_ERR | 302 | Container run error |
Expand Down Expand Up @@ -1121,6 +1122,7 @@ Enum for Suggestion codes
| SET_CLEANUP_FLAG | 116 | Set Cleanup flag for skaffold command. |
| BUILD_FIX_UNKNOWN_PLATFORM_FLAG | 117 | Check value provided to the `--platform` flag |
| BUILD_INSTALL_PLATFORM_EMULATORS | 118 | Check if QEMU platform emulators are installed |
| SET_PUSH_AND_CONTAINER_REGISTRY | 119 | Set --push and container registry to run a multi-platform build |
| CHECK_CLUSTER_CONNECTION | 201 | Check cluster connection |
| CHECK_MINIKUBE_STATUS | 202 | Check minikube status |
| INSTALL_HELM | 203 | Install helm tool |
Expand Down
22 changes: 22 additions & 0 deletions pkg/skaffold/build/builder_mux.go
Expand Up @@ -128,6 +128,11 @@ func (b *BuilderMux) Build(ctx context.Context, out io.Writer, tags tag.ImageTag
return built, nil
}

err := checkMultiplatformHaveRegistry(b, artifacts, resolver)
if err != nil {
return nil, fmt.Errorf("%w", err) // TODO: remove error wrapping after fixing #7790
}

ar, err := InOrder(ctx, out, tags, resolver, artifacts, builderF, b.concurrency, b.store)
if err != nil {
return nil, err
Expand Down Expand Up @@ -197,3 +202,20 @@ func getConcurrency(pbs []PipelineBuilder, cliConcurrency int) int {
log.Entry(ctx).Infof("final build concurrency value is %d", minConcurrency)
return minConcurrency
}

func checkMultiplatformHaveRegistry(b *BuilderMux, artifacts []*latest.Artifact, platforms platform.Resolver) error {
for _, artifact := range artifacts {
pb := b.byImageName[artifact.ImageName]
hasExternalRegistry := pb.PushImages()
pl, err := filterBuildEnvSupportedPlatforms(pb.SupportedPlatforms(), platforms.GetPlatforms(artifact.ImageName))
if err != nil {
return err
}

if pl.IsMultiPlatform() && !hasExternalRegistry {
return noRegistryForMultiplatformBuildErr(fmt.Errorf("multi-platform build requires pushing images to a valid container registry"))
}
}

return nil
}
36 changes: 36 additions & 0 deletions pkg/skaffold/build/errors.go
@@ -0,0 +1,36 @@
/*
Copyright 2022 The Skaffold Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package build

import (
sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
"github.com/GoogleContainerTools/skaffold/proto/v1"
)

func noRegistryForMultiplatformBuildErr(err error) error {
return sErrors.NewError(err,
&proto.ActionableErr{
Message: err.Error(),
ErrCode: proto.StatusCode_BUILD_CROSS_PLATFORM_NO_REGISTRY_ERR,
Suggestions: []*proto.Suggestion{
{
SuggestionCode: proto.SuggestionCode_SET_PUSH_AND_CONTAINER_REGISTRY,
Action: "To run multi-platform builds, set --push to true and set a container registry with --default-repo or in the global config",
},
},
})
}

0 comments on commit 0164731

Please sign in to comment.