0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CodeBuild × Node.js

Last updated at Posted at 2021-10-06

事前準備

  • CodeBuildを構築する前に以下の設定を実施
  • ビルドしたファイルをS3に保存する為のS3を作成
  • VPCへのアクセスの為にSubnetにNATを設定
  • なお、CodeBuild構築中に「サービスロール」の作成も実施される為、作成するユーザのIAMのアクセス権に「IAMFullAccess」も必要

配置用S3作成

名前とリージョン
バケット名 リージョン
example-codebuild-output アジアンパシフィック(東京)
プロパティ設定
バージョニング サーバアクセスのログ記録 Tags オブジェクトレベルのログ記録 デフォルト暗号化
無効 無効 0 Tags 無効 無効

※デフォルト

アクセス許可の設定
  • ユーザを管理
ユーザID オブジェクト オブジェクトへのアクセス許可
gpl_example_ml(所有者) 読み込み書き込み 読み込み書き込み
他のAWSアカウントのアクセス
アカウント オブジェクト オブジェクトへのアクセス許可
なし なし なし
パブリックアクセス許可を管理
このバケットにパブリック読み取りアクセス権限を付与しない(推奨)
システムのアクセス許可の管理
Amazon S3 ログ配信グループにこのバケットへの書き込み権限を付与しない

NAT設定

NATゲートウェイ作成
  • PublicサブネットにNATゲートウェイを作成
サブネット Elastic IP割り当てID Name NATゲートウェイID
subnet-xxxxxx example-public-subnet eipalloc-xxxxxxxx(EIPの作成ボタンから作成) example-nat-gateway
ルートテーブルへのNATゲートウェイ追加
  • VPC作成時にデフォルトで作成されたルートテーブルのルートに上記作成したNATゲートウェイを追加
送信先 ターゲット
0.0.0.0/0 nat-xxxxxxxxxxxxxxx
CodeBuild設定

ビルドプロジェクト作成

  • CodeBuild設定は、Gulpでのjs及びcss生成目的
大項目 中項目 設定値
プロジェクトの設定 プロジェクト名 example-xxxxxx-codebuild
ソースビルド:対象 ソースプロバイダ AWS CodeCommit
リポジトリ example-xxxxxx-repository
バッチ なし
環境:ビルド方法 環境イメージ AWS CodeBuild によって管理されたイメージの使用
オペレーティングシステム Ubuntu
ランタイム Node.js
ランタイムバージョン aws/codebuild/nodejs:7.0.0
特権付与 チェックしない
ビルド仕様 ソースコードのルートディレクトリのbuildspec.ymlを使用
buildspec名 buildspec.yml
アーティファクト タイプ Amazon S3
名前 example-xxxxxx-codebuild_artifact.zip
パス なし
名前空間のタイプ ビルドID
バケット名 example-xxxxxx-codebuild-output
キャッシュ タイプ
サービスロール アカウントでサービスロール作成
ロール名 codebuild-example-xxxxxx-codebuild-service-role
VPC VPC vpc-xxxxxxxx
サブネット 複数選択可 subnet-xxxxx ,ap-northeast-1a ,example-private-subnet-1
サブネット 複数選択可 subnet-yyyyy ,ap-northeast-1c ,example-private-subnet-2
サブネット ※NATインターフェースを設定したルートテーブルにあるサブネットを設定する
セキュリティーグループ 以下を選択(複数選択可)
sg-xxxxxxxxxx default
sg-yyyyyyyyyy example-web-sg
詳細設定 ほぼデフォルト設定のまま(パッケージングだけZipに変更)
ビルドタイムアウト 60分
暗号化キー デフォルトキー
パッケージング Zip
コンピューティングタイプ 3GBメモリ、2vCPU
バッチ 無効

buildspec.yml作成

  • buildspec.ymlファイルを作成
    CodeCommitリポジトリのルートフォルダに格納
version: 0.1
phases:
  install:
    commands:
      - npm install -g gulp
  pre_build:
    commands:
      - npm install
  build:
    commands:
      - echo Build started on `date`
      - node -v
      - npm -v
      - gulp -v
      - echo Compiling the js and css code
      - gulp build
  post_build:
    commands:
      - echo Build completed on `date`
artifacts:
  files:
    - 'app/**/*'
    - 'common/**/*'
    - 'etc/**/*'
    - 'appspec.yml'
関連
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?