fix: Replace jq with Python for PHP version parsing
All checks were successful
Helm Chart Release / release-chart (push) Successful in 12s
All checks were successful
Helm Chart Release / release-chart (push) Successful in 12s
jqが利用できない環境でも動作するよう、Python3に変更。 Changes: - jqの依存を削除 - Python3でDocker Hub APIレスポンスをパース - 正規表現パターンマッチングをPythonで実装 - バージョンソートをPythonで実装 - デバッグ出力を追加(利用可能なタグ、マッチ数) Benefits: - 追加パッケージのインストール不要 - デバッグ情報が詳細 - より確実な動作 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -51,24 +51,47 @@ jobs:
|
|||||||
|
|
||||||
# Docker Hub API v2を使用してタグを取得
|
# Docker Hub API v2を使用してタグを取得
|
||||||
echo "Fetching tags from Docker Hub..."
|
echo "Fetching tags from Docker Hub..."
|
||||||
RAW_RESPONSE=$(curl -s "https://registry.hub.docker.com/v2/repositories/library/php/tags?page_size=100")
|
|
||||||
|
|
||||||
# デバッグ: jqが利用可能か確認
|
# Pythonを使用してJSONをパースし、タグを抽出
|
||||||
if ! command -v jq &> /dev/null; then
|
LATEST=$(python3 << 'PYTHON_SCRIPT'
|
||||||
echo "ERROR: jq is not installed"
|
import sys
|
||||||
echo "Installing jq..."
|
import urllib.request
|
||||||
apt-get update && apt-get install -y jq
|
import json
|
||||||
fi
|
import re
|
||||||
|
|
||||||
# タグ一覧を取得してデバッグ出力
|
url = "https://registry.hub.docker.com/v2/repositories/library/php/tags?page_size=100"
|
||||||
echo "DEBUG: Available PHP tags (first 10):"
|
try:
|
||||||
echo "$RAW_RESPONSE" | jq -r '.results[].name' | grep 'fpm-alpine' | head -10
|
with urllib.request.urlopen(url) as response:
|
||||||
|
data = json.loads(response.read())
|
||||||
|
tags = [result['name'] for result in data.get('results', [])]
|
||||||
|
|
||||||
# パターン: 8.5.2-fpm-alpine3.23 形式(alpineバージョンは2-3桁に対応)
|
# パターン: 8.5.2-fpm-alpine3.23 形式
|
||||||
LATEST=$(echo "$RAW_RESPONSE" | \
|
pattern = re.compile(r'^\d+\.\d+\.\d+-fpm-alpine\d+\.\d{2,3}$')
|
||||||
jq -r '.results[].name' | \
|
matching_tags = [tag for tag in tags if pattern.match(tag)]
|
||||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+-fpm-alpine[0-9]+\.[0-9]{2,3}$' | \
|
|
||||||
sort -V | tail -1)
|
# デバッグ出力
|
||||||
|
print("DEBUG: Available PHP tags (first 10):", file=sys.stderr)
|
||||||
|
for tag in [t for t in tags if 'fpm-alpine' in t][:10]:
|
||||||
|
print(f" {tag}", file=sys.stderr)
|
||||||
|
|
||||||
|
print(f"DEBUG: Matching tags count: {len(matching_tags)}", file=sys.stderr)
|
||||||
|
|
||||||
|
if matching_tags:
|
||||||
|
# バージョンソート
|
||||||
|
def version_key(tag):
|
||||||
|
parts = tag.split('-')[0].split('.')
|
||||||
|
return tuple(int(p) for p in parts)
|
||||||
|
|
||||||
|
sorted_tags = sorted(matching_tags, key=version_key)
|
||||||
|
latest = sorted_tags[-1]
|
||||||
|
print(latest)
|
||||||
|
else:
|
||||||
|
print("", end="")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR: {e}", file=sys.stderr)
|
||||||
|
print("", end="")
|
||||||
|
PYTHON_SCRIPT
|
||||||
|
)
|
||||||
|
|
||||||
echo "DEBUG: Matched LATEST=$LATEST"
|
echo "DEBUG: Matched LATEST=$LATEST"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user