Skip to content

Commit

Permalink
wip: add component redeploy step to install update
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-acosta committed Jun 20, 2024
1 parent 85d87f3 commit ef14445
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 20 deletions.
42 changes: 42 additions & 0 deletions app/[installer-slug]/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,45 @@ export async function reprovisionInstall(

return res.json();
}

export async function deployComponents(
id: string,
): Promise<Record<string, any>> {
const res = await fetch(
`${NUON_API_URL}/v1/installs/${id}/components/deploy-all`,
{
cache: "no-store",
headers: {
Authorization: `Bearer ${process?.env?.NUON_API_TOKEN}`,
"X-Nuon-Org-ID": process.env?.NUON_ORG_ID || "",
},
method: "POST",
},
);

if (!res.ok) {
console.debug(await res.json());
throw new Error("Can't fetch install");
}

return res.json();
}

export async function redeployInstall(
id: string,
app: Record<string, any>,
formData: FormData,
) {
const updateRes = await updateInstall(id, app, formData);
if (updateRes.error) {
return updateRes.json();
}

const reproRes = await reprovisionInstall(id);
if (reproRes.error) {
return reproRes.json();
}

const compRes = await deployComponents(id);
return await compRes.json();
}
6 changes: 2 additions & 4 deletions app/[installer-slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {
createInstall,
getInstall,
updateInstall,
reprovisionInstall,
redeployInstall,
} from "@/app/[installer-slug]/actions";
import { getAppBySlug, getInstaller } from "@/common";
import { Link } from "@/components";
Expand Down Expand Up @@ -46,8 +45,7 @@ export default async function Installer({ params, searchParams }) {
searchParams={searchParams}
createInstall={createInstall}
getInstall={getInstall}
updateInstall={updateInstall}
reprovisionInstall={reprovisionInstall}
redeployInstall={redeployInstall}
regions={regions}
/>
</main>
Expand Down
2 changes: 2 additions & 0 deletions app/[installer-slug]/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export function installRequestBody(
app: Record<string, any>,
formData: FormData,
) {
console.log("formData: ", formData);

const data = Object.fromEntries(formData);
const inputs = Object.keys(data).reduce(
(acc: Record<string, unknown>, key) => {
Expand Down
38 changes: 22 additions & 16 deletions components/InstallStepper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ const InstallStepper = ({
searchParams,
regions,
createInstall,
updateInstall,
getInstall,
reprovisionInstall,
redeployInstall,
}) => {
const [activeStep, setActiveStep] = React.useState(0);
const [isLastStep, setIsLastStep] = React.useState(false);
Expand Down Expand Up @@ -72,14 +71,8 @@ const InstallStepper = ({
}
installID = res.id;
} else {
// if we've already created the install, update it and reprovision
const updateRes = updateInstall(formData);
if (updateRes.error) {
setError(updateRes);
return;
}

const reproRes = reprovisionInstall(install.id);
// if we've already created the install, redeploy it
const reproRes = await redeployInstall(install.id, app, formData);
if (reproRes.error) {
setError(reproRes);
return;
Expand Down Expand Up @@ -308,12 +301,7 @@ const InstallStepper = ({

<div>
<InstallStatus install={install} />
<Button
type="submit"
className="block mr-0 ml-auto rounded text-sm text-gray-50 bg-primary-600 hover:bg-primary-700 focus:bg-primary-700 active:bg-primary-800 px-4 py-1.5 w-fit mt-4"
>
{install.id === "" ? "Create Install" : "Update Install"}
</Button>
<InstallButton install={install} />
</div>
</div>
</AccordionBody>
Expand All @@ -325,4 +313,22 @@ const InstallStepper = ({
);
};

const InstallButton = ({ install }) => {
const loading = install.status === "provisioning";

let label = "Create Install";
if (install.id.length > 0) label = "Update Install";
if (loading) label == "";

return (
<Button
loading={loading}
type="submit"
className="block mr-0 ml-auto rounded text-sm text-gray-50 bg-primary-600 hover:bg-primary-700 focus:bg-primary-700 active:bg-primary-800 px-4 py-1.5 w-fit mt-4"
>
{label}
</Button>
);
};

export default InstallStepper;

0 comments on commit ef14445

Please sign in to comment.