Просмотр исходного кода

call subdomain endpoint for deploy template

Alexander Belanger 5 лет назад
Родитель
Сommit
441eabf1e2

+ 31 - 2
dashboard/src/main/home/launch/expanded-template/LaunchTemplate.tsx

@@ -175,14 +175,14 @@ class LaunchTemplate extends Component<PropsType, StateType> {
       });
   };
 
-  onSubmit = (rawValues: any) => {
+  onSubmit = async (rawValues: any) => {
     let { currentCluster, currentProject } = this.context;
     let name =
       this.state.templateName || randomWords({ exactly: 3, join: "-" });
     this.setState({ saveValuesStatus: "loading" });
 
     // Convert dotted keys to nested objects
-    let values = {};
+    let values : any = {};
     for (let key in rawValues) {
       _.set(values, key, rawValues[key]);
     }
@@ -225,6 +225,35 @@ class LaunchTemplate extends Component<PropsType, StateType> {
     }
 
     _.set(values, "ingress.provider", provider);
+    var url : string
+
+    // check if template is docker and create external domain if necessary
+    if (this.props.currentTemplate.name == "web") {
+      if (values?.ingress?.enabled && values?.ingress?.hosts?.length == 0) {
+        url = await new Promise((resolve, reject) => {
+          api.createSubdomain(
+            "<token>",
+            {
+              release_name: this.props.currentTemplate.name.toLowerCase().trim(),
+            },
+            {
+              id: currentProject.id,
+              cluster_id: currentCluster.id,
+            }
+          ).then((res) => {
+            resolve(res.data?.external_url)
+          })
+          .catch((err) => {
+            this.setState({ saveValuesStatus: "error" });
+          });
+        })
+
+        values.ingress.hosts = [url]
+        values.ingress.custom_domain = true
+      }
+    }
+
+    console.log("VALUES ARE", values)
 
     api
       .deployTemplate(

+ 15 - 0
dashboard/src/shared/api.tsx

@@ -143,6 +143,20 @@ const createProject = baseApi<{ name: string }, {}>("POST", (pathParams) => {
   return `/api/projects`;
 });
 
+const createSubdomain = baseApi<
+  {
+    release_name: string;
+  },
+  {
+    id: number;
+    cluster_id: number;
+  }
+>("POST", (pathParams) => {
+  let { cluster_id, id } = pathParams;
+
+  return `/api/projects/${id}/k8s/subdomain?cluster_id=${cluster_id}`;
+});
+
 const deleteCluster = baseApi<
   {},
   {
@@ -620,6 +634,7 @@ export default {
   deleteCluster,
   deleteInvite,
   deleteProject,
+  createSubdomain,
   deployTemplate,
   destroyEKS,
   destroyGKE,

+ 1 - 1
internal/config/config.go

@@ -29,7 +29,7 @@ type ServerConf struct {
 	TimeoutIdle          time.Duration `env:"SERVER_TIMEOUT_IDLE,default=15s"`
 	IsLocal              bool          `env:"IS_LOCAL,default=false"`
 	IsTesting            bool          `env:"IS_TESTING,default=false"`
-	AppRootDomain        string        `env:"APP_ROOT_DOMAIN"`
+	AppRootDomain        string        `env:"APP_ROOT_DOMAIN,default=porter.run"`
 
 	DefaultHelmRepoURL string `env:"HELM_REPO_URL,default=https://porter-dev.github.io/chart-repo/"`