feat: チャートをゼロから再設計(外部DB前提のYOURLS+Nginx構成に作り直し)
Helm Chart Release / release-chart (push) Successful in 7s
Helm Chart Release / release-chart (push) Successful in 7s
旧チャートは存在しないDocker Hubイメージ(yourls/yourls)を参照し、Bitnami MySQL サブチャートに依存するなど正しく動作しない状態だったため、YOURLS公式イメージ (docker.io/yourls, container-entrypoint.sh/config-container.php)の実装を確認した上で WordPressチャートと同一方針(外部DB、emptyDir+PVC分離、fsGroup非root実行、 real IP取得対応)でスクラッチから再構築した。
This commit is contained in:
@@ -2,96 +2,113 @@ name: Update Docker Image Tags and Release Helm Chart
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 4 * * 1' # 毎週月曜日 4:00 AM (JST 1:00 PM)
|
||||
- cron: "0 4 * * 1" # 毎週月曜日 04:00 UTC (JST 13:00)
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
update-and-release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Helm
|
||||
uses: azure/setup-helm@v3
|
||||
with:
|
||||
version: 'v3.12.0'
|
||||
|
||||
- name: Check for new nginx version
|
||||
id: nginx
|
||||
run: |
|
||||
set -e
|
||||
echo "Checking nginx versions..."
|
||||
CURRENT=$(grep -A3 "nginx:" values.yaml | grep "tag:" | head -1 | sed 's/.*tag: *"\([^"]*\)".*/\1/' | tr -d ' ')
|
||||
echo "Current nginx: $CURRENT"
|
||||
|
||||
# Docker Hub API v2を使用してタグを取得
|
||||
LATEST=$(curl -s "https://registry.hub.docker.com/v2/repositories/library/nginx/tags?page_size=100" | \
|
||||
jq -r '.results[].name' | \
|
||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+-alpine-perl$' | \
|
||||
sort -V | tail -1)
|
||||
|
||||
if [ -z "$LATEST" ]; then
|
||||
echo "Warning: Could not fetch latest nginx version, using current"
|
||||
LATEST="$CURRENT"
|
||||
fi
|
||||
echo "Latest nginx: $LATEST"
|
||||
echo "current=$CURRENT" >> $GITHUB_OUTPUT
|
||||
echo "latest=$LATEST" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Check for new YOURLS version
|
||||
- name: Check for new YOURLS FPM Alpine version
|
||||
id: yourls
|
||||
run: |
|
||||
set -e
|
||||
echo "Checking YOURLS versions..."
|
||||
echo "Checking YOURLS fpm-alpine versions..."
|
||||
CURRENT=$(grep -A3 "yourls:" values.yaml | grep "tag:" | head -1 | sed 's/.*tag: *"\([^"]*\)".*/\1/' | tr -d ' ')
|
||||
echo "Current YOURLS: $CURRENT"
|
||||
|
||||
# Docker Hub API v2を使用してタグを取得
|
||||
# パターン: 1.10.2-fpm-alpine 形式
|
||||
LATEST=$(curl -s "https://registry.hub.docker.com/v2/repositories/yourls/yourls/tags?page_size=100" | \
|
||||
|
||||
# 公式イメージは docker.io/yourls (docker-library配下)。
|
||||
# docker.io/yourls/yourls という別名前空間のイメージは非公式のため使用しない。
|
||||
LATEST=$(curl -s "https://hub.docker.com/v2/repositories/library/yourls/tags?page_size=100&name=fpm-alpine" | \
|
||||
jq -r '.results[].name' | \
|
||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+-fpm-alpine$' | \
|
||||
sort -V | tail -1)
|
||||
|
||||
grep -v 'rc' | \
|
||||
grep -v 'beta' | \
|
||||
grep -v 'alpha' | \
|
||||
sort -V | \
|
||||
tail -n 1)
|
||||
|
||||
if [ -z "$LATEST" ]; then
|
||||
echo "Warning: Could not fetch latest YOURLS version, using current"
|
||||
LATEST="$CURRENT"
|
||||
fi
|
||||
|
||||
# YOURLSバージョンを抽出 (1.10.2の部分)
|
||||
|
||||
APP_VERSION=$(echo "$LATEST" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
|
||||
if [ -z "$APP_VERSION" ]; then
|
||||
echo "Error: Could not extract YOURLS version"
|
||||
exit 1
|
||||
echo "Warning: Could not extract YOURLS version from: $LATEST"
|
||||
APP_VERSION=$(echo "$CURRENT" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
|
||||
fi
|
||||
|
||||
|
||||
echo "Latest YOURLS: $LATEST"
|
||||
echo "YOURLS version: $APP_VERSION"
|
||||
|
||||
echo "current=$CURRENT" >> $GITHUB_OUTPUT
|
||||
echo "latest=$LATEST" >> $GITHUB_OUTPUT
|
||||
echo "app_version=$APP_VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Check for new Nginx Alpine Perl version
|
||||
id: nginx
|
||||
run: |
|
||||
set -e
|
||||
echo "Checking Nginx Alpine Perl versions..."
|
||||
CURRENT=$(grep -A3 "nginx:" values.yaml | grep "tag:" | head -1 | sed 's/.*tag: *"\([^"]*\)".*/\1/' | tr -d ' ')
|
||||
echo "Current Nginx: $CURRENT"
|
||||
|
||||
LATEST=$(curl -s "https://hub.docker.com/v2/repositories/library/nginx/tags?page_size=100&name=alpine-perl" | \
|
||||
jq -r '.results[].name' | \
|
||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+-alpine-perl$' | \
|
||||
grep -v 'rc' | \
|
||||
grep -v 'beta' | \
|
||||
grep -v 'alpha' | \
|
||||
sort -V | \
|
||||
tail -n 1)
|
||||
|
||||
if [ -z "$LATEST" ]; then
|
||||
echo "Warning: Could not fetch latest Nginx version, using current"
|
||||
LATEST="$CURRENT"
|
||||
fi
|
||||
echo "Latest Nginx: $LATEST"
|
||||
echo "current=$CURRENT" >> $GITHUB_OUTPUT
|
||||
echo "latest=$LATEST" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Determine if update is needed
|
||||
id: check_update
|
||||
run: |
|
||||
set -e
|
||||
NGINX_CURRENT="${{ steps.nginx.outputs.current }}"
|
||||
NGINX_LATEST="${{ steps.nginx.outputs.latest }}"
|
||||
YOURLS_CURRENT="${{ steps.yourls.outputs.current }}"
|
||||
YOURLS_LATEST="${{ steps.yourls.outputs.latest }}"
|
||||
|
||||
echo "Nginx: $NGINX_CURRENT vs $NGINX_LATEST"
|
||||
NGINX_CURRENT="${{ steps.nginx.outputs.current }}"
|
||||
NGINX_LATEST="${{ steps.nginx.outputs.latest }}"
|
||||
|
||||
echo "YOURLS: $YOURLS_CURRENT vs $YOURLS_LATEST"
|
||||
|
||||
if [ "$NGINX_CURRENT" != "$NGINX_LATEST" ] || [ "$YOURLS_CURRENT" != "$YOURLS_LATEST" ]; then
|
||||
echo "update_needed=true" >> $GITHUB_OUTPUT
|
||||
echo "Nginx: $NGINX_CURRENT vs $NGINX_LATEST"
|
||||
|
||||
UPDATE_NEEDED=false
|
||||
YOURLS_UPDATED=false
|
||||
|
||||
if [ "$YOURLS_CURRENT" != "$YOURLS_LATEST" ]; then
|
||||
UPDATE_NEEDED=true
|
||||
YOURLS_UPDATED=true
|
||||
echo "YOURLS update detected"
|
||||
fi
|
||||
|
||||
if [ "$NGINX_CURRENT" != "$NGINX_LATEST" ]; then
|
||||
UPDATE_NEEDED=true
|
||||
echo "Nginx update detected"
|
||||
fi
|
||||
|
||||
echo "update_needed=$UPDATE_NEEDED" >> $GITHUB_OUTPUT
|
||||
echo "yourls_updated=$YOURLS_UPDATED" >> $GITHUB_OUTPUT
|
||||
|
||||
if [ "$UPDATE_NEEDED" = "true" ]; then
|
||||
echo "Update is needed"
|
||||
else
|
||||
echo "update_needed=false" >> $GITHUB_OUTPUT
|
||||
echo "Already up to date"
|
||||
echo "Already up to date - no action required"
|
||||
fi
|
||||
|
||||
- name: Update values.yaml
|
||||
@@ -99,37 +116,30 @@ jobs:
|
||||
run: |
|
||||
set -e
|
||||
echo "Updating values.yaml..."
|
||||
|
||||
# YOURLSバージョンを取得
|
||||
APP_VERSION="${{ steps.yourls.outputs.app_version }}"
|
||||
|
||||
# Nginx更新
|
||||
NGINX_OLD="${{ steps.nginx.outputs.current }}"
|
||||
NGINX_NEW="${{ steps.nginx.outputs.latest }}"
|
||||
if [ "$NGINX_OLD" != "$NGINX_NEW" ]; then
|
||||
# nginxセクションのtagのみを更新(1つ目のタグ)
|
||||
sed -i "0,/tag: \"${NGINX_OLD}\"/s//tag: \"${NGINX_NEW}\"/" values.yaml
|
||||
echo "Nginx updated: $NGINX_OLD -> $NGINX_NEW"
|
||||
fi
|
||||
|
||||
# YOURLS更新
|
||||
|
||||
YOURLS_OLD="${{ steps.yourls.outputs.current }}"
|
||||
YOURLS_NEW="${{ steps.yourls.outputs.latest }}"
|
||||
if [ "$YOURLS_OLD" != "$YOURLS_NEW" ]; then
|
||||
# yourlsセクションのtagのみを更新(2つ目のタグ)
|
||||
sed -i "0,/tag: \"${NGINX_NEW}\"/b; s/tag: \"${YOURLS_OLD}\"/tag: \"${YOURLS_NEW}\"/" values.yaml
|
||||
sed -i "s|tag: \"${YOURLS_OLD}\"|tag: \"${YOURLS_NEW}\"|g" values.yaml
|
||||
echo "YOURLS updated: $YOURLS_OLD -> $YOURLS_NEW"
|
||||
fi
|
||||
|
||||
|
||||
NGINX_OLD="${{ steps.nginx.outputs.current }}"
|
||||
NGINX_NEW="${{ steps.nginx.outputs.latest }}"
|
||||
if [ "$NGINX_OLD" != "$NGINX_NEW" ]; then
|
||||
sed -i "s|tag: \"${NGINX_OLD}\"|tag: \"${NGINX_NEW}\"|g" values.yaml
|
||||
echo "Nginx updated: $NGINX_OLD -> $NGINX_NEW"
|
||||
fi
|
||||
|
||||
echo "values.yaml updated"
|
||||
git diff values.yaml
|
||||
|
||||
- name: Update Chart.yaml version
|
||||
if: steps.check_update.outputs.update_needed == 'true'
|
||||
if: steps.check_update.outputs.yourls_updated == 'true'
|
||||
run: |
|
||||
set -e
|
||||
APP_VERSION="${{ steps.yourls.outputs.app_version }}"
|
||||
sed -i "s/^version: .*/version: \"$APP_VERSION\"/" Chart.yaml
|
||||
sed -i "s/^version: .*/version: $APP_VERSION/" Chart.yaml
|
||||
sed -i "s/^appVersion: .*/appVersion: \"$APP_VERSION\"/" Chart.yaml
|
||||
echo "Chart.yaml updated to version $APP_VERSION"
|
||||
cat Chart.yaml
|
||||
@@ -138,105 +148,128 @@ jobs:
|
||||
if: steps.check_update.outputs.update_needed == 'true'
|
||||
run: |
|
||||
git config user.name "Gitea Actions Bot"
|
||||
git config user.email "actions@gitea.local"
|
||||
git add values.yaml Chart.yaml
|
||||
git commit -m "chore: update to YOURLS ${{ steps.yourls.outputs.app_version }}, nginx ${{ steps.nginx.outputs.latest }}"
|
||||
git push origin main
|
||||
git config user.email "actions@git.cafepieters.com"
|
||||
|
||||
if [ "${{ steps.check_update.outputs.yourls_updated }}" = "true" ]; then
|
||||
git add values.yaml Chart.yaml
|
||||
git commit -m "chore: update to YOURLS ${{ steps.yourls.outputs.app_version }}, nginx ${{ steps.nginx.outputs.latest }}"
|
||||
else
|
||||
git add values.yaml
|
||||
git commit -m "chore: update nginx to ${{ steps.nginx.outputs.latest }} (no release)"
|
||||
fi
|
||||
|
||||
MAX_RETRIES=3
|
||||
RETRY_COUNT=0
|
||||
until git push origin main || [ $RETRY_COUNT -eq $MAX_RETRIES ]; do
|
||||
RETRY_COUNT=$((RETRY_COUNT+1))
|
||||
echo "Push failed, retrying ($RETRY_COUNT/$MAX_RETRIES)..."
|
||||
sleep 5
|
||||
git pull --rebase origin main
|
||||
done
|
||||
|
||||
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
|
||||
echo "ERROR: Failed to push after $MAX_RETRIES attempts"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Successfully pushed changes to main branch"
|
||||
|
||||
- name: Install Helm
|
||||
if: steps.check_update.outputs.yourls_updated == 'true'
|
||||
uses: azure/setup-helm@v3
|
||||
with:
|
||||
version: 'latest'
|
||||
|
||||
- name: Package Helm Chart
|
||||
if: steps.check_update.outputs.update_needed == 'true'
|
||||
if: steps.check_update.outputs.yourls_updated == 'true'
|
||||
run: |
|
||||
helm package .
|
||||
echo "Helm chart packaged"
|
||||
|
||||
- name: Create Git Tag
|
||||
if: steps.check_update.outputs.update_needed == 'true'
|
||||
if: steps.check_update.outputs.yourls_updated == 'true'
|
||||
run: |
|
||||
APP_VERSION="${{ steps.yourls.outputs.app_version }}"
|
||||
git tag -a "v$APP_VERSION" -m "Release YOURLS $APP_VERSION"
|
||||
git push origin "v$APP_VERSION"
|
||||
echo "Git tag v$APP_VERSION created"
|
||||
|
||||
if git rev-parse "v$APP_VERSION" >/dev/null 2>&1; then
|
||||
echo "Tag v$APP_VERSION already exists, skipping tag creation"
|
||||
else
|
||||
git tag -a "v$APP_VERSION" -m "Release YOURLS $APP_VERSION"
|
||||
git push origin "v$APP_VERSION"
|
||||
echo "Git tag v$APP_VERSION created"
|
||||
fi
|
||||
|
||||
- name: Create Gitea Release
|
||||
if: steps.check_update.outputs.update_needed == 'true'
|
||||
if: steps.check_update.outputs.yourls_updated == 'true'
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: |
|
||||
APP_VERSION="${{ steps.yourls.outputs.app_version }}"
|
||||
CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}')
|
||||
PACKAGE_FILE="${CHART_NAME}-${APP_VERSION}.tgz"
|
||||
RELEASE_BODY="YOURLS Helm Chart v${APP_VERSION} - YOURLS: ${{ steps.yourls.outputs.latest }}, Nginx: ${{ steps.nginx.outputs.latest }}"
|
||||
|
||||
# リリースを作成
|
||||
curl -X POST \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\":\"v${APP_VERSION}\",\"name\":\"v${APP_VERSION}\",\"body\":\"${RELEASE_BODY}\"}" \
|
||||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases"
|
||||
|
||||
# リリースIDを取得
|
||||
RELEASE_ID=$(curl -s \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/v${APP_VERSION}" | jq -r '.id')
|
||||
|
||||
# アセットをアップロード
|
||||
curl -X POST \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/gzip" \
|
||||
--data-binary "@${PACKAGE_FILE}" \
|
||||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${PACKAGE_FILE}"
|
||||
|
||||
echo "Release created with asset: ${PACKAGE_FILE}"
|
||||
RELEASE_BODY="YOURLS Helm Chart v${APP_VERSION} - Automated release"
|
||||
|
||||
- name: Checkout Helm Repository
|
||||
if: steps.check_update.outputs.update_needed == 'true'
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: helmchart/repo
|
||||
token: ${{ secrets.GITEA_TOKEN }}
|
||||
path: helm-repo
|
||||
fetch-depth: 0
|
||||
if curl -s -H "Authorization: token ${GITEA_TOKEN}" "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/v${APP_VERSION}" | jq -e '.id' >/dev/null 2>&1; then
|
||||
echo "Release v$APP_VERSION already exists, skipping release creation"
|
||||
else
|
||||
curl -X POST \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\":\"v${APP_VERSION}\",\"name\":\"v${APP_VERSION}\",\"body\":\"${RELEASE_BODY}\"}" \
|
||||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases"
|
||||
|
||||
- name: Update Helm Repository Index
|
||||
if: steps.check_update.outputs.update_needed == 'true'
|
||||
RELEASE_ID=$(curl -s \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/v${APP_VERSION}" | jq -r '.id')
|
||||
|
||||
curl -X POST \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/gzip" \
|
||||
--data-binary "@${PACKAGE_FILE}" \
|
||||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${PACKAGE_FILE}"
|
||||
|
||||
echo "Release v${APP_VERSION} created with asset ${PACKAGE_FILE}"
|
||||
fi
|
||||
|
||||
- name: Publish to Gitea Package Registry
|
||||
if: steps.check_update.outputs.yourls_updated == 'true'
|
||||
run: |
|
||||
set -e
|
||||
APP_VERSION="${{ steps.yourls.outputs.app_version }}"
|
||||
CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}')
|
||||
PACKAGE_FILE="${CHART_NAME}-${APP_VERSION}.tgz"
|
||||
|
||||
echo "Updating Helm repository..."
|
||||
|
||||
# パッケージファイルをHelmリポジトリにコピー
|
||||
cp "${PACKAGE_FILE}" helm-repo/
|
||||
|
||||
cd helm-repo
|
||||
|
||||
# index.yamlを生成/更新
|
||||
helm repo index . --url "https://git.cafepieters.com/helmchart/repo/raw/branch/main"
|
||||
|
||||
# コミットしてプッシュ
|
||||
git config user.name "Gitea Actions Bot"
|
||||
git config user.email "actions@gitea.local"
|
||||
git add "${PACKAGE_FILE}" index.yaml
|
||||
git commit -m "chore: add ${CHART_NAME} v${APP_VERSION}" || echo "No changes to commit"
|
||||
git push origin main
|
||||
|
||||
echo "Helm repository updated successfully"
|
||||
|
||||
echo "🚀 Publishing ${PACKAGE_FILE} to Gitea Package Registry..."
|
||||
|
||||
curl --fail-with-body \
|
||||
-u "${{ secrets.REGISTRY_USER }}:${{ secrets.REGISTRY_TOKEN }}" \
|
||||
-X POST \
|
||||
--upload-file "${PACKAGE_FILE}" \
|
||||
"https://git.cafepieters.com/api/packages/helmchart/helm/api/charts"
|
||||
|
||||
echo "✅ Chart published successfully to Gitea Package Registry"
|
||||
|
||||
- name: Summary
|
||||
if: steps.check_update.outputs.update_needed == 'true'
|
||||
if: always()
|
||||
run: |
|
||||
APP_VERSION="${{ steps.yourls.outputs.app_version }}"
|
||||
NGINX_VERSION="${{ steps.nginx.outputs.latest }}"
|
||||
YOURLS_VERSION="${{ steps.yourls.outputs.latest }}"
|
||||
echo "========================================"
|
||||
echo "Update completed successfully!"
|
||||
echo "========================================"
|
||||
echo "Chart Version: ${APP_VERSION}"
|
||||
echo "YOURLS: ${YOURLS_VERSION}"
|
||||
echo "Nginx: ${NGINX_VERSION}"
|
||||
echo "========================================"
|
||||
echo "Helm repository updated at:"
|
||||
echo "https://git.cafepieters.com/helmchart/repo"
|
||||
echo "========================================"
|
||||
YOURLS_UPDATED="${{ steps.check_update.outputs.yourls_updated }}"
|
||||
|
||||
echo "================================"
|
||||
echo "Update completed!"
|
||||
echo "- YOURLS: ${APP_VERSION}"
|
||||
echo "- Nginx: ${NGINX_VERSION}"
|
||||
echo ""
|
||||
|
||||
if [ "$YOURLS_UPDATED" = "true" ]; then
|
||||
echo "✅ YOURLS version updated - Release created (v${APP_VERSION})"
|
||||
echo "YOURLS updated: ${{ steps.yourls.outputs.current }} -> ${{ steps.yourls.outputs.latest }}"
|
||||
echo "Nginx updated: ${{ steps.nginx.outputs.current }} -> ${{ steps.nginx.outputs.latest }}"
|
||||
elif [ "${{ steps.check_update.outputs.update_needed }}" = "true" ]; then
|
||||
echo "ℹ️ Nginx only update - No release (waiting for next YOURLS update)"
|
||||
echo "Nginx updated: ${{ steps.nginx.outputs.current }} -> ${{ steps.nginx.outputs.latest }}"
|
||||
else
|
||||
echo "ℹ️ Already up to date - no action required"
|
||||
fi
|
||||
echo "================================"
|
||||
|
||||
Reference in New Issue
Block a user