

Amazon CodeCatalyst 不再向新客戶開放。現有客戶可以繼續正常使用該服務。如需詳細資訊，請參閱[如何從 CodeCatalyst 遷移](migration.md)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 設定開發環境的 devfile
<a name="devenvironment-devfile"></a>

*devfile* 是一種開放標準，可協助您在團隊中自訂開發開發環境。devfile 是 YAML 檔案，可編纂您所需的開發工具。透過設定 devfile，您可以預先確定所需的專案工具和應用程式程式庫，Amazon CodeCatalyst 會為您將其安裝到您的開發環境。devfile 專屬於為其建立的儲存庫，您可以為每個儲存庫建立個別的 devfile。您的開發環境支援命令和事件，並提供預設的通用 devfile 映像。

如果您使用空白藍圖建立專案，您可以手動建立 devfile。如果您使用不同的藍圖建立專案，CodeCatalyst 會自動建立 devfile。開發環境的`/projects`目錄會存放從來源儲存庫和 devfile 提取的檔案。當您第一次建立開發環境時， `/home`目錄是空的， 會存放您在使用開發環境時建立的檔案。開發環境的 `/projects`和 `/home`目錄中的所有內容都會持續儲存。

**注意**  
只有當您變更 devfile 或 devfile 元件名稱時，`/home`資料夾才會變更。如果您變更 devfile 或 devfile 元件名稱，則會取代`/home`目錄的內容，而且無法復原先前的`/home`目錄資料。

如果您使用來源儲存庫建立的開發環境在其根中不包含 devfile，或者如果您建立沒有來源儲存庫的開發環境，則預設通用 devfile 會自動套用到來源儲存庫。相同的預設通用 devfile 映像會用於所有 IDEs。CodeCatalyst 目前支援 devfile 2.0.0 版。如需 devfile 的詳細資訊，請參閱 [Devfile 結構描述 - 2.0.0 版](https://devfile.io/docs/2.0.0/devfile-schema)。

**注意**  
您只能在您的 devfile 中包含公用容器影像。

請注意，VPC 連線的開發環境僅支援下列開發檔案映像：
+ 通用映像
+ 如果儲存庫與 VPC 位於相同區域，則為私有 Amazon ECR 映像

**Topics**
+ [編輯開發環境的儲存庫 devfile](devenvironment-devfile-moving.md)
+ [CodeCatalyst 支援的 Devfile 功能](#devenvironment-devfile-support)
+ [開發環境的 devfile 範例](#devenvironment-devfile-example)
+ [使用復原模式對儲存庫開發檔進行故障診斷](#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 中編輯開發環境的儲存庫 devfile
<a name="devenvironment-devfile-procedure"></a><a name="devenvironment-devfile-steps"></a>

**編輯儲存庫 devfile**

1. 在 https：//[https://codecatalyst.aws/](https://codecatalyst.aws/) 開啟 CodeCatalyst 主控台。

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，則必須重新啟動開發環境，變更才會生效。

您可以檢閱執行 正在使用哪個 devfile`/aws/mde/mde status`。位置欄位具有相對於環境`/projects`資料夾的 devfile 路徑。

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

您也可以將預設 devfile `/projects/devfile.yaml` 移入您的原始碼儲存庫。若要更新 devfile 的位置，請使用下列命令：`/aws/mde/mde start --location repository-name/devfile.yaml`。

## 在 IDE 中編輯開發環境的儲存庫 devfile
<a name="devenvironment-devfile-ide"></a>

若要變更開發環境的組態，您必須編輯 devfile。我們建議您在支援的 IDE 中編輯 devfile，然後更新開發環境，但您也可以從 CodeCatalyst 中的來源儲存庫根目錄編輯 devfile。如果您在支援的 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 程式碼中編輯開發環境的儲存庫 devfile](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/codecatalyst-devenvironment.html#codecatalyst-devenvironment-devfile)
+ [在 JetBrains 中編輯開發環境的儲存庫 devfile](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/codecatalyst-overview.html#codecatalyst-overview-default)

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

CodeCatalyst 支援 2.0.0 版的下列 devfile 功能。如需 devfile 的詳細資訊，請參閱 [Devfile 結構描述 - 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
```

開發檔案啟動、命令和事件日誌會擷取並儲存在 中`/aws/mde/logs`。若要偵錯開發檔案行為，請使用運作中的開發檔案啟動開發環境並存取日誌。

## 使用復原模式對儲存庫開發檔進行故障診斷
<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 主動支援下列 devfile 映像：


| 映像版本 | 映像識別符 | 
| --- | --- | 
| 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 提供通用映像通知服務。您可以使用它來訂閱 Amazon Simple Notification Service (SNS) 主題，該主題會在 CodeCatalyst 通用映像更新發佈時通知您。如需 SNS 主題的詳細資訊，請參閱[什麼是 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](https://console.aws.amazon.com/sns/v2/home)。

1. 在導覽列中，選擇您的 AWS 區域。

1. 在導覽窗格中選擇 **Subscriptions (訂閱)**，然後選擇 **Create subscription (建立訂閱)**。

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

1. 在 **Protocol (通訊協定)** 中，選擇 **Email (電子郵件)**。

1. 在**端點**中，提供電子郵件地址。此電子郵件地址將用於接收通知。

1. 選擇**建立訂閱**。

1. 您將收到一封確認電子郵件，主旨行為「AWS 通知 - 訂閱確認」。開啟電子郵件，然後選擇**確認訂閱**。

**使用 Amazon SNS 主控台取消訂閱 CodeCatalyst 通用映像更新**

1. 開啟儀表板的 Amazon SNS 主控台[https://console.aws.amazon.com/sns/v2/home](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_tw/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 僅支援 devfile 中的`exec`命令。如需詳細資訊，請參閱 Devfile.io 文件中的[新增命令](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` 必須是小寫。

## CodeCatalyst 支援的 Exec 參數
<a name="devenvironment-exec-support"></a>

CodeCatalyst 在 devfile 2.0.0 版上支援下列`exec`參數。
+ `commandLine`
+ `component`
+ `id`
+ `workingDir`

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

目前，CodeCatalyst 僅支援您 devfile 中的`postStart`事件。如需詳細資訊，請參閱 https：//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 僅支援您 devfile 中的`container`元件。如需詳細資訊，請參閱 Devfile.io 文件中的[新增元件](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`、`mountSources`、 `env`和 `volumeMounts`。