1
1

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 1 year has passed since last update.

GitHub ActionsでAWS CDKが動かなくてハマった話

Posted at

書いてあること

GitHub ActionsでAWSのCDKを使ってデプロイの差分を取得しようとしたらエラーが出て解決に数日かかってしまった。
ネットで調べても解決策がヒットせず、色々試行錯誤してようやく解決した。
もし同じような問題が起きて困っている人は参考にしてほしい。

エラーが出るCIのファイル

ci.yml
name: CI

on:
  pull_request:
    branches: [main]

jobs:
  diff:
    name: Diff
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18.x'

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ap-northeast-1

      - name: diff
        working-directory: ./
        run : |
          npm ci
          npm run cdk-diff

実際に出たエラー

上記CIを動かすと、このエラーが出る。yarnのインストールに失敗?そんなことある?
エラーメッセージでググっても良い解決策が見つからない。

#5 [ 2/10] RUN npm install --global yarn@1.22.5
#5 0.214 exec /bin/sh: exec format error
#5 ERROR: process "/bin/sh -c npm install --global yarn@1.22.5" did not complete successfully: exit code: 1
------
 > [ 2/10] RUN npm install --global yarn@1.22.5:
0.214 exec /bin/sh: exec format error
------
Dockerfile:7
--------------------
   5 |     
   6 |     # Install yarn
   7 | >>> RUN npm install --global yarn@1.22.5
   8 |     
   9 |     # Install pnpm
--------------------
ERROR: failed to solve: process "/bin/sh -c npm install --global yarn@1.22.5" did not complete successfully: exit code: 1
/home/runner/work/hoge/hoge/node_modules/aws-cdk-lib/core/lib/private/asset-staging.js:2
`).map((line,idx)=>`${idx===0?firstLine:padding}${line}`)};const reason=proc.signal!=null?`signal ${proc.signal}`:`status ${proc.status}`,command=[prog,...args.map(arg=>/[^a-z0-9_-]/i.test(arg)?JSON.stringify(arg):arg)].join(" ");throw new Error([`${prog} exited with ${reason}`,...prependLines("--> STDOUT:  ",proc.stdout)??[],...prependLines("--> STDERR:  ",proc.stderr)??[],`--> Command: ${command}`].join(`
                                                                                                                                                                                                                                            ^
Error: docker exited with status 1
--> Command: docker build -t cdk-e4d4c769de205f6558dd8adc010a0a517a8ae893f27262ab6dbe3fed349afb5e --platform "linux/arm64" --build-arg "IMAGE=public.ecr.aws/sam/build-nodejs18.x" --build-arg "ESBUILD_VERSION=0" "/home/runner/work/hoge/hoge/node_modules/aws-cdk-lib/aws-lambda-nodejs/lib"
    at dockerExec (/home/runner/work/hoge/hoge/node_modules/aws-cdk-lib/core/lib/private/asset-staging.js:2:237)
    at Function.fromBuild (/home/runner/work/hoge/hoge/node_modules/aws-cdk-lib/core/lib/bundling.js:1:4364)
    at new Bundling (/home/runner/work/hoge/hoge/node_modules/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.js:1:3393)
    at Function.bundle (/home/runner/work/hoge/hoge/node_modules/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.js:1:605)
    at new NodejsFunction (/home/runner/work/hoge/hoge/node_modules/aws-cdk-lib/aws-lambda-nodejs/lib/function.js:1:1273)
    at new HogeCdkStack (/home/runner/work/hoge/hoge/lib/hoge-cdk-stack.ts:114:28)
    at Object.<anonymous> (/home/runner/work/hoge/hoge/bin/hoge-cdk.ts:23:23)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module.m._compile (/home/runner/work/hoge/hoge/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
[06:13:43] Notices refreshed
[06:13:43] Failed to store notices in the cache: Error: ENOENT: no such file or directory, open '/home/runner/.cdk/cache/notices.json'

Subprocess exited with error 1
[06:13:43] Error: Subprocess exited with error 1
    at ChildProcess.<anonymous> (/opt/hostedtoolcache/node/18.17.1/x64/lib/node_modules/aws-cdk/lib/index.js:445:50448)
    at ChildProcess.emit (node:events:514:28)
    at ChildProcess.emit (node:domain:489:12)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12)
Error: Process completed with exit code 1.

解決策

ci.ymlにこれを追加した

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2
        with:
          platforms: linux/arm64
ci.yml
name: CI

on:
  pull_request:
    branches: [main]

jobs:
  diff:
    name: Diff
    runs-on: ubuntu-latest

    steps:
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2
        with:
          platforms: linux/arm64
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18.x'

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ap-northeast-1

      - name: diff
        working-directory: ./
        run : |
          npm ci
          npm run cdk-diff

これでようやくCIが通った。3,4日悩んだけど解決した。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?