-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SENTINEL] 1.0 release with GDA support (#276)
* updated dockerfile * no exact version pinning for metadata * fix observer mode * use public repo for metadata * report app version in log * bump version to 1.0 * simplified docker config * move SENTINEL_BALANCE_THRESHOLD to config * updated readme and example env * fix toga script * change default DB path * GDA Snapshots (#277) * modify to run as cron * get rpc urls from .env * set only snapshot url variable * update deployment * remove log --------- Co-authored-by: didi <[email protected]> Co-authored-by: Axe <[email protected]>
- Loading branch information
1 parent
09b8804
commit c2add4f
Showing
25 changed files
with
754 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ name: Dev CI/CD | |
on: | ||
push: | ||
branches: | ||
- '*' | ||
- 'master' | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
# syntax = docker/dockerfile:1.3 | ||
|
||
# Always add commit hash for reproducability | ||
FROM node:18-alpine@sha256:3482a20c97e401b56ac50ba8920cc7b5b2022bfc6aa7d4e4c231755770cf892f | ||
|
||
# Enable prod optimizations | ||
# Set environment variables | ||
ENV NODE_ENV=production | ||
|
||
# Create app directory | ||
WORKDIR /app | ||
RUN apk add --update --no-cache g++ make python3 && \ | ||
ln -sf python3 /usr/bin/python && \ | ||
apk add --update --no-cache yarn | ||
|
||
COPY ["package.json", "yarn.lock", "./"] | ||
RUN yarn install --frozen-lockfile --production | ||
COPY . /app | ||
# Install dependencies | ||
RUN apk add --update --no-cache \ | ||
yarn \ | ||
tini | ||
|
||
# Copy package.json and yarn.lock | ||
COPY package.json yarn.lock ./ | ||
|
||
# Install app dependencies | ||
RUN yarn install --production | ||
|
||
# Copy the rest of the application | ||
COPY . ./ | ||
|
||
# make sure we can write the data directory | ||
RUN chown node:node data | ||
RUN chown -R node:node /app/data \ | ||
&& chmod -R 755 /app/data | ||
|
||
# Add a simple init system so that Node would respect process signals | ||
RUN apk add --no-cache tini | ||
# Use tini as the entrypoint | ||
ENTRYPOINT ["/sbin/tini", "--"] | ||
|
||
# Don't run as root | ||
USER node | ||
CMD ["node", "main.js" ] | ||
|
||
# Start the application | ||
CMD ["node", "main.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
# Minimal version which starts the sentinel service only, without additional monitoring services. | ||
# Basic docker-compose file for running a sentinel. | ||
# This is ideal for resource constrained environments or for use with custom monitoring setups. | ||
|
||
version: '3' | ||
services: | ||
sentinel: | ||
image: superfluidfinance/superfluid-sentinel:${SENTINEL_VERSION:-latest} | ||
build: . | ||
restart: unless-stopped | ||
env_file: .env | ||
environment: | ||
- NODE_ENV=production | ||
- DB_PATH=data/db.sqlite | ||
# hardcode the port inside the container | ||
- METRICS_PORT=9100 | ||
ports: | ||
- ${METRICS_PORT:-9100}:9100 | ||
volumes: | ||
- data:/app/data | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: '0.50' | ||
memory: 300M | ||
reservations: | ||
memory: 50M | ||
|
||
volumes: | ||
data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const { writeFileSync, readFileSync } = require("fs"); | ||
|
||
function cleanLogData(path) { | ||
const newCIDs = new Map(); | ||
try { | ||
readFileSync(path, "utf8").split(/\r?\n/).forEach(line => { | ||
const splitLine = line.split(","); | ||
const fileName = splitLine[0]; | ||
const filtered = fileName.match("_(.*)_") | ||
if(filtered) { | ||
newCIDs.set(filtered[1], splitLine[1]); | ||
} | ||
}); | ||
return newCIDs; | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
||
(() => { | ||
try { | ||
const myArgs = process.argv.slice(2); | ||
const ipfsLog = myArgs[0]; | ||
const outputFile = myArgs[1]; | ||
|
||
console.log(`ipfs log file: ${ipfsLog}, output file: ${outputFile}`); | ||
|
||
if(!ipfsLog) { | ||
throw new Error("No IPFS log") | ||
} | ||
if(!outputFile) { | ||
throw new Error("No output file") | ||
} | ||
|
||
const newCIDs = cleanLogData(ipfsLog); | ||
/*if(newCIDs.size !== 10) { | ||
throw new Error("IPFS log not complety") | ||
}*/ | ||
|
||
// Read manifest data from local file | ||
const manifestJson = JSON.parse(readFileSync('manifest.json', 'utf8')); | ||
|
||
// Update manifest in memory | ||
for (const [key, value] of newCIDs) { | ||
manifestJson.networks[key].cid = value; | ||
} | ||
|
||
// Write updated manifest to output file | ||
writeFileSync(outputFile, JSON.stringify(manifestJson, null, 2)); | ||
|
||
} catch (err) { | ||
console.error(err) | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/bin/bash | ||
|
||
set -xe | ||
|
||
#Variables | ||
rpc_urls="${SNAPSHOT_RPC_URLS}" | ||
ipfs_api="${IPFS_API}" | ||
|
||
generate_snapshot() { | ||
echo "Generating new snapshots..." | ||
yarn install | ||
|
||
if [ ! -d "snapshots" ]; then | ||
mkdir snapshots | ||
fi | ||
|
||
# Get list of RPC URLs from environment variable | ||
IFS=',' read -r -a rpc_array <<< "$rpc_urls" | ||
for rpc in "${rpc_array[@]}"; do | ||
echo "${rpc}" | ||
[ -n "$rpc" ] && node ./scripts/buildSnapshot.js "https://$rpc" | ||
done | ||
|
||
echo "Generating done" | ||
} | ||
|
||
|
||
upload_snapshot() { | ||
echo "Uploading snapshots..." | ||
ipfs_logfile="logs/ipfs_$(date '+%Y-%m-%d').txt" | ||
rm -f -- "$ipfs_logfile" | ||
for file in ./snapshots/*.sqlite.gz; do | ||
ipfs_hash=`ipfs --api "$ipfs_api" add -q $file` | ||
echo $file,$ipfs_hash >> "$ipfs_logfile" | ||
done | ||
node ./scripts/generateManifest.js "$ipfs_logfile" manifest.json | ||
ipfs_hash=`ipfs --api "$ipfs_api" add -q manifest.json` | ||
echo manifest.json,$ipfs_hash >> "$ipfs_logfile" | ||
# updating the manifest ipns link | ||
ipfs --api "$ipfs_api" name publish --key=sentinel-manifest "$ipfs_hash" | ||
echo "Uploading snapshots done" | ||
} | ||
|
||
clean_snapshots() { | ||
echo "Cleaning snapshot folder..." | ||
rm -f -- "$HOME/snapshots"/*.gz | ||
echo "Cleaning done" | ||
} | ||
|
||
# Usage | ||
usage() { | ||
echo "Usage: $0 [-g] [-u] [-p] [-c]" | ||
echo "Options:" | ||
echo " -g Generate snapshots" | ||
echo " -u Upload snapshots" | ||
echo " -c Clean snapshots" | ||
exit 1 | ||
} | ||
|
||
# Command line options | ||
while getopts "gupc" opt; do | ||
case $opt in | ||
g) generate_snapshot ;; | ||
u) upload_snapshot ;; | ||
c) clean_snapshots ;; | ||
*) usage ;; | ||
esac | ||
done | ||
|
||
# If no options are provided, show usage | ||
if [[ $# -eq 0 ]]; then | ||
usage | ||
fi |
Oops, something went wrong.