more container orchestration logic
This commit is contained in:
parent
a3dd0d6598
commit
561a284fc9
@ -20,6 +20,8 @@ RUN useradd -m myuser
|
||||
RUN mkdir projects && chown -R myuser:myuser projects
|
||||
USER myuser
|
||||
|
||||
# user namespace mapping
|
||||
|
||||
EXPOSE 3000
|
||||
EXPOSE 4000
|
||||
|
||||
|
15
frontend/.env.example
Normal file
15
frontend/.env.example
Normal file
@ -0,0 +1,15 @@
|
||||
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
|
||||
CLERK_SECRET_KEY=
|
||||
NEXT_PUBLIC_LIVEBLOCKS_PUBLIC_KEY=
|
||||
LIVEBLOCKS_SECRET_KEY=
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
|
||||
NEXT_PUBLIC_AWS_ECS_CLUSTER=
|
||||
AWS_ECS_SECURITY_GROUP=
|
||||
|
||||
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
|
||||
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
|
||||
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/dashboard
|
||||
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/dashboard
|
@ -34,8 +34,8 @@ export default function Editor({
|
||||
console.log("startServer");
|
||||
}, []);
|
||||
|
||||
if (!isServerRunning || didFail)
|
||||
return <Loading didFail={didFail} text="Creating your sandbox resources" />;
|
||||
// if (!isServerRunning || didFail)
|
||||
// return <Loading didFail={didFail} text="Creating your sandbox resources" />;
|
||||
|
||||
return <CodeEditor userData={userData} sandboxData={sandboxData} />;
|
||||
}
|
||||
|
@ -83,13 +83,13 @@ export async function unshareSandbox(sandboxId: string, userId: string) {
|
||||
|
||||
export async function startServer(serviceName: string) {
|
||||
const command = new CreateServiceCommand({
|
||||
cluster: "arn:aws:ecs:us-east-1:767398085538:service/Sandbox/Sandbox",
|
||||
cluster: process.env.AWS_ECS_CLUSTER!,
|
||||
serviceName,
|
||||
taskDefinition: "Sandbox1",
|
||||
desiredCount: 1,
|
||||
networkConfiguration: {
|
||||
awsvpcConfiguration: {
|
||||
securityGroups: ["sg-07e489fcf3299af52"],
|
||||
securityGroups: [process.env.AWS_ECS_SECURITY_GROUP!],
|
||||
subnets: [
|
||||
"subnet-06d04f2a6ebb1710c",
|
||||
"subnet-097c000f157c26a78",
|
||||
@ -105,7 +105,17 @@ export async function startServer(serviceName: string) {
|
||||
|
||||
try {
|
||||
const response = await ecsClient.send(command);
|
||||
console.log("started server:", response);
|
||||
console.log("started server:", response.service?.serviceName);
|
||||
|
||||
// store in workers kv:
|
||||
// {
|
||||
// userId: {
|
||||
// sandboxId,
|
||||
// serviceName,
|
||||
// startedAt,
|
||||
|
||||
// }
|
||||
// }
|
||||
} catch (error) {
|
||||
console.error("Error starting server:", error);
|
||||
}
|
||||
|
@ -94,31 +94,34 @@ export function addNew(
|
||||
// }
|
||||
// }
|
||||
|
||||
// const checkServiceStatus = (serviceName: string) => {
|
||||
// return new Promise((resolve, reject) => {
|
||||
const checkServiceStatus = (serviceName: string) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const command = new DescribeServicesCommand({
|
||||
cluster: process.env.NEXT_PUBLIC_AWS_ECS_CLUSTER,
|
||||
services: [serviceName],
|
||||
});
|
||||
|
||||
// const command = new DescribeServicesCommand({
|
||||
// cluster: "arn:aws:ecs:us-east-1:767398085538:service/Sandbox/Sandbox",
|
||||
// services: [serviceName]
|
||||
// })
|
||||
const interval = setInterval(async () => {
|
||||
try {
|
||||
const response = await ecsClient.send(command);
|
||||
console.log("Checking service status", response);
|
||||
|
||||
// const interval = setInterval(async () => {
|
||||
// try {
|
||||
|
||||
// const response = await ecsClient.send(command)
|
||||
|
||||
// if (response.services && response.services.length > 0) {
|
||||
// const service = response.services?.[0];
|
||||
// if (service.runningCount === service.desiredCount && service.deployments.length === 1 && service.deployments[0].rolloutState === 'COMPLETED') {
|
||||
// clearInterval(interval);
|
||||
// resolve(service);
|
||||
// }
|
||||
// }
|
||||
|
||||
// } catch (error) {
|
||||
// clearInterval(interval);
|
||||
// reject(error);
|
||||
// }
|
||||
// }, 5000); // Check every 5 seconds
|
||||
// });
|
||||
// };
|
||||
if (response.services && response.services.length > 0) {
|
||||
const service = response.services?.[0];
|
||||
if (
|
||||
service.runningCount === service.desiredCount &&
|
||||
service.deployments &&
|
||||
service.deployments.length === 1 &&
|
||||
service.deployments[0].rolloutState === "COMPLETED"
|
||||
) {
|
||||
clearInterval(interval);
|
||||
resolve(service);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
clearInterval(interval);
|
||||
reject(error);
|
||||
}
|
||||
}, 5000);
|
||||
});
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user