

亚马逊 CodeCatalyst 不再向新买家开放。现有客户可以继续正常使用该服务。有关更多信息，请参阅 [如何从中迁移 CodeCatalyst](migration.md)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 配置开发环境的 devfile
<a name="devenvironment-devfile"></a>

*devfile* 是一种开放标准，可帮助您在整个团队中自定义开发环境。devfile 是一个 YAML 文件，用于对所需的开发工具进行编码。通过配置开发文件，您可以预先确定所需的项目工具和应用程序库，然后 Amazon CodeCatalyst 将它们安装到您的开发环境中。存储库与为它创建的 devfile 相对应，您可以为每个存储库创建一个单独的 devfile。您的开发环境支持命令和事件，并提供默认的通用 devfile 映像。

如果您使用空蓝图创建项目，则可以手动创建 devfile。如果您使用不同的蓝图创建项目，则会自动 CodeCatalyst 创建一个 devfile。开发环境的 `/projects` 目录存储从源存储库中提取的文件和 devfile。`/home` 目录（首次创建开发环境时，该目录为空）存储您在使用开发环境时创建的文件。开发环境的 `/projects` 和 `/home` 目录中的所有内容都将持久存储。

**注意**  
仅在更改 devfile 名称或 devfile 组件名称时，`/home` 文件夹才会更改。如果更改 devfile 或 devfile 组件名称，则 `/home` 目录的内容将被替换，并且无法恢复之前的 `/home` 目录数据。

