Update .gitea/workflows/z-docs.yml
This commit is contained in:
parent
46e20069fc
commit
9a3d1e69c8
@ -1,137 +1,53 @@
|
||||
#!/bin/bash
|
||||
name: Deploy from Main
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
schedule:
|
||||
- cron: '0 0 * * 0' # Weekly: Every Sunday at midnight UTC
|
||||
workflow_dispatch:
|
||||
|
||||
# Check for required positional arguments
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "Error: Two arguments required"
|
||||
echo "Usage: $0 <owner/repo> <branch-or-tag>"
|
||||
exit 1
|
||||
fi
|
||||
env:
|
||||
TARGET_REPO: zramsay/zenith-docs
|
||||
CERC_REGISTRY_USER_KEY: ${{ secrets.CICD_LACONIC_USER_KEY }}
|
||||
CERC_REGISTRY_BOND_ID: ${{ secrets.CICD_LACONIC_BOND_ID }}
|
||||
CERC_REGISTRY_RPC_ENDPOINT: "http://143.198.37.25:26657"
|
||||
CERC_REGISTRY_GQL_ENDPOINT: "http://143.198.37.25:9473/api"
|
||||
CERC_REGISTRY_CHAIN_ID: "laconic-mainnet"
|
||||
CERC_REGISTRY_DEPLOYMENT_HOSTNAME: zenith-docs
|
||||
APP_NAME: "zenith-docs"
|
||||
DEPLOYER_LRN: "lrn://mito-systems/deployers/webapp-deployer-api.pwa.laconic.audubon.app"
|
||||
AUTHORITY: "mito-systems"
|
||||
|
||||
# Check required environment variables
|
||||
if [ -z "$CERC_REGISTRY_USER_KEY" ]; then
|
||||
echo "Error: CERC_REGISTRY_USER_KEY environment variable is required"
|
||||
exit 1
|
||||
fi
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Clone project repository"
|
||||
uses: actions/checkout@v3
|
||||
|
||||
if [ -z "$CERC_REGISTRY_BOND_ID" ]; then
|
||||
echo "Error: CERC_REGISTRY_BOND_ID environment variable is required"
|
||||
exit 1
|
||||
fi
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18
|
||||
|
||||
REPO_PATH="$1"
|
||||
REF="$2"
|
||||
REPO="https://git.vdb.to/${REPO_PATH}"
|
||||
- name: Deploy from docs-mvp branch
|
||||
run: |
|
||||
# Get latest commit from docs-mvp branch
|
||||
commit_info=$(curl -s https://git.vdb.to/api/v1/repos/${{ env.TARGET_REPO }}/branches/docs-mvp)
|
||||
commit_hash=$(echo $commit_info | jq -r .commit.id)
|
||||
commit_date=$(echo $commit_info | jq -r .commit.timestamp)
|
||||
|
||||
# Get the commit hash - try as branch first, then as tag
|
||||
COMMIT_HASH=$(curl -s "https://git.vdb.to/api/v1/repos/${REPO_PATH}/branches/${REF}" | jq -r '.commit.id')
|
||||
if [ -z "$COMMIT_HASH" ] || [ "$COMMIT_HASH" = "null" ]; then
|
||||
# Fall back to tag lookup
|
||||
COMMIT_HASH=$(curl -s "https://git.vdb.to/api/v1/repos/${REPO_PATH}/tags/${REF}" | jq -r '.commit.sha')
|
||||
if [ -z "$COMMIT_HASH" ] || [ "$COMMIT_HASH" = "null" ]; then
|
||||
echo "Error: Could not find commit hash for ref $REF"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
echo "Latest commit: $commit_hash"
|
||||
echo "Committed at: $commit_date"
|
||||
echo "Proceeding with deployment"
|
||||
|
||||
# Use short commit hash for version
|
||||
SHORT_HASH="${COMMIT_HASH:0:7}"
|
||||
VERSION="${REF}-${SHORT_HASH}"
|
||||
# Setup dependencies
|
||||
sudo apt -y update && sudo apt -y install jq
|
||||
corepack enable
|
||||
npm config set @cerc-io:registry https://git.vdb.to/api/packages/cerc-io/npm/
|
||||
npm install -g @cerc-io/laconic-registry-cli
|
||||
|
||||
echo "Deploying from ref: $REF"
|
||||
echo "Commit hash: $COMMIT_HASH"
|
||||
echo "Version: $VERSION"
|
||||
|
||||
# Create temporary files
|
||||
RECORD_FILE=tmp.rf.$
|
||||
CONFIG_FILE=$(mktemp)
|
||||
|
||||
# Generate registry configuration
|
||||
cat <<EOF > "$CONFIG_FILE"
|
||||
services:
|
||||
registry:
|
||||
rpcEndpoint: '${CERC_REGISTRY_RPC_ENDPOINT}'
|
||||
gqlEndpoint: '${CERC_REGISTRY_GQL_ENDPOINT}'
|
||||
chainId: ${CERC_REGISTRY_CHAIN_ID}
|
||||
gas: 900000
|
||||
fees: 900000alnt
|
||||
EOF
|
||||
|
||||
# Generate the application record
|
||||
cat <<EOF | sed '/.*: ""$/d' > "$RECORD_FILE"
|
||||
record:
|
||||
type: ApplicationRecord
|
||||
name: "$APP_NAME"
|
||||
version: "$VERSION"
|
||||
app_type: webapp
|
||||
repository:
|
||||
- "$REPO"
|
||||
repository_ref: "$COMMIT_HASH"
|
||||
app_version: "0.0.1"
|
||||
EOF
|
||||
|
||||
# Publish the application record
|
||||
echo "Publishing application record..."
|
||||
cat $RECORD_FILE
|
||||
RECORD_ID=$(laconic -c $CONFIG_FILE registry record publish --filename $RECORD_FILE --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} | jq -r '.id')
|
||||
echo "Record ID: $RECORD_ID"
|
||||
|
||||
# Set up LRN (Laconic Resource Name)
|
||||
if [ -z "$CERC_REGISTRY_APP_LRN" ]; then
|
||||
CERC_REGISTRY_APP_LRN="lrn://$AUTHORITY/applications/$APP_NAME"
|
||||
fi
|
||||
|
||||
# Set name mappings
|
||||
echo "Setting name mappings..."
|
||||
laconic -c $CONFIG_FILE registry name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_APP_LRN" "$RECORD_ID"
|
||||
laconic -c $CONFIG_FILE registry name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_APP_LRN@${COMMIT_HASH}" "$RECORD_ID"
|
||||
|
||||
|
||||
# Handle deployer payment if required
|
||||
if [ ! -z "$DEPLOYER_LRN" ]; then
|
||||
echo "Processing deployer payment..."
|
||||
paymentAddress=$(laconic -c $CONFIG_FILE registry name resolve "$DEPLOYER_LRN" | jq -r '.[0].attributes.paymentAddress')
|
||||
paymentAmount=$(laconic -c $CONFIG_FILE registry name resolve "$DEPLOYER_LRN" | jq -r '.[0].attributes.minimumPayment' | sed 's/alnt//g')
|
||||
|
||||
if [[ -n "$paymentAmount" && "$paymentAmount" != "null" ]]; then
|
||||
payment=$(laconic -c $CONFIG_FILE registry tokens send --address "$paymentAddress" --type alnt --quantity "$paymentAmount" --user-key "$CERC_REGISTRY_USER_KEY" --bond-id "$CERC_REGISTRY_BOND_ID")
|
||||
txHash=$(echo "$payment" | jq -r '.tx.hash')
|
||||
echo "Paid deployer with txHash: $txHash"
|
||||
else
|
||||
echo "No payment required - skipping payment step"
|
||||
txHash=""
|
||||
fi
|
||||
|
||||
# Generate deployment request
|
||||
echo "Generating deployment request..."
|
||||
cat <<EOF | sed '/.*: ""$/d' > "$RECORD_FILE"
|
||||
record:
|
||||
type: ApplicationDeploymentRequest
|
||||
version: '1.0.0'
|
||||
name: "$APP_NAME"
|
||||
application: "$CERC_REGISTRY_APP_LRN"
|
||||
deployer: $DEPLOYER_LRN
|
||||
dns: $CERC_REGISTRY_DEPLOYMENT_HOSTNAME
|
||||
config:
|
||||
env:
|
||||
LACONIC_HOSTED_CONFIG_laconicd_chain_id: laconic-testnet-2
|
||||
meta:
|
||||
note: "Added by CI @ $(date)"
|
||||
repository: "$REPO"
|
||||
repository_ref: "$COMMIT_HASH"
|
||||
payment: $txHash
|
||||
EOF
|
||||
|
||||
cat $RECORD_FILE
|
||||
DEPLOY_RECORD_ID=$(laconic -c $CONFIG_FILE registry record publish \
|
||||
--filename $RECORD_FILE \
|
||||
--user-key "${CERC_REGISTRY_USER_KEY}" \
|
||||
--bond-id ${CERC_REGISTRY_BOND_ID} | jq -r '.id')
|
||||
echo "Deployment Record ID: $DEPLOY_RECORD_ID"
|
||||
fi
|
||||
|
||||
# Cleanup
|
||||
rm -f $RECORD_FILE $CONFIG_FILE
|
||||
echo "Script completed successfully"
|
||||
# Run deployment
|
||||
./deploy.sh ${{ env.TARGET_REPO }} docs-mvp
|
||||
Loading…
Reference in New Issue
Block a user