简体   繁体   English

在AWS上配置基于云的vscode ide

[英]Configure cloud-based vscode ide on AWS

CONTEXT: We have a platform where users can create their own projects - multiple projects per user.背景:我们有一个平台,用户可以在其中创建自己的项目——每个用户可以创建多个项目。 We need to provide them with a browser-based IDE to edit those projects.我们需要为他们提供基于浏览器的 IDE 来编辑这些项目。 We decided to go with coder-server.我们决定使用 coder-server go。 For this we need to configure an auto-scalable cluster on AWS.为此,我们需要在 AWS 上配置一个可自动扩展的集群。 When the user clicks "Edit Project" we will bring up a new container each time.当用户单击“编辑项目”时,我们每次都会调出一个新容器。 https://hub.docker.com/r/codercom/code-server https://hub.docker.com/r/codercom/code-server

QUESTION: How to pass parameters from the url query (my-site.com/edit?project=1234) into a startup script to pre-configure the workspace in a docker container when it starts?问题:如何将来自 url 查询 (my-site.com/edit?project=1234) 的参数传递到启动脚本中,以便在启动时在 docker 容器中预配置工作区?

Let's say the stack is AWS + ECS + Fargate.假设堆栈是 AWS + ECS + Fargate。 We could use kube.netes instead of ECS if it helps.如果有帮助,我们可以使用 kube.netes 而不是 ECS。

I don't have any experience in cluster configuration.我在集群配置方面没有任何经验。 Will appreciate any help or at least a direction where to dig further.将不胜感激任何帮助或至少是进一步挖掘的方向。

The above can be achieved using multiple ways in AWS ECS.以上可以在 AWS ECS 中使用多种方式实现。 The basic requirements for such systems are to launch and terminate containers on the fly while persisting the changes in the files.此类系统的基本要求是在运行中启动和终止容器,同时保留文件中的更改。 (I will focus on launching the containers) (我将专注于启动容器)

Using AWS SDK's:使用 AWS SDK:

The task can be easily achieved using AWS SDKs, Using a base task definition.该任务可以使用 AWS 开发工具包、使用基本任务定义轻松实现。 AWS SDK allows starting tasks with overrides on the base task definition. AWS SDK 允许启动任务并覆盖基本任务定义。

EG If task definition has a memory of 2GB then the SDK can override the memory to parameterised value while launching a task from task def. EG 如果任务定义有一个 2GB 的 memory,那么 SDK 可以在从任务定义启动任务时覆盖 memory 为参数化值。

Refer to the boto3 (AWS SDK for Python) docs.请参阅 boto3(适用于 Python 的 AWS SDK)文档。

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.run_task https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.run_task

Overall Solution整体解决方案

Now that we know how to run custom tasks with python SDK (on demand).现在我们知道如何使用 python SDK(按需)运行自定义任务。 The overall flow for your application is your API calling AWS lambda function whit parameters to spin up and wait to keep checking task status and update and rout traffic to it once the status is healthy.您的应用程序的整体流程是您的 API 调用 AWS lambda function 参数以启动并等待继续检查任务状态并在状态健康时更新和路由流量到它。

  1. API calls AWS lambda functions with parameters API 调用带参数的 AWS lambda 函数
  2. Lambda function using AWS SDK create a new task with overrides from base task definition. Lambda function 使用 AWS SDK 创建一个新任务,覆盖基本任务定义。 (assuming the base task definition already exists) (假设基本任务定义已经存在)
  3. Keep checking the status of the new task in the same function call and set a flag in your database for your front end to be able to react to it.在同一个 function 调用中继续检查新任务的状态,并在数据库中设置一个标志,以便前端能够对其做出反应。
  4. Once the status is healthy you can add a rule in the application load balancer using AWS SDK to route traffic to the IP without exposing the IP address to the end client (AWS application load balancer can get expensive, I'll advise using Nginx or HAProxy on ec2 to manage dynamic routing)一旦状态正常,您可以使用 AWS SDK 在应用程序负载均衡器中添加规则,以将流量路由到 IP,而不会将 IP 地址暴露给最终客户端(AWS 应用程序负载均衡器可能会变得昂贵,我建议使用 Nginx 或 HAProxy在 ec2 上管理动态路由)

Note:笔记:

Ensure your Image is lightweight, and the startup times are less than 15 mins as lambda cannot execute beyond that.确保您的图像是轻量级的,并且启动时间少于 15 分钟,因为 lambda 无法执行超过该时间。 If that's the case create a microservice for launching ad-hoc containers and hosting them on EC2如果是这种情况,请创建一个微服务来启动临时容器并将它们托管在 EC2 上

Using Terraform:使用 Terraform:

If you looking for infrastructure provisioning terraform is the way to go. It has a learning curve so recommend it as a secondary option.如果您正在寻找基础设施供应 terraform 是通往 go 的途径。它有一个学习曲线,因此推荐它作为次要选项。

Terraform is popular for parametrising using variables and it can be plugged in easily as a backend for an API. The flow of your application still remains the same from step 1, but instead of AWS Lambda API will be calling your ad-hoc container microservice, which in turn calls terraform script and passing variables to it. Terraform 在使用变量进行参数化方面很受欢迎,它可以作为 API 的后端轻松插入。您的应用程序的流程仍然与步骤 1 相同,但 API 将调用您的临时容器微服务,而不是 AWS Lambda,依次调用 terraform 脚本并将变量传递给它。

Refer to the Terrafrom docs for AWS请参阅 AWS 的 Terrafrom 文档

https://registry.terraform.io/providers/hashicorp/aws/latesthttps://registry.terraform.io/providers/hashicorp/aws/latest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM