

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 連線的開發環境僅支援下列 devfile 映像：
+ 通用映像
+ 如果儲存庫與 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)

## 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`。