change gke cluster
This commit is contained in:
parent
59fb0521af
commit
5df770bdd6
3
.gitignore
vendored
3
.gitignore
vendored
@ -42,4 +42,5 @@ dist
|
|||||||
backend/server/projects
|
backend/server/projects
|
||||||
backend/database/drizzle
|
backend/database/drizzle
|
||||||
|
|
||||||
app.yaml
|
app.yaml
|
||||||
|
ingressController.yaml
|
@ -15,5 +15,6 @@
|
|||||||
|
|
||||||
# Node.js dependencies:
|
# Node.js dependencies:
|
||||||
node_modules/
|
node_modules/
|
||||||
|
.env
|
||||||
|
|
||||||
.env
|
ingressController.yaml
|
@ -30,24 +30,14 @@ if (process.env.NODE_ENV === "production") {
|
|||||||
kubeconfig.loadFromOptions({
|
kubeconfig.loadFromOptions({
|
||||||
clusters: [
|
clusters: [
|
||||||
{
|
{
|
||||||
name: 'docker-desktop',
|
name: 'gke_sylvan-epoch-422219-f9_us-central1_sandbox-cluster',
|
||||||
server: process.env.DOCKER_DESKTOP_SERVER!,
|
|
||||||
caData: process.env.DOCKER_DESKTOP_CA_DATA,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'gke_sylvan-epoch-422219-f9_us-central1_sandbox',
|
|
||||||
server: process.env.GKE_CLUSTER_SERVER!,
|
server: process.env.GKE_CLUSTER_SERVER!,
|
||||||
caData: process.env.GKE_CLUSTER_CA_DATA,
|
caData: process.env.GKE_CLUSTER_CA_DATA,
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
users: [
|
users: [
|
||||||
{
|
{
|
||||||
name: 'docker-desktop',
|
name: 'gke_sylvan-epoch-422219-f9_us-central1_sandbox-cluster',
|
||||||
certData: process.env.DOCKER_DESKTOP_CLIENT_CERTIFICATE_DATA,
|
|
||||||
keyData: process.env.DOCKER_DESKTOP_CLIENT_KEY_DATA,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'gke_sylvan-epoch-422219-f9_us-central1_sandbox',
|
|
||||||
exec: {
|
exec: {
|
||||||
apiVersion: 'client.authentication.k8s.io/v1beta1',
|
apiVersion: 'client.authentication.k8s.io/v1beta1',
|
||||||
command: 'gke-gcloud-auth-plugin',
|
command: 'gke-gcloud-auth-plugin',
|
||||||
@ -76,8 +66,8 @@ if (process.env.NODE_ENV === "production") {
|
|||||||
}
|
}
|
||||||
kubeconfig.loadFromDefault()
|
kubeconfig.loadFromDefault()
|
||||||
|
|
||||||
const coreV1Api = kubeconfig.makeApiClient(CoreV1Api)
|
|
||||||
const appsV1Api = kubeconfig.makeApiClient(AppsV1Api)
|
const appsV1Api = kubeconfig.makeApiClient(AppsV1Api)
|
||||||
|
const coreV1Api = kubeconfig.makeApiClient(CoreV1Api)
|
||||||
const networkingV1Api = kubeconfig.makeApiClient(NetworkingV1Api)
|
const networkingV1Api = kubeconfig.makeApiClient(NetworkingV1Api)
|
||||||
|
|
||||||
const readAndParseKubeYaml = (
|
const readAndParseKubeYaml = (
|
||||||
@ -131,14 +121,15 @@ app.post("/start", async (req, res) => {
|
|||||||
sandboxId
|
sandboxId
|
||||||
)
|
)
|
||||||
|
|
||||||
console.log("Successfully read and parsed kube yaml")
|
|
||||||
|
|
||||||
async function resourceExists(api: any, getMethod: string, name: string) {
|
async function resourceExists(api: any, getMethod: string, name: string) {
|
||||||
try {
|
try {
|
||||||
await api[getMethod](namespace, name)
|
await api[getMethod](name, namespace)
|
||||||
return true
|
return true
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (e.response && e.response.statusCode === 404) return false
|
if (e.response && e.response.statusCode === 404) {
|
||||||
|
console.log("Resource does not exist.", e.response.body.message, e.response.body.details)
|
||||||
|
return false
|
||||||
|
}
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,22 +141,16 @@ app.post("/start", async (req, res) => {
|
|||||||
if (!(await resourceExists(appsV1Api, 'readNamespacedDeployment', name))) {
|
if (!(await resourceExists(appsV1Api, 'readNamespacedDeployment', name))) {
|
||||||
await appsV1Api.createNamespacedDeployment(namespace, manifest)
|
await appsV1Api.createNamespacedDeployment(namespace, manifest)
|
||||||
console.log("Made deploymnet")
|
console.log("Made deploymnet")
|
||||||
} else {
|
|
||||||
return res.status(200).send({ message: "Resource deployment already exists." })
|
|
||||||
}
|
}
|
||||||
else if (kind === "Service")
|
else if (kind === "Service")
|
||||||
if (!(await resourceExists(coreV1Api, 'readNamespacedService', name))) {
|
if (!(await resourceExists(coreV1Api, 'readNamespacedService', name))) {
|
||||||
await coreV1Api.createNamespacedService(namespace, manifest)
|
await coreV1Api.createNamespacedService(namespace, manifest)
|
||||||
console.log("Made service")
|
console.log("Made service")
|
||||||
} else {
|
|
||||||
return res.status(200).send({ message: "Resource service already exists." })
|
|
||||||
}
|
}
|
||||||
else if (kind === "Ingress")
|
else if (kind === "Ingress")
|
||||||
if (!(await resourceExists(networkingV1Api, 'readNamespacedIngress', name))) {
|
if (!(await resourceExists(networkingV1Api, 'readNamespacedIngress', name))) {
|
||||||
await networkingV1Api.createNamespacedIngress(namespace, manifest)
|
await networkingV1Api.createNamespacedIngress(namespace, manifest)
|
||||||
console.log("Made ingress")
|
console.log("Made ingress")
|
||||||
} else {
|
|
||||||
return res.status(200).send({ message: "Resource ingress already exists." })
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -441,7 +441,7 @@ io.on("connection", async (socket) => {
|
|||||||
if (sockets.length === 0) {
|
if (sockets.length === 0) {
|
||||||
// close server
|
// close server
|
||||||
console.log("Closing server due to inactivity.");
|
console.log("Closing server due to inactivity.");
|
||||||
// const res = await stopServer(data.sandboxId, data.userId)
|
const res = await stopServer(data.sandboxId, data.userId)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 20000);
|
}, 20000);
|
||||||
|
@ -4,7 +4,7 @@ import dynamic from "next/dynamic";
|
|||||||
import Loading from "@/components/editor/loading";
|
import Loading from "@/components/editor/loading";
|
||||||
import { Sandbox, User } from "@/lib/types";
|
import { Sandbox, User } from "@/lib/types";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { startServer, stopServer } from "@/lib/utils";
|
import { startServer } from "@/lib/utils";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
const CodeEditor = dynamic(() => import("@/components/editor/editor"), {
|
const CodeEditor = dynamic(() => import("@/components/editor/editor"), {
|
||||||
@ -32,9 +32,9 @@ export default function Editor({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
// return () => {
|
||||||
stopServer(sandboxData.id, userData.id);
|
// stopServer(sandboxData.id, userData.id);
|
||||||
};
|
// };
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (!isServerRunning)
|
if (!isServerRunning)
|
||||||
|
@ -29,7 +29,7 @@ export default function PreviewWindow({
|
|||||||
<div className="text-xs">
|
<div className="text-xs">
|
||||||
Preview
|
Preview
|
||||||
<span className="inline-block ml-2 items-center font-mono text-muted-foreground">
|
<span className="inline-block ml-2 items-center font-mono text-muted-foreground">
|
||||||
localhost:3000
|
localhost:8000
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex space-x-1 translate-x-1">
|
<div className="flex space-x-1 translate-x-1">
|
||||||
|
@ -76,17 +76,4 @@ export async function startServer(sandboxId: string, userId: string, callback: (
|
|||||||
callback(false)
|
callback(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const stopServer = async (sandboxId: string, userId: string) => {
|
|
||||||
const res = await fetch("http://localhost:4001/stop", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
sandboxId,
|
|
||||||
userId
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user