【ヒント】CI/CDパイプラインにおけるPipインストール問題のトラブルシューティング
By JoeVu, at: 2024年9月20日17:38
Estimated Reading Time: __READING_TIME__ minutes
![[TIPS] Troubleshooting Pip Installation Issues in CI/CD Pipelines](/media/filer_public_thumbnails/filer_public/2e/79/2e79498b-5628-4425-a716-0d72bb726268/celery_-_pip_issues.png__1500x900_crop_subsampling-2_upscale.png)
![[TIPS] Troubleshooting Pip Installation Issues in CI/CD Pipelines](/media/filer_public_thumbnails/filer_public/2e/79/2e79498b-5628-4425-a716-0d72bb726268/celery_-_pip_issues.png__400x240_crop_subsampling-2_upscale.png)
CI/CDパイプラインにおけるPipインストール問題のトラブルシューティング
問題
DjangoアプリケーションのGitLabにおけるCI/CDパイプラインで問題が発生しました。数ヶ月間問題なく動作していたパイプラインが、pip install -r requirements.txt
ステップで突然失敗するようになりました。エラーログはCelery==5.1.0のインストールに関する問題を示していました。
Requested celery==5.1.0 from https://files.pythonhosted.org/packages/b4/f3/884b0b5bd46bc9d9721076c060b2ea37b2f95fdb6edb01e7fcda3def56dc/celery-5.1.0-py3-none-any.whl (from -r requirements.txt (line 34)) has invalid metadata: Expected matching RIGHT_PARENTHESIS for LEFT_PARENTHESIS, after version specifier
pytz (>dev)
~^
Please use pip<24.1 if you need to use this version.
ERROR: Ignored the following yanked versions: 5.0.6, 5.2.5
ERROR: Ignored the following versions that require a different python version: 5.0 Requires-Python >=3.10; 5.0.1 Requires-Python >=3.10; 5.0.2 Requires-Python >=3.10; 5.0.3 Requires-Python >=3.10; 5.0.4 Requires-Python >=3.10; 5.0.5 Requires-Python >=3.10; 5.0.6 Requires-Python >=3.10; 5.0.7 Requires-Python >=3.10; 5.0.8 Requires-Python >=3.10; 5.0a1 Requires-Python >=3.10; 5.0b1 Requires-Python >=3.10; 5.0rc1 Requires-Python >=3.10; 5.1 Requires-Python >=3.10; 5.1a1 Requires-Python >=3.10; 5.1b1 Requires-Python >=3.10; 5.1rc1 Requires-Python >=3.10
これは非常に奇妙なことで、Celeryバージョン5.1.0は存在し、私は長年使用してきました。
根本原因
この問題は、pipバージョン24.2とCelery==5.1.0の非互換性が原因でした。エラーログによると、pipはバージョンミスマッチのためにCeleryのメタデータを正しく解析できず、インストールが失敗しました。
参考リンク:https://github.com/celery/celery/discussions/9112
解決策
この問題を解決するために、CI/CDパイプラインを修正し、最新バージョン(24.2(2024年8月16日現在))にアップグレードする代わりに、pipバージョン24.0をインストールするように変更しました。これにより問題は解決し、パイプラインはCeleryを含むすべての依存関係を正常にインストールしました。
Create venv and upgrade pip:
stage: build
rules:
- if: $CI_COMMIT_BRANCH == "develop"
when: manual
tags:
- test
script:
- rm -R venv
- python3.8 -m venv venv
- venv/bin/pip3 install -U pip==24.0 --force
- venv/bin/pip3 install wheel
教訓
CI/CDパイプラインを維持管理する際には、使用しているツールの変更を監視することが重要です。この場合、pipのバージョンのアップグレードによって、長期間安定していたパッケージとの非互換性が発生しました。以前のpipバージョンにロールバックすることで、上流での修正を待つ間、またはパッケージのアップグレードの準備をする間、パイプラインの安定性を維持することができました。
同様の問題に直面している人のために、既存の依存関係で動作する安定したリリースにpipバージョンを固定してみてください。これにより、予期しない失敗を防ぎ、CI/CDパイプラインを円滑に実行し続けることができます。