This commit is contained in:
parent
10d3bbefa4
commit
be0e3eb060
1 changed files with 46 additions and 19 deletions
|
|
@ -9,8 +9,17 @@ concurrency:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: self-hosted
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: node:24-bookworm
|
||||||
|
timeout-minutes: 30
|
||||||
steps:
|
steps:
|
||||||
|
- name: Install deploy tools
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
apt-get update -qq
|
||||||
|
apt-get install -y -q ca-certificates curl git jq
|
||||||
|
|
||||||
- name: Build Astro and restart Nomad
|
- name: Build Astro and restart Nomad
|
||||||
env:
|
env:
|
||||||
NOMAD_ADDR: ${{ secrets.NOMAD_ADDR }}
|
NOMAD_ADDR: ${{ secrets.NOMAD_ADDR }}
|
||||||
|
|
@ -24,37 +33,55 @@ jobs:
|
||||||
REPO_URL: https://git.bcgen.ie/familyfedie/familyfedie-website.git
|
REPO_URL: https://git.bcgen.ie/familyfedie/familyfedie-website.git
|
||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
rm -rf source
|
|
||||||
export REF_NAME="${GITHUB_REF_NAME:-main}"
|
export REF_NAME="${GITHUB_REF_NAME:-main}"
|
||||||
|
|
||||||
nix --extra-experimental-features "nix-command flakes" \
|
git config --global http.lowSpeedLimit 1024
|
||||||
shell nixpkgs#git \
|
git config --global http.lowSpeedTime 60
|
||||||
-c git clone --depth 1 --branch "$REF_NAME" "$REPO_URL" source
|
|
||||||
|
for attempt in 1 2 3; do
|
||||||
|
echo "Cloning $REPO_URL ($REF_NAME), attempt $attempt/3"
|
||||||
|
rm -rf source
|
||||||
|
if timeout 180 git clone --depth 1 --branch "$REF_NAME" "$REPO_URL" source; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
if [ "$attempt" -eq 3 ]; then
|
||||||
|
echo "git clone failed after 3 attempts" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sleep $((attempt * 10))
|
||||||
|
done
|
||||||
|
|
||||||
cd source
|
cd source
|
||||||
nix --extra-experimental-features "nix-command flakes" \
|
npm ci --no-audit --no-fund
|
||||||
shell nixpkgs#nodejs_24 \
|
|
||||||
-c npm ci
|
|
||||||
rm -rf dist
|
rm -rf dist
|
||||||
nix --extra-experimental-features "nix-command flakes" \
|
npm run build
|
||||||
shell nixpkgs#nodejs_24 \
|
|
||||||
-c npm run build
|
|
||||||
|
|
||||||
test -f dist/index.html
|
test -f dist/index.html
|
||||||
test -f dist/admin/index.html
|
test -f dist/admin/index.html
|
||||||
test -f dist/speeches/index.html
|
test -f dist/speeches/index.html
|
||||||
test -f dist/assets/icons/familyfed-favicon.png
|
test -f dist/assets/icons/familyfed-favicon.png
|
||||||
|
|
||||||
ALLOC_ID=$(nix --extra-experimental-features "nix-command flakes" \
|
ALLOC_ID=$(
|
||||||
shell nixpkgs#curl nixpkgs#jq \
|
curl -fsS \
|
||||||
-c sh -c 'curl -sf -H "X-Nomad-Token: $NOMAD_TOKEN" "$NOMAD_ADDR/v1/job/familyfed/allocations" | jq -r "map(select(.ClientStatus == \"running\"))[0].ID"')
|
--connect-timeout 15 \
|
||||||
|
--max-time 60 \
|
||||||
|
--retry 3 \
|
||||||
|
--retry-delay 5 \
|
||||||
|
--retry-all-errors \
|
||||||
|
-H "X-Nomad-Token: $NOMAD_TOKEN" \
|
||||||
|
"$NOMAD_ADDR/v1/job/familyfed/allocations" \
|
||||||
|
| jq -r 'map(select(.ClientStatus == "running"))[0].ID'
|
||||||
|
)
|
||||||
|
|
||||||
test -n "$ALLOC_ID"
|
test -n "$ALLOC_ID"
|
||||||
test "$ALLOC_ID" != "null"
|
test "$ALLOC_ID" != "null"
|
||||||
echo "Stopping allocation to trigger fresh prestart: $ALLOC_ID"
|
echo "Stopping allocation to trigger fresh prestart: $ALLOC_ID"
|
||||||
nix --extra-experimental-features "nix-command flakes" \
|
curl -fsS -X POST \
|
||||||
shell nixpkgs#curl \
|
--connect-timeout 15 \
|
||||||
-c curl -sf -X POST \
|
--max-time 60 \
|
||||||
-H "X-Nomad-Token: $NOMAD_TOKEN" \
|
--retry 3 \
|
||||||
"$NOMAD_ADDR/v1/allocation/$ALLOC_ID/stop"
|
--retry-delay 5 \
|
||||||
|
--retry-all-errors \
|
||||||
|
-H "X-Nomad-Token: $NOMAD_TOKEN" \
|
||||||
|
"$NOMAD_ADDR/v1/allocation/$ALLOC_ID/stop"
|
||||||
echo "Deploy triggered. Nomad will schedule a new alloc that re-fetches the site."
|
echo "Deploy triggered. Nomad will schedule a new alloc that re-fetches the site."
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue