Jelajahi Sumber

Merge branch 'staging' of https://github.com/porter-dev/porter into beta.3.integration-frontend

jusrhee 5 tahun lalu
induk
melakukan
7a6bea0544

+ 0 - 0
.github/workflows/gcr.yaml → .github/workflows/staging.yaml


+ 1 - 1
README.md

@@ -1,5 +1,5 @@
 # Porter 
-[![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://github.com/tterb/atomic-design-ui/blob/master/LICENSEs) [![Go Report Card](https://goreportcard.com/badge/gojp/goreportcard)](https://goreportcard.com/report/gojp/goreportcard)
+[![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://github.com/tterb/atomic-design-ui/blob/master/LICENSEs) [![Go Report Card](https://goreportcard.com/badge/gojp/goreportcard)](https://goreportcard.com/report/github.com/porter-dev/porter)
 
 **Porter is a Kubernetes-powered PaaS that runs in your own cloud provider.** Porter brings the Heroku experience to Kubernetes without compromising its flexibility. Get started on Porter without the overhead of DevOps and fully customize your infra later when you need to.
 

+ 1 - 0
cmd/app/main.go

@@ -87,6 +87,7 @@ func main() {
 		Repository: repo,
 		ServerConf: appConf.Server,
 		RedisConf:  &appConf.Redis,
+		DBConf:     appConf.Db,
 	})
 
 	appRouter := router.New(a)

+ 1 - 0
dashboard/src/main/home/new-project/NewProject.tsx

@@ -323,6 +323,7 @@ export default class NewProject extends Component<PropsType, StateType> {
 
           if (this.state.selectedProvider === 'aws') {
             this.provisionECR(proj, this.provisionEKS)
+
           } else {
             this.props.setCurrentView('dashboard', null);
           }

+ 84 - 78
dashboard/src/main/home/new-project/Provisioner.tsx

@@ -49,99 +49,102 @@ export default class Provisioner extends Component<PropsType, StateType> {
     return true;
   }
 
-  componentDidMount() {
-    let { currentProject } = this.context;
-    let protocol = process.env.NODE_ENV == 'production' ? 'wss' : 'ws'
-    let viewData = this.props.viewData || []
+  setupWebsocket = (ws: WebSocket, infra: any) => {
+    ws.onopen = () => {
+      console.log('connected to websocket')
+    }
 
-    let websockets = viewData.map((infra: any) => {
-      let ws = new WebSocket(`${protocol}://${process.env.API_SERVER}/api/projects/${currentProject.id}/provision/${infra.kind}/${infra.infra_id}/logs`)
+    ws.onmessage = (evt: MessageEvent) => {
+      let event = JSON.parse(evt.data);
+      let validEvents = [] as any[];
+      let err = null;
       
-      ws.onopen = () => {
-        console.log('connected to websocket')
-      }
+      for (var i = 0; i < event.length; i++) {
+        let msg = event[i];
+        if (msg["Values"] && msg["Values"]["data"] && this.isJSON(msg["Values"]["data"])) { 
+          let d = JSON.parse(msg["Values"]["data"]);
+
+          if (d["kind"] == "error") {
+            err = d["log"];
+            break;
+          }
 
-      ws.onmessage = (evt: MessageEvent) => {
-        let event = JSON.parse(evt.data);
-        let validEvents = [] as any[];
-        let err = null;
-        
-        for (var i = 0; i < event.length; i++) {
-          let msg = event[i];
-          if (msg["Values"] && msg["Values"]["data"] && this.isJSON(msg["Values"]["data"])) { 
-            let d = JSON.parse(msg["Values"]["data"]);
-  
-            if (d["kind"] == "error") {
-              err = d["log"];
-              break;
-            }
-  
-            // add only valid events
-            if (d["log"] != null && d["created_resources"] != null && d["total_resources"] != null) {
-              validEvents.push(d);
-            }
+          // add only valid events
+          if (d["log"] != null && d["created_resources"] != null && d["total_resources"] != null) {
+            validEvents.push(d);
           }
         }
-  
-        if (err) {
-          let e = ansiparse(err).map((el: any) => {
-            return el.text;
-          })
-          this.setState({ logs: e, error: true });
-          return;
-        }
-  
-        if (validEvents.length == 0) {
-          return;
-        }
-        
-        if (!this.state.maxStep[infra.kind] || !this.state.maxStep[infra.kind]["total_resources"]) {
-          this.setState({
-            maxStep: {
-              ...this.state.maxStep,
-              [infra.kind] : validEvents[validEvents.length - 1]["total_resources"]
-            }
-          })
-        }
-        
-        let logs = [] as any[]
-        validEvents.forEach((e: any) => {
-          logs.push(...ansiparse(e["log"]))
-        })
+      }
 
-        logs = logs.map((log: any) => {
-          return log.text
-        })
-  
-        this.setState({ 
-          logs: [...this.state.logs, ...logs], 
-          currentStep: {
-            ...this.state.currentStep,
-            [infra.kind] : validEvents[validEvents.length - 1]["created_resources"]
-          },
-        }, () => {
-          this.scrollToBottom()
+      if (err) {
+        let e = ansiparse(err).map((el: any) => {
+          return el.text;
         })
+        this.setState({ logs: e, error: true });
+        return;
       }
 
-      ws.onerror = (err: ErrorEvent) => {
-        console.log(err)
+      if (validEvents.length == 0) {
+        return;
       }
-
-      ws.onclose = () => {
-        console.log('closing provisioner websocket')
+      
+      if (!this.state.maxStep[infra.kind] || !this.state.maxStep[infra.kind]["total_resources"]) {
+        this.setState({
+          maxStep: {
+            ...this.state.maxStep,
+            [infra.kind] : validEvents[validEvents.length - 1]["total_resources"]
+          }
+        })
       }
+      
+      let logs = [] as any[]
+      validEvents.forEach((e: any) => {
+        logs.push(...ansiparse(e["log"]))
+      })
+
+      logs = logs.map((log: any) => {
+        return log.text
+      })
+
+      this.setState({ 
+        logs: [...this.state.logs, ...logs], 
+        currentStep: {
+          ...this.state.currentStep,
+          [infra.kind] : validEvents[validEvents.length - 1]["created_resources"]
+        },
+      }, () => {
+        this.scrollToBottom()
+      })
+    }
 
-      return ws
+    ws.onerror = (err: ErrorEvent) => {
+      console.log(err)
+    }
+
+    ws.onclose = () => {
+      console.log('closing provisioner websocket')
+    }
+
+    return ws
+  }
+
+  componentDidMount() {
+    let { currentProject } = this.context;
+    let protocol = process.env.NODE_ENV == 'production' ? 'wss' : 'ws'
+    let viewData = this.props.viewData || []
+
+    let websockets = viewData.map((infra: any) => {
+      let ws = new WebSocket(`${protocol}://${process.env.API_SERVER}/api/projects/${currentProject.id}/provision/${infra.kind}/${infra.infra_id}/logs`)
+      return this.setupWebsocket(ws, infra)
     });
 
-    this.setState({ websockets, logs: [] });
+    this.setState({ websockets, logs: ["Provisioning EKS cluster and ECR registry..."] });
   }
 
   componentWillUnmount() {
     if (!this.state.websockets) { return; }
 
-    this.state.websockets.forEach((ws) => {
+    this.state.websockets.forEach((ws: any) => {
       ws.close()
     })
   }
@@ -211,15 +214,18 @@ export default class Provisioner extends Component<PropsType, StateType> {
     let currentStep = 0;
 
     for (let key in this.state.maxStep) {
-      console.log(key)
-      maxStep += this.state.maxStep[key]
+      if (key == 'eks') {
+        maxStep += this.state.maxStep[key]
+      }
     }
 
     for (let key in this.state.currentStep) {
-      currentStep += this.state.currentStep[key]
+      if (key == 'eks') {
+        currentStep += this.state.currentStep[key]
+      }
     }
 
-    if (true && !this.state.triggerEnd) {
+    if (maxStep !== 0 && currentStep === maxStep && !this.state.triggerEnd) {
       this.onEnd()
       this.setState({ triggerEnd: true });
     }

+ 14 - 11
internal/kubernetes/agent.go

@@ -7,7 +7,6 @@ import (
 	"io"
 	"strings"
 
-	"github.com/porter-dev/porter/internal/config"
 	"github.com/porter-dev/porter/internal/kubernetes/provisioner"
 	"github.com/porter-dev/porter/internal/kubernetes/provisioner/aws"
 	"github.com/porter-dev/porter/internal/kubernetes/provisioner/aws/ecr"
@@ -26,6 +25,8 @@ import (
 	"k8s.io/client-go/informers"
 	"k8s.io/client-go/kubernetes"
 	"k8s.io/client-go/tools/cache"
+
+	"github.com/porter-dev/porter/internal/config"
 )
 
 // Agent is a Kubernetes agent for performing operations that interact with the
@@ -240,6 +241,8 @@ func (a *Agent) ProvisionECR(
 	ecrName string,
 	awsInfra *models.AWSInfra,
 	operation provisioner.ProvisionerOperation,
+	pgConf *config.DBConf,
+	redisConf *config.RedisConf,
 ) (*batchv1.Job, error) {
 	id := awsInfra.GetID()
 	prov := &provisioner.Conf{
@@ -247,6 +250,8 @@ func (a *Agent) ProvisionECR(
 		Name:      fmt.Sprintf("prov-%s-%s", id, string(operation)),
 		Kind:      provisioner.ECR,
 		Operation: operation,
+		Redis:     redisConf,
+		Postgres:  pgConf,
 		AWS: &aws.Conf{
 			AWSRegion:          awsConf.AWSRegion,
 			AWSAccessKeyID:     string(awsConf.AWSAccessKeyID),
@@ -267,6 +272,8 @@ func (a *Agent) ProvisionEKS(
 	eksName string,
 	awsInfra *models.AWSInfra,
 	operation provisioner.ProvisionerOperation,
+	pgConf *config.DBConf,
+	redisConf *config.RedisConf,
 ) (*batchv1.Job, error) {
 	id := awsInfra.GetID()
 	prov := &provisioner.Conf{
@@ -274,6 +281,8 @@ func (a *Agent) ProvisionEKS(
 		Name:      fmt.Sprintf("prov-%s-%s", id, string(operation)),
 		Kind:      provisioner.EKS,
 		Operation: provisioner.Apply,
+		Redis:     redisConf,
+		Postgres:  pgConf,
 		AWS: &aws.Conf{
 			AWSRegion:          awsConf.AWSRegion,
 			AWSAccessKeyID:     string(awsConf.AWSAccessKeyID),
@@ -291,12 +300,16 @@ func (a *Agent) ProvisionEKS(
 func (a *Agent) ProvisionTest(
 	projectID uint,
 	operation provisioner.ProvisionerOperation,
+	pgConf *config.DBConf,
+	redisConf *config.RedisConf,
 ) (*batchv1.Job, error) {
 	prov := &provisioner.Conf{
 		ID:        fmt.Sprintf("%s-%d", "testing", projectID),
 		Name:      fmt.Sprintf("prov-%s-%d-%s", "testing", projectID, string(operation)),
 		Operation: provisioner.Apply,
 		Kind:      provisioner.Test,
+		Redis:     redisConf,
+		Postgres:  pgConf,
 	}
 
 	return a.provision(prov)
@@ -307,16 +320,6 @@ func (a *Agent) provision(
 ) (*batchv1.Job, error) {
 	prov.Namespace = "default"
 
-	prov.Redis = &config.RedisConf{
-		Host: "redis-master.default.svc.cluster.local",
-		Port: "6379",
-	}
-
-	prov.Postgres = &provisioner.PostgresConf{
-		Host: "postgres-postgresql.default.svc.cluster.local",
-		Port: "5432",
-	}
-
 	job, err := prov.GetProvisionerJobTemplate()
 
 	if err != nil {

+ 18 - 28
internal/kubernetes/provisioner/provisioner.go

@@ -1,6 +1,8 @@
 package provisioner
 
 import (
+	"fmt"
+
 	batchv1 "k8s.io/api/batch/v1"
 	v1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -29,7 +31,7 @@ type Conf struct {
 	Namespace string
 	ID        string
 	Redis     *config.RedisConf
-	Postgres  *PostgresConf
+	Postgres  *config.DBConf
 	Operation ProvisionerOperation
 
 	// provider-specific configurations
@@ -38,12 +40,6 @@ type Conf struct {
 	EKS *eks.Conf
 }
 
-// PostgresConf is the postgres config for the provisioner container
-type PostgresConf struct {
-	Host string
-	Port string
-}
-
 type ProvisionerOperation string
 
 const (
@@ -170,19 +166,20 @@ func (conf *Conf) addRedisEnv(env []v1.EnvVar) []v1.EnvVar {
 
 	env = append(env, v1.EnvVar{
 		Name:  "REDIS_USER",
-		Value: "default",
+		Value: conf.Redis.Username,
 	})
 
 	env = append(env, v1.EnvVar{
-		Name: "REDIS_PASS",
-		ValueFrom: &v1.EnvVarSource{
-			SecretKeyRef: &v1.SecretKeySelector{
-				LocalObjectReference: v1.LocalObjectReference{
-					Name: "redis",
-				},
-				Key: "redis-password",
-			},
-		},
+		Name:  "REDIS_PASS",
+		Value: conf.Redis.Password,
+		// ValueFrom: &v1.EnvVarSource{
+		// 	SecretKeyRef: &v1.SecretKeySelector{
+		// 		LocalObjectReference: v1.LocalObjectReference{
+		// 			Name: "redis",
+		// 		},
+		// 		Key: "redis-password",
+		// 	},
+		// },
 	})
 
 	env = append(env, v1.EnvVar{
@@ -202,24 +199,17 @@ func (conf *Conf) addPostgresEnv(env []v1.EnvVar) []v1.EnvVar {
 
 	env = append(env, v1.EnvVar{
 		Name:  "PG_PORT",
-		Value: conf.Postgres.Port,
+		Value: fmt.Sprintf("%d", conf.Postgres.Port),
 	})
 
 	env = append(env, v1.EnvVar{
 		Name:  "PG_USER",
-		Value: "postgres",
+		Value: conf.Postgres.Username,
 	})
 
 	env = append(env, v1.EnvVar{
-		Name: "PG_PASS",
-		ValueFrom: &v1.EnvVarSource{
-			SecretKeyRef: &v1.SecretKeySelector{
-				LocalObjectReference: v1.LocalObjectReference{
-					Name: "postgres-postgresql",
-				},
-				Key: "postgresql-password",
-			},
-		},
+		Name:  "PG_PASS",
+		Value: conf.Postgres.Password,
 	})
 
 	return env

File diff ditekan karena terlalu besar
+ 0 - 6
prov.yaml


+ 5 - 0
server/api/api.go

@@ -37,6 +37,7 @@ type AppConfig struct {
 	Repository *repository.Repository
 	ServerConf config.ServerConf
 	RedisConf  *config.RedisConf
+	DBConf     config.DBConf
 
 	// TestAgents if API is in testing mode
 	TestAgents *TestAgents
@@ -63,6 +64,9 @@ type App struct {
 	// redis client for redis connection
 	RedisConf *config.RedisConf
 
+	// config for db
+	DBConf config.DBConf
+
 	// oauth-specific clients
 	GithubConf *oauth2.Config
 
@@ -89,6 +93,7 @@ func New(conf *AppConfig) (*App, error) {
 		Repo:       conf.Repository,
 		ServerConf: conf.ServerConf,
 		RedisConf:  conf.RedisConf,
+		DBConf:     conf.DBConf,
 		TestAgents: conf.TestAgents,
 		db:         conf.DB,
 		validator:  validator,

+ 14 - 1
server/api/provision_handler.go

@@ -33,7 +33,12 @@ func (app *App) HandleProvisionTest(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	_, err = agent.ProvisionTest(uint(projID), provisioner.Apply)
+	_, err = agent.ProvisionTest(
+		uint(projID),
+		provisioner.Apply,
+		&app.DBConf,
+		app.RedisConf,
+	)
 
 	if err != nil {
 		app.handleErrorInternal(err, w)
@@ -111,6 +116,8 @@ func (app *App) HandleProvisionAWSECRInfra(w http.ResponseWriter, r *http.Reques
 		form.ECRName,
 		infra,
 		provisioner.Apply,
+		&app.DBConf,
+		app.RedisConf,
 	)
 
 	if err != nil {
@@ -199,6 +206,8 @@ func (app *App) HandleDestroyAWSECRInfra(w http.ResponseWriter, r *http.Request)
 		form.ECRName,
 		infra,
 		provisioner.Destroy,
+		&app.DBConf,
+		app.RedisConf,
 	)
 
 	if err != nil {
@@ -279,6 +288,8 @@ func (app *App) HandleProvisionAWSEKSInfra(w http.ResponseWriter, r *http.Reques
 		form.EKSName,
 		infra,
 		provisioner.Apply,
+		&app.DBConf,
+		app.RedisConf,
 	)
 
 	if err != nil {
@@ -367,6 +378,8 @@ func (app *App) HandleDestroyAWSEKSInfra(w http.ResponseWriter, r *http.Request)
 		form.EKSName,
 		infra,
 		provisioner.Destroy,
+		&app.DBConf,
+		app.RedisConf,
 	)
 
 	if err != nil {

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini