فهرست منبع

Merge pull request #211 from porter-dev/beta.3.fix-209

Beta.3.fix 209
abelanger5 5 سال پیش
والد
کامیت
f289f88b41

+ 36 - 1
cli/cmd/connect/ecr.go

@@ -4,11 +4,16 @@ import (
 	"context"
 	"fmt"
 	"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
@@ -50,6 +55,8 @@ Would you like to proceed? %s `,
 			return ecrManual(client, projectID, region)
 		}
 
+		waitForAuthorizationToken(region, creds)
+
 		integration, err := client.CreateAWSIntegration(
 			context.Background(),
 			projectID,
@@ -142,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")
+}

+ 2 - 0
internal/forms/integration.go

@@ -11,6 +11,7 @@ type CreateGCPIntegrationForm struct {
 	ProjectID    uint   `json:"project_id" form:"required"`
 	GCPKeyData   string `json:"gcp_key_data" form:"required"`
 	GCPProjectID string `json:"gcp_project_id"`
+	GCPRegion    string `json:"gcp_region"`
 }
 
 // ToGCPIntegration converts the project to a gorm project model
@@ -20,6 +21,7 @@ func (cgf *CreateGCPIntegrationForm) ToGCPIntegration() (*ints.GCPIntegration, e
 		ProjectID:    cgf.ProjectID,
 		GCPKeyData:   []byte(cgf.GCPKeyData),
 		GCPProjectID: cgf.GCPProjectID,
+		GCPRegion:    cgf.GCPRegion,
 	}, nil
 }
 

+ 30 - 0
internal/kubernetes/provisioner/gcp/gcp.go

@@ -0,0 +1,30 @@
+package gcp
+
+import (
+	v1 "k8s.io/api/core/v1"
+)
+
+// Conf wraps the GCP integration model
+type Conf struct {
+	GCPRegion, GCPProjectID, GCPKeyData string
+}
+
+// AttachGCPEnv adds the relevant AWS env for the provisioner
+func (conf *Conf) AttachGCPEnv(env []v1.EnvVar) []v1.EnvVar {
+	env = append(env, v1.EnvVar{
+		Name:  "GCP_REGION",
+		Value: conf.GCPRegion,
+	})
+
+	env = append(env, v1.EnvVar{
+		Name:  "GCP_CREDENTIALS",
+		Value: conf.GCPKeyData,
+	})
+
+	env = append(env, v1.EnvVar{
+		Name:  "GCP_PROJECT_ID",
+		Value: conf.GCPProjectID,
+	})
+
+	return env
+}

+ 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

+ 4 - 1
internal/models/integrations/gcp.go

@@ -19,11 +19,14 @@ type GCPIntegration struct {
 	ProjectID uint `json:"project_id"`
 
 	// The GCP project id where the service account for this auth mechanism persists
-	GCPProjectID string `json:"gcp-project-id"`
+	GCPProjectID string `json:"gcp_project_id"`
 
 	// The GCP user email that linked this service account
 	GCPUserEmail string `json:"gcp-user-email"`
 
+	// The GCP region, which may or may not be used by the integration
+	GCPRegion string `json:"gcp_region"`
+
 	// ------------------------------------------------------------------
 	// All fields encrypted before storage.
 	// ------------------------------------------------------------------