buildspec 파일 샘플의 런타임 버전 CodeBuild - AWS CodeBuild

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

buildspec 파일 샘플의 런타임 버전 CodeBuild

Amazon Linux 2(AL2) 표준 이미지 버전 1.0 이상 또는 Ubuntu 표준 이미지 버전 2.0 이상을 사용하는 경우 buildspec 파일의 runtime-versions 섹션에서 하나 이상의 런타임을 지정할 수 있습니다. 이 샘플은 프로젝트 런타임 변경, 둘 이상의 런타임 지정, 다른 런타임에 종속되는 런타임 지정 방법을 보여줍니다. 지원되는 런타임에 대한 자세한 내용은 Docker 이미지 제공: CodeBuild 단원을 참조하십시오.

참고

빌드 컨테이너에서 도커를 사용할 경우에는 권한이 있는 모드에서 빌드가 실행되어야 합니다. 자세한 내용은 AWS CodeBuild에서 빌드 실행AWS CodeBuild에서 빌드 프로젝트 생성 섹션을 참조하세요.

런타임 버전 업데이트

buildspec 파일의 runtime-versions 섹션을 업데이트하여 프로젝트에서 사용되는 런타임을 새 버전으로 수정할 수 있습니다. 다음 예제는 Java 버전 8 및 11을 지정하는 방법을 보여 줍니다.

  • Java 버전 8을 지정하는 runtime-versions 부분:

    phases: install: runtime-versions: java: corretto8
  • Java 버전 11을 지정하는 runtime-versions 부분:

    phases: install: runtime-versions: java: corretto11

다음 예제는 Ubuntu 표준 이미지 5.0 또는 Amazon Linux 2 표준 이미지 3.0을 사용하여 Python의 다양한 버전을 지정하는 방법을 보여 줍니다.

  • Python 버전 3.7을 지정하는 runtime-versions 섹션:

    phases: install: runtime-versions: python: 3.7
  • Python 버전 3.8을 지정하는 runtime-versions 섹션:

    phases: install: runtime-versions: python: 3.8

이 샘플은 Java 버전 8 런타임으로 시작해서 이후 Java 버전 10 런타임으로 업데이트되는 프로젝트를 보여줍니다.

  1. Maven을 다운로드하고 설치합니다. 자세한 정보는 Apache Maven 웹 사이트의 Downloading Apache MavenInstalling Apache Maven 단원을 참조하십시오.

  2. 로컬 컴퓨터나 인스턴스의 빈 디렉터리로 전환한 다음, 아래 Maven 명령을 실행합니다.

    mvn archetype:generate "-DgroupId=com.mycompany.app" "-DartifactId=ROOT" "-DarchetypeArtifactId=maven-archetype-webapp" "-DinteractiveMode=false"

    성공하면 다음 디렉터리 구조 및 파일이 생성됩니다.

    . └── ROOT ├── pom.xml └── src └── main ├── resources └── webapp ├── WEB-INF │ └── web.xml └── index.jsp
  3. 다음 콘텐츠를 가진 buildspec.yml이라는 파일을 생성합니다: 파일을 (root directory name)/my-web-app 디렉터리에 저장합니다.

    version: 0.2 phases: install: runtime-versions: java: corretto8 build: commands: - java -version - mvn package artifacts: files: - '**/*' base-directory: 'target/my-web-app'

    buildspec 파일에서

    • runtime-versions 부분은 해당 프로젝트에서 Java 런타임 버전 8을 사용하도록 지정합니다.

    • - java -version 명령은 빌드할 때 프로젝트에서 사용하는 Java 버전을 표시합니다.

    파일 구조가 아래와 같이 나타날 것입니다.

    (root directory name) └── my-web-app ├── src │ ├── main │ ├── resources │ └── webapp │ └── WEB-INF │ └── web.xml │ └── index.jsp ├── buildspec.yml └── pom.xml
  4. my-web-app디렉터리의 콘텐츠를 S3 입력 버킷 CodeCommit GitHub, 또는 Bitbucket 리포지토리에 업로드합니다.

    중요

    (root directory name) 또는 (root directory name)/my-web-app은 업로드하지 말고, (root directory name)/my-web-app 안에 있는 디렉터리 및 파일만 업로드하십시오.

    S3 입력 버킷을 사용하고 있는 경우, 디렉터리 구조 및 파일을 포함하는 ZIP 파일을 생성한 다음, 이를 입력 버킷에 업로드합니다. (root directory name) 또는 (root directory name)/my-web-app을 ZIP 파일에 추가하지 말고, (root directory name)/my-web-app 안에 있는 디렉터리 및 파일만 추가하십시오.

  5. https://console.aws.amazon.com/codesuite/codebuild/home 에서 AWS CodeBuild 콘솔을 엽니다.

  6. 빌드 프로젝트를 생성합니다. 자세한 내용은 빌드 프로젝트 만들기(콘솔)빌드 실행(콘솔) 섹션을 참조하세요. 다음 설정을 제외하고 모든 설정을 기본값 그대로 둡니다.

    • 환경:

      • 환경 이미지에서 이미지 관리를 선택합니다.

      • 운영 체제에서 Amazon Linux 2를 선택합니다.

      • 런타임에서 표준을 선택합니다.

      • 이미지의 경우 aws/codebuild/amazonlinux2-x86_64-standard:4.0을 선택합니다.

  7. 빌드 시작를 선택합니다.

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

  9. 빌드가 완료되면 빌드 로그 탭에서 빌드 출력을 확인합니다. 다음과 유사한 출력 화면이 표시되어야 합니다.

    [Container] Date Time Phase is DOWNLOAD_SOURCE [Container] Date Time CODEBUILD_SRC_DIR=/codebuild/output/src460614277/src [Container] Date Time YAML location is /codebuild/output/src460614277/src/buildspec.yml [Container] Date Time Processing environment variables [Container] Date Time Selecting 'java' runtime version 'corretto8' based on manual selections... [Container] Date Time Running command echo "Installing Java version 8 ..." Installing Java version 8 ... [Container] Date Time Running command export JAVA_HOME="$JAVA_8_HOME" [Container] Date Time Running command export JRE_HOME="$JRE_8_HOME" [Container] Date Time Running command export JDK_HOME="$JDK_8_HOME" [Container] Date Time Running command for tool_path in "$JAVA_8_HOME"/bin/* "$JRE_8_HOME"/bin/*;
  10. Java 버전 11의 runtime-versions 부분 업데이트:

    install: runtime-versions: java: corretto11
  11. 변경을 저장한 후 빌드를 다시 실행하고 빌드 출력을 확인합니다. Java 설치 버전이 11인지 확인해야 합니다. 다음과 유사한 출력 화면이 표시되어야 합니다.

    [Container] Date Time Phase is DOWNLOAD_SOURCE [Container] Date Time CODEBUILD_SRC_DIR=/codebuild/output/src460614277/src [Container] Date Time YAML location is /codebuild/output/src460614277/src/buildspec.yml [Container] Date Time Processing environment variables [Container] Date Time Selecting 'java' runtime version 'corretto11' based on manual selections... Installing Java version 11 ... [Container] Date Time Running command export JAVA_HOME="$JAVA_11_HOME" [Container] Date Time Running command export JRE_HOME="$JRE_11_HOME" [Container] Date Time Running command export JDK_HOME="$JDK_11_HOME" [Container] Date Time Running command for tool_path in "$JAVA_11_HOME"/bin/* "$JRE_11_HOME"/bin/*;

런타임 2개 지정

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

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

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

  3. 다음 콘텐츠를 가진 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") }
  4. my-source 디렉터리 안에 이름이 nodejs-app인 디렉터리를 생성합니다. golang-app 디렉터리와 레벨이 같아야 합니다.

  5. 다음 콘텐츠를 가진 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");
  6. 다음 콘텐츠를 가진 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" }
  7. 다음 콘텐츠를 가진 buildspec.yml이라는 파일을 생성합니다: my-source 디렉터리에, nodejs-appgolang-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
  8. 파일 구조가 아래와 같이 나타날 것입니다.

    my-source ├── golang-app │ └── hello.go ├── nodejs.app │ ├── index.js │ └── package.json └── buildspec.yml
  9. my-source디렉터리의 콘텐츠를 S3 입력 버킷 또는 CodeCommit GitHub, 또는 Bitbucket 리포지토리에 업로드합니다.

    중요

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

  10. https://console.aws.amazon.com/codesuite/codebuild/home 에서 AWS CodeBuild 콘솔을 엽니다.

  11. 빌드 프로젝트를 생성합니다. 자세한 내용은 빌드 프로젝트 만들기(콘솔)빌드 실행(콘솔) 섹션을 참조하세요. 다음 설정을 제외하고 모든 설정을 기본값 그대로 둡니다.

    • 환경:

      • 환경 이미지에서 이미지 관리를 선택합니다.

      • 운영 체제에서 Amazon Linux 2를 선택합니다.

      • 런타임에서 표준을 선택합니다.

      • 이미지의 경우 aws/codebuild/amazonlinux2-x86_64-standard:4.0을 선택합니다.

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

  13. 빌드 시작를 선택합니다.

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

  15. 빌드가 완료되면 빌드 로그 탭에서 빌드 출력을 확인합니다. 다음과 유사한 출력 화면이 표시되어야 합니다. 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