LoginSignup
0
1

CI / CD パイプラインのエラー奮闘記

Posted at

はじめに

学習用のサイトが完成しCI / CD パイプラインを GitHubActionsで構築しようとしたところエラーがでてうまくできませんでした。
バックエンド・フロントエンド両方でエラーが出ていてビックリしました 笑
その時の奮闘記になります。

もくじ

1. 開発環境
2. バックエンド(Rails)
3. フロントエンド(Next)
4. まとめ
5. 参考

開発環境

・フロント・バックエンドなど
nginx
docker
Next.js 14.2.1
Ruby on Rails 7.0.8.1

・デプロイ先
AWS
GitHubActions (CI/CDパイプライン)

・使用PC
Macbookpro M3
WSL Ubuntu

バックエンド(Rails)

GitHubActionのエラー内容
・Deploy Amazon ECS task definition

Please migrate your code to use AWS SDK for JavaScript (v3).
For more information, check blog post at https://a.co/cUPnyil
(Use `node --trace-warnings ...` to show where the warning was created
Error: arn:aws:ecs:ap-northeast-1:***:service/backend-service is MISSING

エラー内容はbackend-serviceがないとのこと。
AWSのECSでService Nameと照合したら、名前が間違っていました。

・ECS_SERVICE_BACKENDを訂正

.github/workflow/cd.yml


env:
  AWS_REGION: ap-northeast-1
  ECS_CLUSTER: app-cluster
  ECS_SERVICE_BACKEND: backend-task-service
  ECS_SERVICE_FRONTEND: frontend-service


フロントエンド(Next.js)

GitHubActionのエラー内容
・Build, tag, and push image to Amazon ECR

#14 1.218   ▲ Next.js 14.2.1
#14 1.218   - Environments: .env.production
#14 1.219 
#14 1.219    Linting and checking validity of types ...
#14 8.906    Creating an optimized production build ...
#14 9.538    Disabled SWC as replacement for Babel because of custom Babel configuration ".babelrc" https://nextjs.org/docs/messages/swc-disabled
#14 10.02    Using external babel configuration from /app/.babelrc
#14 11.85  ⚠ Attempted to load @next/swc-linux-x64-gnu, but an error occurred: /app/node_modules/@next/swc-linux-x64-gnu/next-swc.linux-x64-gnu.node: invalid ELF header
#14 11.85  ⚠ Attempted to load @next/swc-linux-x64-musl, but an error occurred: /app/node_modules/@next/swc-linux-x64-musl/next-swc.linux-x64-musl.node: invalid ELF header
#14 12.03  ⨯ Failed to load SWC binary for linux/x64, see more info here: https://nextjs.org/docs/messages/failed-loading-swc
#14 12.06 
#14 12.06 > Build error occurred
#14 12.06 Error: Jest worker encountered 1 child process exceptions, exceeding retry limit
#14 12.06     at ChildProcessWorker.initialize (/app/node_modules/next/dist/compiled/jest-worker/index.js:1:11580)
#14 12.06     at ChildProcessWorker._onExit (/app/node_modules/next/dist/compiled/jest-worker/index.js:1:12545)
#14 12.06     at ChildProcess.emit (node:events:525:35)
#14 12.06     at ChildProcess._handle.onexit (node:internal/child_process:293:12) {
#14 12.06   type: 'WorkerError'
#14 12.06 }
#14 ERROR: process "/bin/sh -c npm run build" did not complete successfully: exit code: 1
・
・
・
ERROR: failed to solve: process "/bin/sh -c npm run build" did not complete successfully: exit code: 1
Error: Process completed with exit code 1.

SWC関連でエラーになっているので無効にすると直るらしい。以下設定箇所

next.json.js
module.exports = {
  swcMinify: false // 追記
}
.babelrc
{
  "presets": ["next/babel"]
}

dockerを再起動したが直らず...

さらに調べてみるとSWCはPC環境ごとに構築しないとうまく動作しないらしい。
SWCはnode_moduleにあり、このフォルダごとGitHubにアップしてしまっていた。
結果、WSLとGitのswc-linuxが競合しイメージ作成時に失敗したと考えられる。

対策としてnode_moduleをgit pushから除外することにした。

.gitgnore
# 指定のディレクトリを除外する
node_modules

こうすることで無事解決しました!

まとめ

1. AWSとcd.ymlの名前をよく確認する。
2. node_moduleはGitHubにアップロードしない。.gitgnoreで除外設定する。

参考

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