LoginSignup
2
0

More than 1 year has passed since last update.

ドッカ―コンテナが「exit code 1」のとき、GitHub Actionsのステップが終わらなかった件について

Posted at

はじめに

前回の記事「Github ActionsでSpring Bootのテストコードを検証する」のためのサンプルコードを作成したところ、
GitHub Actions上でdocker-compose upするとテストが失敗してもアクションがsuccessになりました。
image.png
>詳細結果
ということで、その原因と解決方法について調査してみました。

原因

Nonzero value (any integer but 0) failure Any other exit code indicates the action failed. When an action fails, all concurrent actions are canceled and future actions are skipped. The check run and check suite both get a failure status.

GitHub Actionsドキュメントによりますと、exit code 0以外はアクション失敗になりますけど、
どうやら単純なdocker-compose upではコンテナの起動が失敗してもGitHub Actionsでは「問題なし」と見なされるようです。
なので、GitHub Actionsにコンテナのexit codeが1であることを知らせる必要があります。

解決方法

docker-compose upに以下のいずれかのオプションをつければOKです。

--exit-code-from

  • 意味:指定したコンテナのexit codeを返却
  • 例:--exit-code-from (対象になるコンテナ名)
  • 私の場合はSpring Bootアプリケーションが存在するコンテナ名がwebなので
    docker-compose up --exit-code-from webと記入しました。
  • 詳細結果

--abort-on-container-exit

  • 意味:起動するコンテナの中で一つでも停止されたらすべてのコンテナを停止する
  • 解決方法をググったら上のオプションの方法がよくみられますが、一応このオプションもいけます。
  • 詳細結果

おわりに

サンプルコードやActionsの結果は以下のレポジトリでご確認してください!
https://github.com/crane93/github-actions-spring-boot

参考になった記事

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