Deploy to Dokku when the deploy button is clicked.

This commit is contained in:
James Murdza 2024-08-09 16:43:25 -07:00
parent d4c65ad1a3
commit 86db64a83b
3 changed files with 19 additions and 5 deletions

View File

@ -128,8 +128,8 @@ const client =
: null; : null;
client?.connect(); client?.connect();
const git = process.env.DOKKU_KEY ? new SecureGitClient( const git = process.env.DOKKU_HOST && process.env.DOKKU_KEY ? new SecureGitClient(
"dokku@gitwit.app", `dokku@${process.env.DOKKU_HOST}`,
process.env.DOKKU_KEY process.env.DOKKU_KEY
) : null; ) : null;

View File

@ -2,26 +2,30 @@
import { useState } from "react"; import { useState } from "react";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { useTerminal } from "@/context/TerminalContext";
import { Play, Pause } from "lucide-react"; import { Play, Pause } from "lucide-react";
export default function DeployButtonModal() { export default function DeployButtonModal() {
const { deploy } = useTerminal();
const [isDeploying, setIsDeploying] = useState(false); const [isDeploying, setIsDeploying] = useState(false);
const handleDeploy = () => { const handleDeploy = () => {
if (isDeploying) { if (isDeploying) {
console.log("Stopping deployment..."); console.log("Stopping deployment...");
} else { } else {
console.log("Starting deployment..."); console.log("Starting deployment...");
setIsDeploying(true);
deploy(() => {
setIsDeploying(false);
});
} }
setIsDeploying(!isDeploying);
}; };
return ( return (
<> <>
<Button variant="outline" onClick={handleDeploy}> <Button variant="outline" onClick={handleDeploy}>
{isDeploying ? <Pause className="w-4 h-4 mr-2" /> : <Play className="w-4 h-4 mr-2" />} {isDeploying ? <Pause className="w-4 h-4 mr-2" /> : <Play className="w-4 h-4 mr-2" />}
{isDeploying ? "Deployed" : "Deploy"} {isDeploying ? "Deploying" : "Deploy"}
</Button> </Button>
</> </>
); );

View File

@ -16,6 +16,7 @@ interface TerminalContextType {
createNewTerminal: (command?: string) => Promise<void>; createNewTerminal: (command?: string) => Promise<void>;
closeTerminal: (id: string) => void; closeTerminal: (id: string) => void;
setUserAndSandboxId: (userId: string, sandboxId: string) => void; setUserAndSandboxId: (userId: string, sandboxId: string) => void;
deploy: (callback: () => void) => void;
} }
const TerminalContext = createContext<TerminalContextType | undefined>(undefined); const TerminalContext = createContext<TerminalContextType | undefined>(undefined);
@ -89,6 +90,14 @@ export const TerminalProvider: React.FC<{ children: React.ReactNode }> = ({ chil
setSandboxId(newSandboxId); setSandboxId(newSandboxId);
}; };
const deploy = (callback: () => void) => {
if (!socket) console.error("Couldn't deploy: No socket");
console.log("Deploying...")
socket?.emit("deploy", () => {
callback();
});
}
const value = { const value = {
socket, socket,
terminals, terminals,
@ -100,6 +109,7 @@ export const TerminalProvider: React.FC<{ children: React.ReactNode }> = ({ chil
createNewTerminal, createNewTerminal,
closeTerminal, closeTerminal,
setUserAndSandboxId, setUserAndSandboxId,
deploy
}; };
return ( return (