Quellcode durchsuchen

push GHA workflow in deploy request

Anukul Sangwan vor 4 Jahren
Ursprung
Commit
eb47dd8b99

+ 1 - 1
cli/cmd/api/domain.go

@@ -17,7 +17,7 @@ type CreateDNSRecordRequest struct {
 // CreateDNSRecordResponse is the DNS record that was created
 type CreateDNSRecordResponse models.DNSRecordExternal
 
-// CreateGithubAction creates a Github action with basic authentication
+// CreateDNSRecord creates a Github action with basic authentication
 func (c *Client) CreateDNSRecord(
 	ctx context.Context,
 	projectID, clusterID uint,

+ 20 - 38
dashboard/src/main/home/launch/launch-flow/LaunchFlow.tsx

@@ -53,47 +53,26 @@ const LaunchFlow: React.FC<PropsType> = (props) => {
   const [folderPath, setFolderPath] = useState(null);
   const [selectedRegistry, setSelectedRegistry] = useState(null);
 
-  const createGHAction = (chartName: string, chartNamespace: string) => {
-    let { currentProject, currentCluster, setCurrentError } = context;
-    let imageRepoUri = `${selectedRegistry.url}/${chartName}-${chartNamespace}`;
+  const getGHActionConfig = (chartName: string) => {
+    let imageRepoUri = `${selectedRegistry.url}/${chartName}-${selectedNamespace}`;
 
     // DockerHub registry integration is per repo
     if (selectedRegistry.service === "dockerhub") {
       imageRepoUri = selectedRegistry.url;
     }
 
-    api
-      .createGHAction(
-        "<token>",
-        {
-          git_repo: actionConfig.git_repo,
-          git_branch: branch,
-          registry_id: selectedRegistry.id,
-          dockerfile_path: dockerfilePath,
-          folder_path: folderPath,
-          image_repo_uri: imageRepoUri,
-          git_repo_id: actionConfig.git_repo_id,
-        },
-        {
-          project_id: currentProject.id,
-          CLUSTER_ID: currentCluster.id,
-          RELEASE_NAME: chartName,
-          RELEASE_NAMESPACE: chartNamespace,
-        }
-      )
-      .then((res) => console.log(""))
-      .catch((err) => {
-        let parsedErr =
-          err?.response?.data?.errors && err.response.data.errors[0];
-        err = parsedErr || err.message || JSON.stringify(err);
-
-        setSaveValuesStatus(`Could not create GitHub Action: ${err}`);
-
-        setCurrentError(err);
-      });
+    return {
+      git_repo: actionConfig.git_repo,
+      git_branch: branch,
+      registry_id: selectedRegistry.id,
+      dockerfile_path: dockerfilePath,
+      folder_path: folderPath,
+      image_repo_uri: imageRepoUri,
+      git_repo_id: actionConfig.git_repo_id,
+    };
   };
 
-  const onSubmitAddon = (wildcard?: any) => {
+  const handleSubmitAddon = (wildcard?: any) => {
     let { currentCluster, currentProject, setCurrentError } = context;
     let name = templateName || randomWords({ exactly: 3, join: "-" });
     setSaveValuesStatus("loading");
@@ -156,7 +135,7 @@ const LaunchFlow: React.FC<PropsType> = (props) => {
       });
   };
 
-  const onSubmit = async (rawValues: any) => {
+  const handleSubmit = async (rawValues: any) => {
     let { currentCluster, currentProject, setCurrentError } = context;
     let name = templateName || randomWords({ exactly: 3, join: "-" });
     setSaveValuesStatus("loading");
@@ -248,6 +227,11 @@ const LaunchFlow: React.FC<PropsType> = (props) => {
       }
     }
 
+    let githubActionConfig = null;
+    if (sourceType == "repo") {
+      githubActionConfig = getGHActionConfig(name);
+    }
+
     api
       .deployTemplate(
         "<token>",
@@ -258,6 +242,7 @@ const LaunchFlow: React.FC<PropsType> = (props) => {
           formValues: values,
           namespace: selectedNamespace,
           name,
+          githubActionConfig,
         },
         {
           id: currentProject.id,
@@ -268,9 +253,6 @@ const LaunchFlow: React.FC<PropsType> = (props) => {
         }
       )
       .then((res: any) => {
-        if (sourceType === "repo") {
-          createGHAction(name, selectedNamespace);
-        }
         // props.setCurrentView('cluster-dashboard');
         setSaveValuesStatus("successful");
         // redirect to dashboard with namespace
@@ -330,7 +312,7 @@ const LaunchFlow: React.FC<PropsType> = (props) => {
     // Display main (non-source) settings page
     return (
       <SettingsPage
-        onSubmit={currentTab === "porter" ? onSubmit : onSubmitAddon}
+        onSubmit={currentTab === "porter" ? handleSubmit : handleSubmitAddon}
         saveValuesStatus={saveValuesStatus}
         selectedNamespace={selectedNamespace}
         setSelectedNamespace={setSelectedNamespace}

+ 1 - 22
dashboard/src/shared/api.tsx

@@ -113,27 +113,6 @@ const createGCR = baseApi<
   return `/api/projects/${pathParams.project_id}/provision/gcr`;
 });
 
-const createGHAction = baseApi<
-  {
-    git_repo: string;
-    git_branch: string;
-    registry_id: number;
-    image_repo_uri: string;
-    dockerfile_path: string;
-    folder_path: string;
-    git_repo_id: number;
-  },
-  {
-    project_id: number;
-    CLUSTER_ID: number;
-    RELEASE_NAME: string;
-    RELEASE_NAMESPACE: string;
-  }
->("POST", (pathParams) => {
-  let { project_id, CLUSTER_ID, RELEASE_NAME, RELEASE_NAMESPACE } = pathParams;
-  return `/api/projects/${project_id}/ci/actions?cluster_id=${CLUSTER_ID}&name=${RELEASE_NAME}&namespace=${RELEASE_NAMESPACE}`;
-});
-
 const createGKE = baseApi<
   {
     gcp_integration_id: number;
@@ -275,6 +254,7 @@ const deployTemplate = baseApi<
     storage: StorageType;
     namespace: string;
     name: string;
+    githubActionConfig?: any;
   },
   {
     id: number;
@@ -1017,7 +997,6 @@ export default {
   createEmailVerification,
   createGCPIntegration,
   createGCR,
-  createGHAction,
   createGKE,
   createInvite,
   createNamespace,

+ 7 - 8
internal/forms/git_action.go

@@ -33,12 +33,11 @@ func (ca *CreateGitAction) ToGitActionConfig(version string) (*models.GitActionC
 }
 
 type CreateGitActionOptional struct {
-	GitRepo        string            `json:"git_repo"`
-	GitBranch      string            `json:"git_branch"`
-	ImageRepoURI   string            `json:"image_repo_uri"`
-	DockerfilePath string            `json:"dockerfile_path"`
-	FolderPath     string            `json:"folder_path"`
-	GitRepoID      uint              `json:"git_repo_id"`
-	BuildEnv       map[string]string `json:"env"`
-	RegistryID     uint              `json:"registry_id"`
+	GitRepo        string `json:"git_repo"`
+	GitBranch      string `json:"git_branch"`
+	ImageRepoURI   string `json:"image_repo_uri"`
+	DockerfilePath string `json:"dockerfile_path"`
+	FolderPath     string `json:"folder_path"`
+	GitRepoID      uint   `json:"git_repo_id"`
+	RegistryID     uint   `json:"registry_id"`
 }

+ 1 - 1
internal/forms/release.go

@@ -128,7 +128,7 @@ type InstallChartTemplateForm struct {
 	*ChartTemplateForm
 
 	// optional git action config
-	GithubActionConfig *CreateGitActionOptional `json:"github_action,omitempty"`
+	GithubActionConfig *CreateGitActionOptional `json:"githubActionConfig,omitempty"`
 }
 
 // UpdateImageForm represents the accepted values for updating a Helm release's image