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
|
RUN mkdir projects && chown -R myuser:myuser projects
|
||||||
USER myuser
|
USER myuser
|
||||||
|
|
||||||
|
# user namespace mapping
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
EXPOSE 4000
|
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");
|
console.log("startServer");
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (!isServerRunning || didFail)
|
// if (!isServerRunning || didFail)
|
||||||
return <Loading didFail={didFail} text="Creating your sandbox resources" />;
|
// return <Loading didFail={didFail} text="Creating your sandbox resources" />;
|
||||||
|
|
||||||
return <CodeEditor userData={userData} sandboxData={sandboxData} />;
|
return <CodeEditor userData={userData} sandboxData={sandboxData} />;
|
||||||
}
|
}
|
||||||
|
@ -83,13 +83,13 @@ export async function unshareSandbox(sandboxId: string, userId: string) {
|
|||||||
|
|
||||||
export async function startServer(serviceName: string) {
|
export async function startServer(serviceName: string) {
|
||||||
const command = new CreateServiceCommand({
|
const command = new CreateServiceCommand({
|
||||||
cluster: "arn:aws:ecs:us-east-1:767398085538:service/Sandbox/Sandbox",
|
cluster: process.env.AWS_ECS_CLUSTER!,
|
||||||
serviceName,
|
serviceName,
|
||||||
taskDefinition: "Sandbox1",
|
taskDefinition: "Sandbox1",
|
||||||
desiredCount: 1,
|
desiredCount: 1,
|
||||||
networkConfiguration: {
|
networkConfiguration: {
|
||||||
awsvpcConfiguration: {
|
awsvpcConfiguration: {
|
||||||
securityGroups: ["sg-07e489fcf3299af52"],
|
securityGroups: [process.env.AWS_ECS_SECURITY_GROUP!],
|
||||||
subnets: [
|
subnets: [
|
||||||
"subnet-06d04f2a6ebb1710c",
|
"subnet-06d04f2a6ebb1710c",
|
||||||
"subnet-097c000f157c26a78",
|
"subnet-097c000f157c26a78",
|
||||||
@ -105,7 +105,17 @@ export async function startServer(serviceName: string) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await ecsClient.send(command);
|
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) {
|
} catch (error) {
|
||||||
console.error("Error starting server:", error);
|
console.error("Error starting server:", error);
|
||||||
}
|
}
|
||||||
|
@ -94,31 +94,34 @@ export function addNew(
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// const checkServiceStatus = (serviceName: string) => {
|
const checkServiceStatus = (serviceName: string) => {
|
||||||
// return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
const command = new DescribeServicesCommand({
|
||||||
|
cluster: process.env.NEXT_PUBLIC_AWS_ECS_CLUSTER,
|
||||||
|
services: [serviceName],
|
||||||
|
});
|
||||||
|
|
||||||
// const command = new DescribeServicesCommand({
|
const interval = setInterval(async () => {
|
||||||
// cluster: "arn:aws:ecs:us-east-1:767398085538:service/Sandbox/Sandbox",
|
try {
|
||||||
// services: [serviceName]
|
const response = await ecsClient.send(command);
|
||||||
// })
|
console.log("Checking service status", response);
|
||||||
|
|
||||||
// const interval = setInterval(async () => {
|
if (response.services && response.services.length > 0) {
|
||||||
// try {
|
const service = response.services?.[0];
|
||||||
|
if (
|
||||||
// const response = await ecsClient.send(command)
|
service.runningCount === service.desiredCount &&
|
||||||
|
service.deployments &&
|
||||||
// if (response.services && response.services.length > 0) {
|
service.deployments.length === 1 &&
|
||||||
// const service = response.services?.[0];
|
service.deployments[0].rolloutState === "COMPLETED"
|
||||||
// if (service.runningCount === service.desiredCount && service.deployments.length === 1 && service.deployments[0].rolloutState === 'COMPLETED') {
|
) {
|
||||||
// clearInterval(interval);
|
clearInterval(interval);
|
||||||
// resolve(service);
|
resolve(service);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
} catch (error) {
|
||||||
// } catch (error) {
|
clearInterval(interval);
|
||||||
// clearInterval(interval);
|
reject(error);
|
||||||
// reject(error);
|
}
|
||||||
// }
|
}, 5000);
|
||||||
// }, 5000); // Check every 5 seconds
|
});
|
||||||
// });
|
};
|
||||||
// };
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user