瀏覽代碼

Merge branch 'stacks-v1' of github.com:porter-dev/porter into stacks-v1

Justin Rhee 3 年之前
父節點
當前提交
9acbc40612

+ 7 - 38
dashboard/src/main/home/app-dashboard/new-app-flow/NewAppFlow.tsx

@@ -186,40 +186,8 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
         throw new Error("Project or cluster not found");
       }
 
-      // create namespace first so we can create subdomain later if necessary
-      const res = await api
-        .getNamespaces(
-          "<token>",
-          {},
-          {
-            id: currentProject.id,
-            cluster_id: currentCluster.id,
-          }
-        )
-      if (res == null || res.data == null) {
-        throw new Error("Namespaces not found");
-      };
-      const stackNamespace = `porter-stack-${formState.applicationName}`;
-      // TODO: clean up types
-      const namespaceExistsAlready = res.data.some((namespace: any) => {
-        return namespace.name == stackNamespace;
-      })
-      if (!namespaceExistsAlready) {
-        await api
-          .createNamespace(
-            "<token>",
-            {
-              name: stackNamespace,
-            },
-            {
-              id: currentProject.id,
-              cluster_id: currentCluster.id,
-            }
-          );
-      }
-
       // validate form data
-      const finalPorterYaml = await createFinalPorterYaml();
+      const finalPorterYaml = createFinalPorterYaml();
       const yamlString = yaml.dump(finalPorterYaml);
       const base64Encoded = btoa(yamlString);
       const imageInfo = imageUrl ? {
@@ -283,12 +251,13 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
     return env;
   };
 
-  const createApps = async (serviceList: Service[]): Promise<z.infer<typeof AppsSchema>> => {
+  const createApps = (serviceList: Service[]): z.infer<typeof AppsSchema> => {
     const apps: z.infer<typeof AppsSchema> = {};
     for (const service of serviceList) {
       let config = Service.serialize(service);
-      if (Service.isWeb(service) && service.generateUrlForExternalTraffic) {
-        const ingress = await Service.handleWebIngress(service, formState.applicationName, currentCluster?.id, currentProject?.id);
+      // TODO: get rid of this block when we handle ingress on the backend
+      if (Service.isWeb(service)) {
+        const ingress = Service.handleWebIngress(service, formState.applicationName, currentCluster?.id, currentProject?.id);
         config = {
           ...config,
           ...ingress,
@@ -314,11 +283,11 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
     return apps;
   };
 
-  const createFinalPorterYaml = async (): Promise<z.infer<typeof PorterYamlSchema>> => {
+  const createFinalPorterYaml = (): z.infer<typeof PorterYamlSchema> => {
     return {
       version: "v1stack",
       env: combineEnv(formState.envVariables, porterJson?.env),
-      apps: await createApps(formState.serviceList),
+      apps: createApps(formState.serviceList),
     };
   };
 

+ 21 - 17
dashboard/src/main/home/app-dashboard/new-app-flow/serviceTypes.ts

@@ -85,7 +85,7 @@ const WebService = {
         generateUrlForExternalTraffic: false,
         customDomain: '',
     }),
-    serialize: async (service: WebService) => {
+    serialize: (service: WebService) => {
         const autoscaling = service.autoscalingOn ? {
             autoscaling: {
                 enabled: true,
@@ -171,10 +171,13 @@ export const Service = {
     isWeb: (service: Service): service is WebService => service.type === 'web',
     isWorker: (service: Service): service is WorkerService => service.type === 'worker',
     isJob: (service: Service): service is JobService => service.type === 'job',
-    handleWebIngress: async (service: WebService, stackName: string, projectId?: number, clusterId?: number) => {
+    handleWebIngress: (service: WebService, stackName: string, projectId?: number, clusterId?: number) => {
         if (projectId == null || clusterId == null) {
             throw new Error('Project ID and Cluster ID must be provided to handle web ingress');
         }
+        if (!service.generateUrlForExternalTraffic) {
+            return {}
+        }
         const ingress: Ingress = {
             enabled: true,
             hosts: [],
@@ -185,21 +188,22 @@ export const Service = {
             ingress.hosts.push(service.customDomain);
             ingress.custom_domain = true;
         } else {
-            const res = await api
-                .createSubdomain(
-                    "<token>",
-                    {},
-                    {
-                        id: projectId,
-                        cluster_id: clusterId,
-                        release_name: stackName,
-                        namespace: `porter-stack-${stackName}`,
-                    }
-                )
-            if (res == null || res.data == null || res.data.external_url == null) {
-                throw new Error('Failed to create subdomain for web service');
-            }
-            ingress.porter_hosts.push(res.data.external_url)
+            // const res = await api
+            //     .createSubdomain(
+            //         "<token>",
+            //         {},
+            //         {
+            //             id: projectId,
+            //             cluster_id: clusterId,
+            //             release_name: stackName,
+            //             namespace: `porter-stack-${stackName}`,
+            //         }
+            //     )
+            // if (res == null || res.data == null || res.data.external_url == null) {
+            //     throw new Error('Failed to create subdomain for web service');
+            // }
+            // ingress.porter_hosts.push(res.data.external_url)
+            throw new Error('Generating external URLs without custom subdomains not yet supported!');
         }
 
         return ingress;