如果您创建的开发环境的源存储库中的根目录不包含 devfile，或者创建的开发环境不具有源存储库，则系统会自动将默认的通用 devfile 应用于源存储库。所有 IDEs用户都使用相同的默认通用 devfile 镜像。 CodeCatalyst 目前支持 devfile 版本 2.0.0。有关 devfile 的更多信息，请参阅 [Devfile schema - Version 2.0.0](https://devfile.io/docs/2.0.0/devfile-schema)。

**注意**  
您只能在 devfile 中包含公共容器映像。

请注意，与 VPC 连接的开发环境仅支持以下 devfile 映像：
+ 通用映像
+ 私有 Amazon ECR 映像（如果存储库与 VPC 位于同一区域）

**Topics**
+ [编辑开发环境的存储库 devfile](devenvironment-devfile-moving.md)
+ [支持的 Devfile 功能 CodeCatalyst](#devenvironment-devfile-support)
+ [开发环境的 devfile 示例](#devenvironment-devfile-example)
+ [使用恢复模式排查存储库 devfile 的问题](#devenvironment-devfile-recovery)
+ [为开发环境指定通用 devfile 映像](devenvironment-universal-image.md)
+ [Devfile 命令](devenvironment-devfile-commands.md)
+ [Devfile 事件](devenvironment-devfile-events.md)
+ [Devfile 组件](devenvironment-devfile-components.md)

# 编辑开发环境的存储库 devfile
<a name="devenvironment-devfile-moving"></a>

使用以下过程编辑开发环境的存储库 devfile。

## 在中编辑开发环境的存储库开发文件 CodeCatalyst
<a name="devenvironment-devfile-procedure"></a><a name="devenvironment-devfile-steps"></a>

**编辑存储库 devfile**

1. 打开 CodeCatalyst 控制台，[网址为 https://codecatalyst.aws/](https://codecatalyst.aws/)。

1. 导航到包含要编辑其 devfile 的源存储库的项目。

1. 在导航窗格中，选择**代码**。

1. 选择**源存储库**。

1. 选择包含要编辑的 devfile 的源存储库。

1. 从文件列表中选择 `devfile.yaml` 文件。

1. 选择**编辑**。

1. 编辑 devfile。

1. 选择**提交**，或者创建拉取请求，以便团队成员能够审查和批准更改。

**注意**  
如果您编辑 devfile，则必须重新启动 devfile 以使更改生效。这可以通过运行 `/aws/mde/mde start --location devfile.yaml` 来完成。如果启动 devfile 时出现问题，它将进入恢复模式。但是，如果您编辑与 VPC 连接的开发环境关联的 devfile，则必须重新启动开发环境才能使更改生效。

您可以通过运行 `/aws/mde/mde status` 来查看正在使用的 devfile。位置字段包含 devfile 相对于环境的 `/projects` 文件夹的路径。

```
{
            "status": "STABLE",
            "location": "devfile.yaml"
        }
```

您还可以将 `/projects/devfile.yaml` 中的默认 devfile 移至您的源代码存储库。要更新 devfile 的位置，请使用以下命令：`/aws/mde/mde start --location repository-name/devfile.yaml`。

## 在 IDE 中编辑开发环境的存储库 devfile
<a name="devenvironment-devfile-ide"></a>

要更改开发环境的配置，您必须编辑 devfile。我们建议您在支持的 IDE 中编辑开发文件，然后更新您的开发环境，但也可以从中源存储库的根目录编辑开发文件。 CodeCatalyst如果您在受支持的 IDE 中编辑 devfile，则必须提交更改并将其推送到源存储库或创建拉取请求，以便团队成员能够审查和批准 devfile 编辑内容。
+ [在中编辑开发环境的存储库 devfile AWS Cloud9](https://docs.aws.amazon.com/cloud9/latest/user-guide/devenvironment-cloud9.title.html#ide-toolkits-edit-devfile-cloud9)
+ [在 VS Code 中编辑开发环境的存储库 devfile](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/codecatalyst-devenvironment.html#codecatalyst-devenvironment-devfile)
+ [在中编辑开发环境的存储库 devfile JetBrains](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/codecatalyst-overview.html#codecatalyst-overview-default)

## 支持的 Devfile 功能 CodeCatalyst
<a name="devenvironment-devfile-support"></a>

CodeCatalyst 在 2.0.0 版本上支持以下开发文件功能。有关 devfile 的更多信息，请参阅 [Devfile schema - Version 2.0.0](https://devfile.io/docs/2.0.0/devfile-schema)。


| 功能 | Type | 
| --- | --- | 
|  `exec`  |  命令  | 
|  `postStart`  |  事件  | 
|  `container`  |  组件  | 
|  `args`  |  组件属性  | 
|  `env`  |  组件属性  | 
|  `mountSources`  |  组件属性  | 
|  `volumeMounts`  |  组件属性  | 

## 开发环境的 devfile 示例
<a name="devenvironment-devfile-example"></a>

以下是简单 devfile 的示例。

```
schemaVersion: 2.0.0
metadata:
  name: al2
components:
  - name: test
    container:
      image: public.ecr.aws/amazonlinux/amazonlinux:2
      mountSources: true
      command: ['sleep', 'infinity']
  - name: dockerstore
commands:
  - id: setupscript
    exec:
      component: test
      commandLine: "chmod +x script.sh"
      workingDir: /projects/devfiles
  - id: executescript
    exec:
      component: test
      commandLine: "/projects/devfiles/script.sh"
  - id: yumupdate
    exec:
      component: test
      commandLine: "yum -y update --security"
events:
  postStart:
    - setupscript
    - executescript
    - yumupdate
```

将捕获 devfile 的启动、命令和事件日志并将其存储在 `/aws/mde/logs` 中。要调试 devfile 行为，请使用有效的 devfile 启动开发环境并访问日志。

## 使用恢复模式排查存储库 devfile 的问题
<a name="devenvironment-devfile-recovery"></a>

如果启动 devfile 时出现问题，它将进入恢复模式，这样您仍能连接到您的环境并修复 devfile。在恢复模式中，运行 `/aws/mde/mde status` 将不会包含 devfile 的位置。

```
{
            "status": "STABLE"
        }
```

您可以查看 `/aws/mde/logs` 下的日志中的错误，修复 devfile，然后重试运行 `/aws/mde/mde start`。

# 为开发环境指定通用 devfile 映像
<a name="devenvironment-universal-image"></a>

默认*通用映像*包括可用于 IDE 的最常用的编程语言和相关工具。如果未指定图像，则 CodeCatalyst 提供此图像并包含由维护的工具 CodeCatalyst。要接收有关新映像版本的通知，请参阅[使用 SNS 订阅通用映像通知](#devenvironment-universal-notifications)。

Amazon CodeCatalyst 积极支持以下开发者文件镜像：


| 映像版本 | 映像标识符 | 
| --- | --- | 
| Universal image 4.0 | public.ecr.aws/aws-mde/universal-image:4.0 | 
| Universal image 5.0 | public.ecr.aws/aws-mde/universal-image:5.0 | 

**注意**  
您还可以使用 `public.ecr.aws/aws-mde/universal-image:latest` 获取最新映像，当前为 `public.ecr.aws/aws-mde/universal-image:5.0`。

CodeCatalyst 已弃用以下图片。您仍然可以使用这些映像，但它们不会缓存在构建主机上，因此将导致开发环境的启动时间更长。


| 映像版本 | 映像标识符 | 弃用日期 | 
| --- | --- | --- | 
| Universal image 1.0 | public.ecr.aws/aws-mde/universal-image:1.0 | 2024 年 8 月 16 日 | 
| Universal image 2.0 | public.ecr.aws/aws-mde/universal-image:2.0 | 2024 年 8 月 16 日 | 
| Universal image 3.0 | public.ecr.aws/aws-mde/universal-image:3.0 | 2025 年 7 月 30 日 | 

**注意**  
如果你使用的是 AWS Cloud9，升级到后自动完成功能将不适用于 PHP、Ruby 和 CSS。`universal-image:3.0`

**Topics**
+ [使用 SNS 订阅通用映像通知](#devenvironment-universal-notifications)
+ [通用映像 4.0 运行时版本](#devenvironment-universal-runtimes-4.0)
+ [通用映像 5.0 运行时版本](#devenvironment-universal-runtimes-5.0)

## 使用 SNS 订阅通用映像通知
<a name="devenvironment-universal-notifications"></a>

CodeCatalyst 提供通用的图像通知服务。您可以使用它来订阅亚马逊简单通知服务 (SNS) Simple Notification Service 主题，该主题将在 CodeCatalyst 通用图像更新发布时通知您。有关 SNS 主题的更多信息，请参阅 [What is Amazon Simple Notification Service?](https://docs.aws.amazon.com/sns/latest/dg/welcome.html)。

每当发布新的通用图像时，我们都会向订阅者发送通知；本节介绍如何订阅 CodeCatalyst 通用图像更新。

**示例消息**

```
{
    "Type": "Notification",
    "MessageId": "123456789",
    "TopicArn": "arn:aws:sns:us-east-1:1234657890:universal-image-updates",
    "Subject": "New Universal Image Release",
    "Message": {
        "v1": {
            "Message": "A new version of the Universal Image has been released. You are now able to launch new DevEnvironments using this image.",
            "image ": {
                "release_type": "MAJOR VERSION",
                "image_name": "universal-image",
                "image_version": "2.0",
                "image_uri": "public.ecr.aws/amazonlinux/universal-image:2.0"
            }
        }
    },
    "Timestamp": "2021-09-03T19:05:57.882Z",
    "UnsubscribeURL": "example url"
}
```

**使用 Amazon SNS 控制台订阅 CodeCatalyst 通用图像更新**

1. 打开 Amazon SNS 控制台以显示[控制面板](https://console.aws.amazon.com/sns/v2/home)。

1. 在导航栏中，选择您的 AWS 区域。

1. 在导航窗格中，选择**订阅**，然后选择**创建订阅**。

1. 在**主题 ARN** 中，输入 `arn:aws:sns:us-east-1:089793673375:universal-image-updates`。

1. 在**协议**中，选择**电子邮件**。

1. 在**端点**中，提供一个电子邮件地址。此电子邮件地址将用于接收通知。

1. 选择**创建订阅**。

1. 您将收到一封主题为 “AWS 通知-订阅确认” 的确认电子邮件。打开这封电子邮件，然后选择**确认订阅**。

**使用 Amazon SNS 控制台取消订阅 CodeCatalyst 通用图像更新**

1. 打开 Amazon SNS 控制台以显示[控制面板](https://console.aws.amazon.com/sns/v2/home)。

1. 在导航栏中，选择您的 AWS 区域。

1. 在导航窗格中，选择**订阅**，然后选择要取消的订阅。

1. 选择**操作**，然后选择**删除订阅**。

1. 选择**删除**。

## 通用映像 4.0 运行时版本
<a name="devenvironment-universal-runtimes-4.0"></a>

下表列出了对 `universal-image:4.0` 可用的运行时。


**`universal-image:4.0` 运行时版本**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/codecatalyst/latest/userguide/devenvironment-universal-image.html)

## 通用映像 5.0 运行时版本
<a name="devenvironment-universal-runtimes-5.0"></a>

下表列出了对 `universal-image:5.0` 可用的运行时。


**`universal-image:5.0` 运行时版本**  

| 运行时名称  | 版本 | 特定主要和最新次要版本 | 
| --- | --- | --- | 
| aws cli |  2.25  |  `aws-cli: 2.x`  | 
| docker compose |  2.34  |  `docker-compose: 2.x`  | 
| dotnet |  8.0  |  `dotnet: 8.x`  | 
| golang |  1.24  |  `golang: 1.x`  | 
| java |  corretto21  |  `java: corretto21.x`  | 
| nodejs |  22.0  |  `nodejs: 22.x`  | 
| php |  8.3.16  |  `php: 8.x`  | 
| python |  3.12  |  `python: 3.x`  | 
| ruby |  3.4.2  |  `ruby: 3.x`  | 
| terraform |  1.10.5  |  `terraform: 1.x`  | 

# Devfile 命令
<a name="devenvironment-devfile-commands"></a>

目前， CodeCatalyst 仅支持你的开发文件中的`exec`命令。有关更多信息，请参阅 Devfile.io 文档中的 [Adding commands](https://devfile.io/docs/2.0.0/adding-commands)。

以下示例说明如何在 devfile 中指定 `exec` 命令。

```
commands:
  - id: setupscript
    exec:
      component: test
      commandLine: "chmod +x script.sh"
      workingDir: /projects/devfiles
  - id: executescript
    exec:
      component: test
      commandLine: "./projects/devfiles/script.sh"
  - id: updateyum
    exec:
      component: test
      commandLine: "yum -y update --security"
```

连接到开发环境后，您可以通过终端执行定义的命令。

```
/aws/mde/mde command <command-id>
/aws/mde/mde command executescript
```

对于长时间运行的命令，您可以使用流标志 `-s` 来实时输出命令的执行。

```
/aws/mde/mde -s command <command-id>
```

**注意**  
`command-id` 必须小写。

## 支持的 exec 参数 CodeCatalyst
<a name="devenvironment-exec-support"></a>

CodeCatalyst 在 devfile 版本 2.0.0 上支持以下`exec`参数。
+ `commandLine`
+ `component`
+ `id`
+ `workingDir`

# Devfile 事件
<a name="devenvironment-devfile-events"></a>

目前， CodeCatalyst 仅支持开发文件中的`postStart`事件。有关更多信息，请参阅 devFile.io 文档[postStartObject](https://devfile.io/docs/2.0.0/adding-event-bindings#post-start-object)中的。

以下示例说明如何在 devfile 中添加 `postStart` 事件绑定。

```
commands:
  - id: executescript
    exec:
      component: test
      commandLine: "./projects/devfiles/script.sh"
  - id: updateyum
    exec:
      component: test
      commandLine: "yum -y update --security"
events:
  postStart:
    - updateyum
    - executescript
```

启动后，您的开发环境将按照指定的 `postStart` 命令的定义顺序来执行这些命令。如果命令失败，开发环境将继续运行，并且执行输出将存储在 `/aws/mde/logs` 下的日志中。

# Devfile 组件
<a name="devenvironment-devfile-components"></a>

目前， CodeCatalyst 仅支持开发文件中的`container`组件。有关更多信息，请参阅 Devfile.io 文档中的 [Adding components](https://devfile.io/docs/2.0.0/adding-components)。

以下示例说明如何将启动命令添加到 devfile 中的容器。

```
components:
  - name: test
    container:
      image: public.ecr.aws/amazonlinux/amazonlinux:2
      command: ['sleep', 'infinity']
```

**注意**  
当容器具有短效入口命令时，您必须包含 `command: ['sleep', 'infinity']` 以使容器保持运行。

CodeCatalyst 还支持容器组件中的以下属性：`args``env`、`mountSources`、和`volumeMounts`。