Tentukan dua runtime - AWS CodeBuild

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

Tentukan dua runtime

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.

  2. Di dalam my-source direktori, buat direktori bernamagolang-app.

  3. 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") }
  4. Di dalam my-source direktori, buat direktori bernamanodejs-app. Itu harus pada tingkat yang sama dengan golang-app direktori.

  5. 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");
  6. 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" }
  7. 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-versionsBagian 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
  8. Struktur file Anda sekarang akan terlihat seperti ini.

    my-source ├── golang-app │ └── hello.go ├── nodejs.app │ ├── index.js │ └── package.json └── buildspec.yml
  9. 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 ZIP file yang berisi struktur direktori dan file, lalu unggah ke bucket input. Jangan tambahkan my-source ke ZIP file, hanya direktori dan file dimy-source.

  10. Buka AWS CodeBuild konsol di https://console.aws.amazon.com/codesuite/codebuild/home.

  11. Buat proyek build. Untuk informasi selengkapnya, silakan lihat Buat proyek build (konsol) dan Menjalankan build (konsol). 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/amazonlinux2-x86_64-standard:4.0.

  12. Pilih Buat proyek build.

  13. Pilih Mulai membangun.

  14. Pada konfigurasi Build, terima default, lalu pilih Start build.

  15. 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