🐁
AWS CodeBuild でGo の CI を実行する
はじめに
AWS CodeBuild で Go 1.21.0 の CI を実行する環境を立てたのでそのメモです。
前提
- 利用する Docker イメージ
- aws/codebuild/amazonlinux2-aarch64-standard:3.0
- この環境イメージを CodeBuild で設定する
- aws/codebuild/amazonlinux2-aarch64-standard:3.0
- Go のバージョン
- 1.21.0
Buildspec
point:
- Go 1.21.0 は公式イメージに含まれていないので自分でインストールする必要がある
version: 0.2
env:
variables:
GOLANG_21_VERSION: "1.21.0"
phases:
install:
commands:
- wget https://go.dev/dl/go${GOLANG_21_VERSION}.linux-arm64.tar.gz -O /tmp/golang.tar.gz
- tar -xzf /tmp/golang.tar.gz -C /tmp
- mv /tmp/go /usr/local/go21
- rm -rf /usr/local/go
- ln -s /usr/local/go21 /usr/local/go
build:
commands:
- make build
- make lint
- make test
install phase は 公式 Docker イメージの Dockerfile を参考にした(チェックサムの検証は省いたが、やった方が良いです...)。
おまけ: Go 1.20 の場合
point:
- Go 1.20 & aws/codebuild/amazonlinux2-aarch64-standard:3.0 環境の場合も、Buildspec の工夫が必要。
- runtime-versions で
golang: 1.20
を設定しても、Go 1.20 を使えない- 理由: Go 1.20 symlink のパスが間違っているというバグがあるから
- 問題箇所 runtimes.yml
- 理由: Go 1.20 symlink のパスが間違っているというバグがあるから
- 解決策: Buildspec で symlink を張り直す
version: 0.2
phases:
install:
commands:
- rm -rf /usr/local/go
- ln -s /usr/local/go20 /usr/local/go
build:
commands:
- make build
- make lint
- make test
Bug を修正する PR はすでにでているので、近いうちに修正されると思います。
Discussion