Added ncc build to nodejs contracts. (#334)

This commit is contained in:
Ravin Perera
2021-07-22 12:38:02 +05:30
committed by GitHub
parent e48d0377cb
commit cdf3a73c7d
6 changed files with 32 additions and 23 deletions

View File

@@ -64,7 +64,7 @@ cmake ..
sudo make install
popd > /dev/null 2>&1
popd > /dev/null 2>&1
rm v1.0.3.tar.gz && rm -r readerwriterqueue-1.0.3
rm v1.0.3.tar.gz && sudo rm -r readerwriterqueue-1.0.3
# Concurrent queue
wget https://github.com/cameron314/concurrentqueue/archive/1.0.2.tar.gz
@@ -92,6 +92,12 @@ sudo apt-get install -y \
# jq command (needed for remote cluster scripts)
sudo apt-get install -y jq
# NodeJs
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
# ncc build utility for nodejs compiled builds.
npm i -g @vercel/ncc
# Update linker library cache.
sudo ldconfig

View File

@@ -1 +1,2 @@
node_modules
node_modules
dist

View File

@@ -1,4 +1,8 @@
{
"scripts": {
"build-echo": "ncc build echo_contract.js -o dist/echo-contract",
"build-file": "ncc build file_contract.js -o dist/file-contract"
},
"dependencies": {
"bson": "4.0.4"
}

View File

@@ -31,16 +31,21 @@ elif [ "$CONTRACT" = "nodefile" ]; then # nodejs file contract (uses BSON protoc
echo "Using nodejs file contract."
pushd $hpcore/examples/nodejs_contract/ > /dev/null 2>&1
npm install
npm run build-file
popd > /dev/null 2>&1
copyfiles="$hpcore/examples/nodejs_contract/{node_modules,package.json,hp-contract-lib.js,file_contract.js}"
copyfiles="$hpcore/examples/nodejs_contract/dist/file-contract/index.js"
binary="/usr/bin/node"
binargs="file_contract.js"
binargs="index.js"
else # nodejs echo contract (default)
echo "Using nodejs echo contract."
copyfiles="$hpcore/examples/nodejs_contract/{package.json,hp-contract-lib.js,echo_contract.js}"
pushd $hpcore/examples/nodejs_contract/ > /dev/null 2>&1
npm install
npm run build-echo
popd > /dev/null 2>&1
copyfiles="$hpcore/examples/nodejs_contract/dist/echo-contract/index.js"
binary="/usr/bin/node"
binargs="echo_contract.js"
binargs="index.js"
fi
if [ "$loglevel" = "" ]; then

View File

@@ -337,12 +337,15 @@ if [ $mode = "new" ] || [ $mode = "updatebin" ]; then
strip $hpcore/build/hpcore
strip $hpcore/build/appbill
cp $hpcore/build/{hpcore,hpfs,hpws} $hpfiles/bin/
cp $hpcore/examples/nodejs_contract/{package.json,echo_contract.js,hp-contract-lib.js} \
$hpfiles/nodejs_contract/
pushd $hpcore/examples/nodejs_contract/ > /dev/null 2>&1
npm install
npm run build-echo
popd > /dev/null 2>&1
cp $hpcore/examples/nodejs_contract/dist/echo-contract/index.js $hpfiles/nodejs_contract/
fi
if [ $mode = "new" ]; then
cp ../bin/{libfuse3.so.3,libblake3.so,fusermount3,hpws,hpfs} $hpfiles/bin/
cp ../bin/{libblake3.so,hpws,hpfs} $hpfiles/bin/
cp ./setup-hp.sh $hpfiles/
fi
@@ -438,7 +441,7 @@ if [ $mode = "new" ] || [ $mode = "reconfig" ]; then
# Merge json contents to produce final config.
echo "$(cat ./cfg/node$n.cfg)" \
'{"contract": {"id": "3c349abe-4d70-4f50-9fa6-018f1f2530ab", "bin_path": "/usr/bin/node", "bin_args": "'$basedir'/'$hpfiles'/nodejs_contract/echo_contract.js", "unl": '${myunl}'}}'\
'{"contract": {"id": "3c349abe-4d70-4f50-9fa6-018f1f2530ab", "bin_path": "/usr/bin/node", "bin_args": "'$basedir'/'$hpfiles'/nodejs_contract/index.js", "unl": '${myunl}'}}'\
'{"mesh": {"known_peers": '${mypeers}'}}'\
$contconfig \
| jq --slurp 'reduce .[] as $item ({}; . * $item)' > ./cfg/node$n-merged.cfg

View File

@@ -15,10 +15,6 @@ then
sudo swapon /swapfile
fi
# Getting updates if any
echo "Checking for updates..."
sudo apt-get update
if [ -x "$(command -v node)" ]; then
echo "NodeJs already installed."
else
@@ -29,14 +25,13 @@ else
sudo apt-get install -y nodejs
fi
if [ -x "$(command -v fusermount3)" ]; then
if [ -x "$(command -v fusermount)" ]; then
echo "FUSE already installed."
else
echo "Installing FUSE and other shared libraries..."
sudo apt-get -y install libgomp1 libssl-dev
sudo cp $basedir/$hpfiles/bin/{libfuse3.so.3,libblake3.so} /usr/local/lib/
sudo apt-get -y install libgomp1 libssl-dev fuse3
sudo cp $basedir/$hpfiles/bin/libblake3.so /usr/local/lib/
sudo ldconfig
sudo cp $basedir/$hpfiles/bin/fusermount3 /usr/local/bin/
fi
if [ -x "$(command -v sqlite3)" ]; then
@@ -59,11 +54,6 @@ if [ -f $basedir/$hpfiles/ssl/tlscert.pem ]; then
fi
if [ $mode = "new" ] || [ $mode = "reconfig" ]; then
# npm install to support nodejs contract
pushd $basedir/$hpfiles/nodejs_contract > /dev/null 2>&1
npm install
popd > /dev/null 2>&1
# Create getpid script (gets process ids belonging to this contract dir)
echo "pids=\$(pidof \$*) && [ ! -z \"\$pids\" ] && ps -fp \$pids | grep -w $contdir | awk '{print \$2}' | tr '\n' ' '" > $contdir/getpid.sh
sudo chmod +x $contdir/getpid.sh