

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Tentukan dua runtime
<a name="sample-runtime-two-major-version-runtimes"></a>

Anda dapat menentukan lebih dari satu runtime dalam proyek CodeBuild build yang sama. Proyek contoh ini menggunakan dua file sumber: satu yang menggunakan runtime Go dan satu yang menggunakan runtime Node.js. 

1. Membuat sebuah direktori bernama `my-source`. 

1. Di dalam `my-source` direktori, buat direktori bernama`golang-app`. 

1. Buat file bernama `hello.go` dengan isi berikut ini. Simpan file di `golang-app` direktori. 

   ```
   package main
   import "fmt"
   
   func main() {
     fmt.Println("hello world from golang")
     fmt.Println("1+1 =", 1+1)
     fmt.Println("7.0/3.0 =", 7.0/3.0)
     fmt.Println(true && false)
     fmt.Println(true || false)
     fmt.Println(!true)
     fmt.Println("good bye from golang")
   }
   ```

1. Di dalam `my-source` direktori, buat direktori bernama`nodejs-app`. Itu harus pada tingkat yang sama dengan `golang-app` direktori. 

1. Buat file bernama `index.js` dengan isi berikut ini. Simpan file di `nodejs-app` direktori. 

   ```
   console.log("hello world from nodejs");
   console.log("1+1 =" + (1+1));
   console.log("7.0/3.0 =" + 7.0/3.0);
   console.log(true && false);
   console.log(true || false);
   console.log(!true);
   console.log("good bye from nodejs");
   ```

1. Buat file bernama `package.json` dengan isi berikut ini. Simpan file di `nodejs-app` direktori. 

   ```
   {
     "name": "mycompany-app",
     "version": "1.0.0",
     "description": "",
     "main": "index.js",
     "scripts": {
       "test": "echo \"run some tests here\""
     },
     "author": "",
     "license": "ISC"
   }
   ```

1. Buat file bernama `buildspec.yml` dengan isi berikut ini. Simpan file di `my-source` direktori, pada tingkat yang sama dengan `golang-app` direktori `nodejs-app` dan. `runtime-versions`Bagian ini menentukan runtime Node.js versi 12 dan Go versi 1.13. 

   ```
   version: 0.2
   
   phases:
     install:
       runtime-versions:
         golang: 1.13
         nodejs: 12
     build:
       commands:
         - echo Building the Go code...
         - cd $CODEBUILD_SRC_DIR/golang-app
         - go build hello.go 
         - echo Building the Node code...
         - cd $CODEBUILD_SRC_DIR/nodejs-app
         - npm run test
   artifacts:
     secondary-artifacts:
       golang_artifacts:
         base-directory: golang-app
         files:
           - hello
       nodejs_artifacts:
         base-directory: nodejs-app
         files:
           - index.js
           - package.json
   ```

1. Struktur file Anda sekarang akan terlihat seperti ini. 

   ```
   my-source
   ├── golang-app
   │   └── hello.go
   ├── nodejs.app
   │   ├── index.js
   │   └── package.json
   └── buildspec.yml
   ```

1. Unggah isi `my-source` direktori ke bucket input S3 atau repositori CodeCommit, GitHub, atau Bitbucket.
**penting**  
 Jika Anda menggunakan bucket input S3, pastikan untuk membuat file ZIP yang berisi struktur direktori dan file, lalu unggah ke bucket input. Jangan tambahkan `my-source` ke file ZIP, hanya direktori dan file di`my-source`.

1. Buka AWS CodeBuild konsol di [https://console.aws.amazon.com/codesuite/codebuild/home](https://console.aws.amazon.com/codesuite/codebuild/home).

1. Buat proyek build. Untuk informasi selengkapnya, lihat [Buat proyek build (konsol)](create-project.md#create-project-console) dan [Jalankan build (konsol)](run-build-console.md). Biarkan semua pengaturan pada nilai default mereka, kecuali untuk pengaturan ini.
   + Untuk **Lingkungan**:
     + Untuk **gambar Lingkungan**, pilih **Gambar terkelola**.
     + Untuk **sistem operasi**, pilih **Amazon Linux 2**.
     + Untuk **Runtime**, pilih **Standar**.
     + Untuk **Gambar**, pilih **aws/codebuild/amazonlinux-x86\$164-standard:4.0**.

1. Pilih **Buat proyek build**. 

1. Pilih **Mulai membangun**. 

1. **Pada **konfigurasi Build**, terima default, lalu pilih Mulai build.** 

1. Setelah build selesai, lihat output build di tab **Build logs**. Anda akan melihat output seperti yang berikut ini. Ini menunjukkan output dari runtime Go dan Node.js. Ini juga menunjukkan output dari aplikasi Go dan Node.js. 

   ```
   [Container] Date Time Processing environment variables
   [Container] Date Time Selecting 'golang' runtime version '1.13' based on manual selections...
   [Container] Date Time Selecting 'nodejs' runtime version '12' based on manual selections...
   [Container] Date Time Running command echo "Installing Go version 1.13 ..."
   Installing Go version 1.13 ... 
    
   [Container] Date Time Running command echo "Installing Node.js version 12 ..." 
   Installing Node.js version 12 ... 
    
   [Container] Date Time Running command n $NODE_12_VERSION
      installed : v12.20.1 (with npm 6.14.10)
   
   [Container] Date Time Moving to directory /codebuild/output/src819694850/src
   [Container] Date Time Registering with agent
   [Container] Date Time Phases found in YAML: 2
   [Container] Date Time  INSTALL: 0 commands
   [Container] Date Time  BUILD: 1 commands
   [Container] Date Time Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
   [Container] Date Time Phase context status code:  Message:
   [Container] Date Time Entering phase INSTALL
   [Container] Date Time Phase complete: INSTALL State: SUCCEEDED
   [Container] Date Time Phase context status code:  Message:  
   [Container] Date Time Entering phase PRE_BUILD 
   [Container] Date Time Phase complete: PRE_BUILD State: SUCCEEDED 
   [Container] Date Time Phase context status code:  Message:  
   [Container] Date Time Entering phase BUILD 
   [Container] Date Time Running command echo Building the Go code... 
   Building the Go code... 
    
   [Container] Date Time Running command cd $CODEBUILD_SRC_DIR/golang-app 
    
   [Container] Date Time Running command go build hello.go 
    
   [Container] Date Time Running command echo Building the Node code... 
   Building the Node code... 
    
   [Container] Date Time Running command cd $CODEBUILD_SRC_DIR/nodejs-app 
    
   [Container] Date Time Running command npm run test 
    
   > mycompany-app@1.0.0 test /codebuild/output/src924084119/src/nodejs-app 
   > echo "run some tests here" 
    
   run some tests here
   ```