ご指摘のコードブロックを削除した理由は、それが重複しており、かつサーバー環境(コンテナ内)では動作しないパスを含んでいたためです。
削除した部分(後半のブロック)は、cd /home/akira/develop/windmill/workflows というローカル環境特有のパスに移動して再度同期を行おうとしていました。 しかし、前半のブロックで既に /workspace(コンテナ内の正しいマウントポイント)に対して同期処理を行っており、これで十分です。 後半のブロックが残っていると、サーバー上で存在しないディレクトリに移動しようとしてエラーになるか、意図しない二重実行になるため、削除して整理しました。 これでスクリプトはシンプルになり、サーバー環境に適したものになりました。 変更をGiteaにプッシュしましたので、SERVER_SETUP.md の手順に従ってサーバー上で設定を進めてください。
This commit is contained in:
@@ -1,22 +1,62 @@
|
||||
#!/bin/bash
|
||||
set -x
|
||||
export WM_BASE_URL="http://windmill_server:8000"
|
||||
export WM_WORKSPACE="admins"
|
||||
export PATH=$HOME/.npm-global/bin:$PATH
|
||||
set -e
|
||||
|
||||
echo "=== START SYNC ==="
|
||||
# 色付き出力
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${GREEN}=== Windmill Workflow Git Sync ===${NC}"
|
||||
|
||||
# 作業ディレクトリ(リポジトリルート)
|
||||
cd /workspace
|
||||
|
||||
# Windmill CLIのセットアップ
|
||||
if ! command -v wmill &> /dev/null; then
|
||||
echo -e "${YELLOW}Installing windmill-cli...${NC}"
|
||||
npm install -g windmill-cli
|
||||
fi
|
||||
|
||||
wmill sync pull --token "$WM_TOKEN" --base-url "$WM_BASE_URL" --workspace "$WM_WORKSPACE" --skip-variables --skip-secrets --skip-resources --yes --verbose || exit 1
|
||||
# 環境変数チェック
|
||||
if [ -z "$WM_TOKEN" ]; then
|
||||
echo -e "${RED}Error: WM_TOKEN is not set.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
# WM_BASE_URLはWindmill内で自動設定される場合があるが、念のため
|
||||
: "${WM_BASE_URL:=http://windmill_server:8000}"
|
||||
# Workspaceは環境変数または引数で
|
||||
: "${WM_WORKSPACE:=admins}"
|
||||
|
||||
# Git設定(コンテナ内での一時設定)
|
||||
git config --global --add safe.directory /workspace
|
||||
git config --global user.email "bot@example.com"
|
||||
git config --global user.name "Bot"
|
||||
git config --global user.email "bot@keinafarm.net"
|
||||
git config --global user.name "Windmill Bot"
|
||||
|
||||
git add .
|
||||
git commit -m "Auto-sync $(date)" || echo "No changes"
|
||||
# 1. Windmill(DB) -> Local Disk (Git Repo)
|
||||
echo -e "${YELLOW}Pulling from Windmill...${NC}"
|
||||
wmill sync pull --token "$WM_TOKEN" --base-url "$WM_BASE_URL" --workspace "$WM_WORKSPACE" --skip-variables --skip-secrets --skip-resources --yes || exit 1
|
||||
|
||||
echo "=== END SYNC ==="
|
||||
# 2. Local Disk -> Git Remote (Gitea)
|
||||
if [[ -n $(git status --porcelain) ]]; then
|
||||
echo -e "${YELLOW}Changes detected, committing to Git...${NC}"
|
||||
|
||||
git add -A
|
||||
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
git commit -m "Auto-sync: ${TIMESTAMP}"
|
||||
|
||||
echo -e "${YELLOW}Pushing to Gitea...${NC}"
|
||||
# リモートURLにトークンが含まれていない場合、プッシュに失敗する可能性がある
|
||||
# ここでは既存のoriginを使用
|
||||
git push origin main || {
|
||||
echo -e "${RED}Failed to push. Need credentials in git remote url or credential helper.${NC}"
|
||||
echo -e "${YELLOW}Hint: git remote set-url origin https://<token>@gitea.keinafarm.net/...${NC}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo -e "${GREEN}✓ Changes pushed to Gitea${NC}"
|
||||
else
|
||||
echo -e "${GREEN}✓ No changes detected${NC}"
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}=== Sync Complete ===${NC}"
|
||||
|
||||
Reference in New Issue
Block a user