Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #808 from hashicorp/backport/cloud-run-ar-patch/he…
Browse files Browse the repository at this point in the history
…avily-enjoyed-cat

Backport of Fix waypoint to work with Artifact Registry into release/0.1.x
  • Loading branch information
mitchellh authored Nov 16, 2020
2 parents 7a96f4c + 94ddac8 commit 8a07f8d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion builtin/google/cloudrun/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (p *Platform) Deploy(

// Validate that the Docker image is stored in a GCP registry
// It is not possible to deploy to Cloud Run using external container registries
err = validateImageName(img.Image, p.config.Project)
err = validateImageName(img.Image)
if err != nil {
return nil, status.Error(codes.FailedPrecondition, err.Error())
}
Expand Down
12 changes: 11 additions & 1 deletion builtin/google/cloudrun/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cloudrun

import (
"fmt"
"regexp"
"strings"

"github.com/go-playground/validator"
Expand All @@ -10,7 +11,7 @@ import (

// ValidateImageName validates that that the specified image is in the gcr Docker Registry for this project
// Returns an error message when validation fails.
func validateImageName(image string, project string) error {
func validateImageName(image string) error {
// cloud run deployments must come from one of the following image registries
var validRegistries = []string{
"gcr.io",
Expand All @@ -26,6 +27,15 @@ func validateImageName(image string, project string) error {
registryValid = true
break
}

// Also check if a valid Artifact Registry was supplied which is LOCATION-docker.pkg.dev
parts := regexp.MustCompile(`([a-z0-9-]*)-docker\.pkg\.dev`).FindStringSubmatch(image)
if len(parts) > 1 {
if parts[1] != "" {
registryValid = true
}
}

}

if !registryValid {
Expand Down
14 changes: 12 additions & 2 deletions builtin/google/cloudrun/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ import (
)

func TestValidateImageReturnsErrorOnInvalidImageName(t *testing.T) {
err := validateImageName("foo", "proj")
err := validateImageName("foo")
require.Error(t, err)
}

func TestValidateImageReturnsErrorOnInvalidRegistry(t *testing.T) {
err := validateImageName("foo/proj/image", "proj")
err := validateImageName("foo/proj/image")
require.Error(t, err)
}

func TestValidateImageReturnsErrorOnInvalidArtifactRegistry(t *testing.T) {
err := validateImageName("FOO-docker.pkg.dev/waypoint-286812/foo/bar")
require.Error(t, err)
}

func TestValidateImageReturnsNoErrorOnValidArtifactRegistry(t *testing.T) {
err := validateImageName("europe-north1-docker.pkg.dev/waypoint-286812/foo/bar")
require.NoError(t, err)
}

var locations = []*run.Location{
{LocationId: "asia-east1"},
{LocationId: "asia-northeast1"},
Expand Down

0 comments on commit 8a07f8d

Please sign in to comment.