Add deploy-gitea.sh
This commit is contained in:
parent
ef103744f0
commit
2ffa39fd57
137
deploy-gitea.sh
Normal file
137
deploy-gitea.sh
Normal file
@ -0,0 +1,137 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
|
||||
# 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
|
||||
|
||||
# Check required environment variables
|
||||
if [ -z "$CERC_REGISTRY_USER_KEY" ]; then
|
||||
echo "Error: CERC_REGISTRY_USER_KEY environment variable is required"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$CERC_REGISTRY_BOND_ID" ]; then
|
||||
echo "Error: CERC_REGISTRY_BOND_ID environment variable is required"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
REPO_PATH="$1"
|
||||
REF="$2"
|
||||
REPO="https://git.vdb.to/${REPO_PATH}"
|
||||
|
||||
# Get the commit hash - try as branch first, then as tag
|
||||
COMMIT_HASH=$(curl -s "https://git.vdb.to/api/v1/repos/${REPO_PATH}/commits/${REF}" | jq -r '.sha')
|
||||
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}/git/refs/tags/${REF}" | jq -r '.object.sha')
|
||||
if [ -z "$COMMIT_HASH" ] || [ "$COMMIT_HASH" = "null" ]; then
|
||||
echo "Error: Could not find commit hash for ref $REF"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Use short commit hash for version
|
||||
SHORT_HASH="${COMMIT_HASH:0:7}"
|
||||
VERSION="${REF}-${SHORT_HASH}"
|
||||
|
||||
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"
|
||||
Loading…
Reference in New Issue
Block a user