|
|
@@ -35,6 +35,7 @@ import {
|
|
|
FullGithubActionConfigType,
|
|
|
GithubActionConfigType,
|
|
|
} from "shared/types";
|
|
|
+import Error from "components/porter/Error";
|
|
|
import { z } from "zod";
|
|
|
import { AppsSchema, EnvSchema, PorterYamlSchema } from "./schema";
|
|
|
import { Service } from "./serviceTypes";
|
|
|
@@ -87,7 +88,8 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
|
|
|
const [imageUrl, setImageUrl] = useState("");
|
|
|
const [imageTag, setImageTag] = useState("latest");
|
|
|
const { currentCluster, currentProject } = useContext(Context);
|
|
|
- const [isLoading, setIsLoading] = useState<boolean>(true);
|
|
|
+ const [deploying, setDeploying] = useState<boolean>(false);
|
|
|
+ const [deploymentError, setDeploymentError] = useState<string | undefined>(undefined);
|
|
|
const [currentStep, setCurrentStep] = useState<number>(0);
|
|
|
const [existingStep, setExistingStep] = useState<number>(0);
|
|
|
const [formState, setFormState] = useState<FormState>(INITIAL_STATE);
|
|
|
@@ -183,6 +185,8 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
|
|
|
|
|
|
const deployPorterApp = async () => {
|
|
|
try {
|
|
|
+ setDeploying(true);
|
|
|
+ setDeploymentError(undefined);
|
|
|
if (currentProject == null || currentCluster == null || currentProject.id == null || currentCluster.id == null) {
|
|
|
throw new Error("Project or cluster not found");
|
|
|
}
|
|
|
@@ -198,41 +202,47 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
|
|
|
}
|
|
|
} : {}
|
|
|
|
|
|
- // write to the db + deploy
|
|
|
- await Promise.all([
|
|
|
- api.createPorterApp(
|
|
|
- "<token>",
|
|
|
- {
|
|
|
- name: formState.applicationName,
|
|
|
- repo_name: actionConfig.git_repo,
|
|
|
- git_branch: branch,
|
|
|
- build_context: folderPath,
|
|
|
- builder: (buildConfig as any)?.builder,
|
|
|
- buildpacks: (buildConfig as any)?.buildpacks.join(",") ?? "",
|
|
|
- dockerfile: dockerfilePath,
|
|
|
- image_repo_uri: imageUrl,
|
|
|
- },
|
|
|
- {
|
|
|
- cluster_id: currentCluster.id,
|
|
|
- project_id: currentProject.id,
|
|
|
- }
|
|
|
- ),
|
|
|
- api.updatePorterStack(
|
|
|
- "<token>",
|
|
|
- {
|
|
|
- stack_name: formState.applicationName,
|
|
|
- porter_yaml: base64Encoded,
|
|
|
- ...imageInfo,
|
|
|
- },
|
|
|
- {
|
|
|
- cluster_id: currentCluster.id,
|
|
|
- project_id: currentProject.id,
|
|
|
- }
|
|
|
- ),
|
|
|
- ])
|
|
|
+ // write to the db
|
|
|
+ await api.createPorterApp(
|
|
|
+ "<token>",
|
|
|
+ {
|
|
|
+ name: formState.applicationName,
|
|
|
+ repo_name: actionConfig.git_repo,
|
|
|
+ git_branch: branch,
|
|
|
+ build_context: folderPath,
|
|
|
+ builder: (buildConfig as any)?.builder,
|
|
|
+ buildpacks: (buildConfig as any)?.buildpacks.join(",") ?? "",
|
|
|
+ dockerfile: dockerfilePath,
|
|
|
+ image_repo_uri: imageUrl,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ cluster_id: currentCluster.id,
|
|
|
+ project_id: currentProject.id,
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ // deploy dummy chart
|
|
|
+ await api.updatePorterStack(
|
|
|
+ "<token>",
|
|
|
+ {
|
|
|
+ stack_name: formState.applicationName,
|
|
|
+ porter_yaml: base64Encoded,
|
|
|
+ ...imageInfo,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ cluster_id: currentCluster.id,
|
|
|
+ project_id: currentProject.id,
|
|
|
+ }
|
|
|
+ );
|
|
|
+ return true;
|
|
|
} catch (err) {
|
|
|
// TODO: better error handling
|
|
|
console.log(err);
|
|
|
+ const errMessage = err?.response?.data?.error ?? err?.toString() ?? 'An error occurred while deploying your app. Please try again.'
|
|
|
+ setDeploymentError(errMessage);
|
|
|
+ return false;
|
|
|
+ } finally {
|
|
|
+ setDeploying(false);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -434,9 +444,15 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
|
|
|
if (imageUrl) {
|
|
|
deployPorterApp();
|
|
|
} else {
|
|
|
+ setDeploymentError(undefined)
|
|
|
setShowGHAModal(true);
|
|
|
}
|
|
|
}}
|
|
|
+ status={deploying ? "loading" : deploymentError ? (
|
|
|
+ <Error message={deploymentError} />
|
|
|
+ ) : undefined}
|
|
|
+ loadingText={"Deploying..."}
|
|
|
+ width={"150px"}
|
|
|
>
|
|
|
Deploy app
|
|
|
</Button>,
|
|
|
@@ -456,6 +472,7 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
|
|
|
projectId={currentProject.id}
|
|
|
clusterId={currentCluster.id}
|
|
|
deployPorterApp={deployPorterApp}
|
|
|
+ deploymentError={deploymentError}
|
|
|
/>
|
|
|
)}
|
|
|
</CenterWrapper>
|