mirror of
https://codeberg.org/Toasterson/solstice-ci.git
synced 2026-04-10 13:20:41 +00:00
Refactor Solstice bootstrapping logic into standalone script
This commit replaces inline workflow preparation logic with a dedicated `solstice-bootstrap.sh` script, simplifying workspace setup, job execution, and shutdown processes. The change ensures cleaner orchestration and improves maintainability by centralizing the bootstrapping logic.
This commit is contained in:
parent
4ca78144f2
commit
e73b6ff49f
1 changed files with 30 additions and 4 deletions
|
|
@ -221,11 +221,37 @@ write_files:
|
||||||
content: |
|
content: |
|
||||||
repo_url: {repo}
|
repo_url: {repo}
|
||||||
commit_sha: {sha}
|
commit_sha: {sha}
|
||||||
|
- path: /usr/local/bin/solstice-bootstrap.sh
|
||||||
|
permissions: '0755'
|
||||||
|
owner: root:root
|
||||||
|
content: |
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
echo "Solstice: bootstrapping workflow runner for {sha}" | tee /dev/console
|
||||||
|
RUNNER="/usr/local/bin/solstice-runner"
|
||||||
|
if [ ! -x "$RUNNER" ]; then
|
||||||
|
mkdir -p /usr/local/bin
|
||||||
|
if command -v curl >/dev/null 2>&1 && [ -n "$SOLSTICE_RUNNER_URL" ]; then
|
||||||
|
curl -fSL "$SOLSTICE_RUNNER_URL" -o "$RUNNER" || true
|
||||||
|
elif command -v wget >/dev/null 2>&1 && [ -n "$SOLSTICE_RUNNER_URL" ]; then
|
||||||
|
wget -O "$RUNNER" "$SOLSTICE_RUNNER_URL" || true
|
||||||
|
else
|
||||||
|
echo 'runner URL not provided or curl/wget missing' | tee /dev/console
|
||||||
|
fi
|
||||||
|
chmod +x "$RUNNER" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
export SOLSTICE_REPO_URL='{repo}'
|
||||||
|
export SOLSTICE_COMMIT_SHA='{sha}'
|
||||||
|
export SOLSTICE_JOB_FILE='/etc/solstice/job.yaml'
|
||||||
|
if [ -x "$RUNNER" ]; then
|
||||||
|
"$RUNNER" || true
|
||||||
|
else
|
||||||
|
echo 'solstice-runner not found; nothing to execute' | tee /dev/console
|
||||||
|
fi
|
||||||
|
echo 'Solstice: runner complete, powering off' | tee /dev/console
|
||||||
|
(command -v poweroff >/dev/null 2>&1 && poweroff) || (command -v shutdown >/dev/null 2>&1 && shutdown -y -i5 -g0) || true
|
||||||
runcmd:
|
runcmd:
|
||||||
- [ sh, -c, "echo 'Solstice: preparing workspace for {sha}' | tee /dev/console" ]
|
- [ /usr/local/bin/solstice-bootstrap.sh ]
|
||||||
- [ sh, -c, "mkdir -p /root/work && cd /root/work && if command -v git >/dev/null 2>&1; then git init && git remote add origin {repo} && git fetch --depth=1 origin {sha} && git checkout -q FETCH_HEAD || true; else echo 'git not installed'; fi" ]
|
|
||||||
- [ sh, -c, "if [ -f /root/work/.solstice/job.sh ]; then chmod +x /root/work/.solstice/job.sh && cd /root/work && /root/work/.solstice/job.sh || true; else echo 'No .solstice/job.sh found in repo'; fi" ]
|
|
||||||
- [ sh, -c, "echo 'Solstice: job complete, powering off' | tee /dev/console; (command -v poweroff >/dev/null 2>&1 && poweroff) || (command -v shutdown >/dev/null 2>&1 && shutdown -y -i5 -g0) || true" ]
|
|
||||||
"#, repo = repo_url, sha = commit_sha);
|
"#, repo = repo_url, sha = commit_sha);
|
||||||
s.into_bytes()
|
s.into_bytes()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue