Prechádzať zdrojové kódy

wait for ecr authorization token

Alexander Belanger 5 rokov pred
rodič
commit
31d9df8b8a

+ 34 - 3
cli/cmd/connect/ecr.go

@@ -6,10 +6,14 @@ import (
 	"strings"
 	"time"
 
+	"github.com/aws/aws-sdk-go/service/ecr"
 	"github.com/fatih/color"
 	"github.com/porter-dev/porter/cli/cmd/api"
-	awsLocal "github.com/porter-dev/porter/cli/cmd/providers/aws/local"
 	"github.com/porter-dev/porter/cli/cmd/utils"
+	"github.com/porter-dev/porter/internal/models/integrations"
+
+	"github.com/porter-dev/porter/cli/cmd/providers/aws"
+	awsLocal "github.com/porter-dev/porter/cli/cmd/providers/aws/local"
 )
 
 // ECR creates an ECR integration
@@ -51,8 +55,7 @@ Would you like to proceed? %s `,
 			return ecrManual(client, projectID, region)
 		}
 
-		// sleep for a few seconds to allow aws to reconfigure
-		time.Sleep(3 * time.Second)
+		waitForAuthorizationToken(region, creds)
 
 		integration, err := client.CreateAWSIntegration(
 			context.Background(),
@@ -146,3 +149,31 @@ func linkRegistry(client *api.Client, projectID uint, intID uint) (uint, error)
 
 	return reg.ID, nil
 }
+
+func waitForAuthorizationToken(region string, creds *aws.PorterAWSCredentials) error {
+	awsInt := &integrations.AWSIntegration{
+		AWSRegion:          region,
+		AWSAccessKeyID:     []byte(creds.AWSAccessKeyID),
+		AWSSecretAccessKey: []byte(creds.AWSSecretAccessKey),
+	}
+
+	sess, err := awsInt.GetSession()
+
+	if err != nil {
+		return err
+	}
+
+	ecrSvc := ecr.New(sess)
+
+	for i := 0; i < 30; i++ {
+		_, err := ecrSvc.GetAuthorizationToken(&ecr.GetAuthorizationTokenInput{})
+
+		if err == nil {
+			return nil
+		}
+
+		time.Sleep(2 * time.Second)
+	}
+
+	return fmt.Errorf("could not get ECR authorization token, please check credentials")
+}

+ 1 - 1
internal/kubernetes/provisioner/gcp/gcp.go

@@ -1,4 +1,4 @@
-package aws
+package gcp
 
 import (
 	v1 "k8s.io/api/core/v1"

+ 8 - 0
internal/kubernetes/provisioner/provisioner.go

@@ -11,6 +11,8 @@ import (
 	"github.com/porter-dev/porter/internal/kubernetes/provisioner/aws/ecr"
 	"github.com/porter-dev/porter/internal/kubernetes/provisioner/aws/eks"
 
+	"github.com/porter-dev/porter/internal/kubernetes/provisioner/gcp"
+
 	"github.com/porter-dev/porter/internal/config"
 )
 
@@ -22,6 +24,7 @@ const (
 	Test InfraOption = "test"
 	ECR  InfraOption = "ecr"
 	EKS  InfraOption = "eks"
+	GCR  InfraOption = "gcr"
 )
 
 // Conf is the config required to start a provisioner container
@@ -35,9 +38,14 @@ type Conf struct {
 	Operation ProvisionerOperation
 
 	// provider-specific configurations
+
+	// AWS
 	AWS *aws.Conf
 	ECR *ecr.Conf
 	EKS *eks.Conf
+
+	// GKE
+	GCP *gcp.Conf
 }
 
 type ProvisionerOperation string