183 lines
7.5 KiB
YAML
183 lines
7.5 KiB
YAML
name: deploy
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
group: mesh-deploy
|
|
cancel-in-progress: false
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
ci:
|
|
uses: ./.github/workflows/ci.yml
|
|
permissions:
|
|
contents: read
|
|
|
|
security:
|
|
uses: ./.github/workflows/security.yml
|
|
permissions:
|
|
contents: read
|
|
pull-requests: read
|
|
security-events: write
|
|
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
with:
|
|
submodules: recursive
|
|
- uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
|
|
with:
|
|
go-version: "1.26"
|
|
- name: Generate the Go from the Zi sources
|
|
uses: ./.github/actions/generate
|
|
- name: Build the vendored liboqs
|
|
uses: ./.github/actions/liboqs
|
|
- name: Build and test
|
|
run: |
|
|
python3 -B scripts/test_migrate_env.py
|
|
python3 -B scripts/test_deployment_inputs.py
|
|
make test
|
|
|
|
deploy:
|
|
needs: [test, ci, security]
|
|
runs-on: ubuntu-latest
|
|
environment: production
|
|
steps:
|
|
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
with:
|
|
submodules: recursive
|
|
- uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
|
|
with:
|
|
go-version: "1.26"
|
|
|
|
- name: Generate the Go from the Zi sources
|
|
uses: ./.github/actions/generate
|
|
|
|
- name: Verify the pinned native source
|
|
id: liboqs
|
|
run: python3 -B scripts/verify_deployment_inputs.py pinned-source
|
|
|
|
- name: Configure SSH
|
|
env:
|
|
MESH_SSH_KEY: ${{ secrets.MESH_SSH_KEY || secrets.DAOCHI_SSH_KEY }}
|
|
MESH_SSH_HOST: ${{ secrets.MESH_HOST || secrets.DAOCHI_HOST }}
|
|
MESH_SSH_HOST_KEY: ${{ secrets.MESH_SSH_HOST_KEY || secrets.DAOCHI_SSH_HOST_KEY }}
|
|
MESH_SSH_USER: ${{ secrets.MESH_USER || secrets.DAOCHI_USER }}
|
|
run: |
|
|
install -m 600 -D /dev/null ~/.ssh/id_ed25519
|
|
test -n "$MESH_SSH_KEY"
|
|
printf '%s\n' "$MESH_SSH_KEY" > ~/.ssh/id_ed25519
|
|
python3 -B scripts/verify_deployment_inputs.py configure-ssh \
|
|
--host "$MESH_SSH_HOST" --user "$MESH_SSH_USER" \
|
|
--trusted-key "$MESH_SSH_HOST_KEY"
|
|
|
|
- name: Sync source and build on origin
|
|
run: |
|
|
expected_commit="${{ steps.liboqs.outputs.liboqs_commit }}"
|
|
expected_source_commit="${{ github.sha }}"
|
|
expected_digest="${{ steps.liboqs.outputs.liboqs_digest }}"
|
|
expected_entries="${{ steps.liboqs.outputs.liboqs_entries }}"
|
|
git ls-files -z --recurse-submodules > "$RUNNER_TEMP/mesh-source-files"
|
|
find . -maxdepth 1 -type f \( -name '*.zi.go' -o -name '*.zi_test.go' \) \
|
|
-print0 >> "$RUNNER_TEMP/mesh-source-files"
|
|
tar --null --no-recursion --files-from="$RUNNER_TEMP/mesh-source-files" -czf - | \
|
|
ssh mesh-origin '
|
|
set -e
|
|
rm -rf /opt/mesh-src.new
|
|
mkdir -p /opt/mesh-src.new
|
|
tar -C /opt/mesh-src.new -xzf -
|
|
python3 -B /opt/mesh-src.new/scripts/verify_deployment_inputs.py verify-source \
|
|
--source-dir /opt/mesh-src.new/vendor/liboqs \
|
|
--expected-commit "'"$expected_commit"'" \
|
|
--expected-digest "'"$expected_digest"'" \
|
|
--expected-entries "'"$expected_entries"'"
|
|
rm -rf /opt/mesh-src.old
|
|
[ -d /opt/mesh-src ] && mv /opt/mesh-src /opt/mesh-src.old
|
|
mv /opt/mesh-src.new /opt/mesh-src
|
|
rm -rf /opt/mesh-src.old
|
|
cd /opt/mesh-src
|
|
make build VERSION=${{ github.sha }} SOURCE_COMMIT=${{ github.sha }} \
|
|
LIBOQS_COMMIT='"$expected_commit"'
|
|
python3 -B scripts/verify_deployment_inputs.py verify-artifact-manifest \
|
|
--output mesh --manifest build/mesh.manifest.json \
|
|
--expected-source-commit "'"$expected_source_commit"'" \
|
|
--expected-liboqs-commit '"$expected_commit"'
|
|
'
|
|
|
|
# Google Play purchases need a service account that Play Console lets view
|
|
# financial data and manage orders. Without the optional secret the node
|
|
# keeps the verifier it has.
|
|
- name: Install the Google Play service account
|
|
env:
|
|
GOOGLE_SERVICE_ACCOUNT_JSON: ${{ secrets.MESH_GOOGLE_SERVICE_ACCOUNT_JSON || secrets.DAOCHI_GOOGLE_SERVICE_ACCOUNT_JSON }}
|
|
run: |
|
|
if [ -z "$GOOGLE_SERVICE_ACCOUNT_JSON" ]; then
|
|
echo "No MESH_GOOGLE_SERVICE_ACCOUNT_JSON secret; the node keeps its Google Play verifier settings"
|
|
exit 0
|
|
fi
|
|
printf '%s' "$GOOGLE_SERVICE_ACCOUNT_JSON" | python3 -I -c '
|
|
import json, sys
|
|
account = json.load(sys.stdin)
|
|
if account.get("type") != "service_account" or not account.get("client_email") or not account.get("private_key"):
|
|
sys.exit("MESH_GOOGLE_SERVICE_ACCOUNT_JSON is not a Google service account key")
|
|
print("Google Play service account:", account["client_email"])
|
|
'
|
|
printf '%s' "$GOOGLE_SERVICE_ACCOUNT_JSON" | ssh mesh-origin '
|
|
set -e
|
|
config=/etc/mesh
|
|
service=mesh.service
|
|
if [ ! -f /etc/mesh/mesh.env ]; then config=/etc/daochi; service=daochi.service; fi
|
|
account=$config/google-play-service-account.json
|
|
umask 077
|
|
cat > "$account.new"
|
|
user=$(systemctl show "$service" -p User --value)
|
|
if [ -n "$user" ]; then
|
|
chown "$user" "$account.new"
|
|
fi
|
|
mv "$account.new" "$account"
|
|
'
|
|
|
|
- name: Swap binary and restart
|
|
id: swap
|
|
env:
|
|
MESH_NODE_SYNC_TOKEN: ${{ secrets.MESH_NODE_SYNC_TOKEN || secrets.DAOCHI_NODE_SYNC_TOKEN }}
|
|
EXPECTED_NATIVE_COMMIT: ${{ steps.liboqs.outputs.liboqs_commit }}
|
|
run: |
|
|
DEPLOY_STAMP=$(date -u +%Y%m%dT%H%M%SZ)
|
|
export DEPLOY_STAMP
|
|
echo "stamp=$DEPLOY_STAMP" >> "$GITHUB_OUTPUT"
|
|
python3 -c 'import json,os,sys; json.dump({"stamp":os.environ["DEPLOY_STAMP"],"source_commit":os.environ["GITHUB_SHA"],"native_commit":os.environ["EXPECTED_NATIVE_COMMIT"],"mesh_token":os.environ["MESH_NODE_SYNC_TOKEN"]},sys.stdout)' |
|
|
ssh mesh-origin python3 /opt/mesh-src/deploy/install.py
|
|
|
|
- name: Health check (rollback on failure)
|
|
run: |
|
|
STAMP=${{ steps.swap.outputs.stamp }}
|
|
code=000
|
|
for _attempt in $(seq 1 30); do
|
|
code=$(ssh mesh-origin 'curl -sS -o /dev/null -w "%{http_code}" "http://127.0.0.1:8080/readyz"' || true)
|
|
[ "$code" = "200" ] && break
|
|
sleep 2
|
|
done
|
|
echo "health check: $code"
|
|
if [ "$code" != "200" ]; then
|
|
echo "::error::health check failed ($code) - rolling back"
|
|
printf '%s' "$STAMP" | ssh mesh-origin sh /opt/mesh-src/deploy/rollback.sh
|
|
exit 1
|
|
fi
|
|
pub=000
|
|
for _attempt in $(seq 1 15); do
|
|
pub=$(curl -sS -o /dev/null -w "%{http_code}" "https://api.waozi.xyz/readyz" || true)
|
|
[ "$pub" = "200" ] && break
|
|
sleep 2
|
|
done
|
|
echo "public endpoint through Cloudflare: $pub"
|
|
if [ "$pub" != "200" ]; then
|
|
echo "::error::public health check failed ($pub) - rolling back"
|
|
printf '%s' "$STAMP" | ssh mesh-origin sh /opt/mesh-src/deploy/rollback.sh
|
|
exit 1
|
|
fi
|