

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 런타임 2개 지정
<a name="sample-runtime-two-major-version-runtimes"></a>

동일한 CodeBuild 빌드 프로젝트에서 둘 이상의 런타임을 지정할 수 있습니다. 이 샘플은 두 개의 소스 파일을 사용하는데 하나는 Go 런타임을 사용하고, 다른 하나는 Node.js 런타임을 사용합니다.

1. `my-source`이라는 디렉터리를 생성합니다.

1. `my-source` 디렉터리 안에 이름이 `golang-app`인 디렉터리를 생성합니다.

1. 다음 콘텐츠를 가진 `hello.go`이라는 파일을 생성합니다: 파일을 `golang-app` 디렉터리에 저장합니다.

   ```
   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. `my-source` 디렉터리 안에 이름이 `nodejs-app`인 디렉터리를 생성합니다. `golang-app` 디렉터리와 레벨이 같아야 합니다.

1. 다음 콘텐츠를 가진 `index.js`이라는 파일을 생성합니다: 파일을 `nodejs-app` 디렉터리에 저장합니다.

   ```
   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. 다음 콘텐츠를 가진 `package.json`이라는 파일을 생성합니다: 파일을 `nodejs-app` 디렉터리에 저장합니다.

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

1. 다음 콘텐츠를 가진 `buildspec.yml`이라는 파일을 생성합니다: `my-source` 디렉터리에, `nodejs-app` 및 `golang-app` 디렉터리와 같은 레벨에 파일을 저장합니다. `runtime-versions` 섹션은 Node.js 버전 12 및 Go 버전 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. 파일 구조가 아래와 같이 나타날 것입니다.

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

1. `my-source` 디렉터리의 내용을 S3 입력 버킷이나 CodeCommit, GitHub 또는 Bitbucket 리포지토리에 업로드합니다.
**중요**  
 S3 입력 버킷을 사용하고 있는 경우, 디렉터리 구조 및 파일을 포함하는 ZIP 파일을 생성한 다음, 이를 입력 버킷에 업로드합니다. `my-source`를 ZIP 파일에 추가하지 말고, `my-source`에 있는 디렉터리와 파일만 추가하십시오.

1. [https://console.aws.amazon.com/codesuite/codebuild/home](https://console.aws.amazon.com/codesuite/codebuild/home) AWS CodeBuild 콘솔을 엽니다.

1. 빌드 프로젝트를 생성합니다. 자세한 내용은 [빌드 프로젝트 만들기(콘솔)](create-project.md#create-project-console) 및 [빌드 실행(콘솔)](run-build-console.md) 섹션을 참조하세요. 다음 설정을 제외하고 모든 설정을 기본값 그대로 둡니다.
   + **환경**:
     + **환경 이미지**에서 **이미지 관리**를 선택합니다.
     + **운영 체제**에서 **Amazon Linux 2**를 선택합니다.
     + **런타임**에서 **표준**을 선택합니다.
     + **이미지**의 경우 **aws/codebuild/amazonlinux-x86\$164-standard:4.0**을 선택합니다.

1. **빌드 프로젝트 생성**을 선택합니다.

1. **빌드 시작**를 선택합니다.

1. **Build configuration(빌드 구성)**에서 기본값을 적용한 다음 **빌드 시작**을 선택합니다.

1. 빌드가 완료되면 **빌드 로그** 탭에서 빌드 출력을 확인합니다. 다음과 유사한 출력 화면이 표시되어야 합니다. Go 및 Node.js 런타임의 출력을 보여줍니다. Go 및 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
   ```