Added Docker support.

This commit is contained in:
Ravin Perera
2019-10-18 23:47:28 +05:30
parent 172d41d191
commit 84f43b7549
9 changed files with 35 additions and 138 deletions

View File

@@ -19,6 +19,14 @@ add_executable(hpcore
src/main.cpp
)
add_custom_target(release
COMMAND cmake -DCMAKE_BUILD_TYPE=RELEASE .
COMMAND make hpcore
COMMAND strip ./build/hpcore
COMMAND docker build -t hpcore:latest .
)
set_target_properties(release PROPERTIES EXCLUDE_FROM_ALL TRUE)
target_link_libraries(hpcore
libsodium.a
libboost_system.a

5
Dockerfile Normal file
View File

@@ -0,0 +1,5 @@
FROM ubuntu:bionic
WORKDIR /hp
COPY ./build/hpcore .
ENTRYPOINT ["/hp/hpcore"]

View File

@@ -0,0 +1,17 @@
FROM hpcore:latest as hpcore-nodejs
RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
FROM hpcore-nodejs
RUN /hp/hpcore new /echocontract
COPY ./examples/echocontract/contract.js /echocontract/bin/contract.js
RUN mv /echocontract/cfg/hp.cfg /echocontract/cfg/hp.json
RUN node -p "JSON.stringify({...require('/echocontract/cfg/hp.json'), binary:'/usr/bin/node', binargs:'./bin/contract.js' }, null, 2)" > /echocontract/cfg/hp.cfg
RUN rm /echocontract/cfg/hp.json
ENTRYPOINT ["/hp/hpcore", "run", "/echocontract"]

View File

@@ -2,9 +2,8 @@ process.on('uncaughtException', (err) => {
console.error('There was an uncaught error', err)
})
const fs = require('fs')
const pipe = require('posix-pipe-fork-exec')
let input = Buffer.from(pipe.getfdbytes(0)).toString()
let input = fs.readFileSync(0, 'utf8');
console.log("===Sample contract started===");
console.log("Contract args received from hp: " + input);
@@ -12,7 +11,7 @@ let hpargs = JSON.parse(input);
Object.keys(hpargs.usrfd).forEach(function (key, index) {
let userfds = hpargs.usrfd[key];
let userinput = Buffer.from(pipe.getfdbytes(userfds[0])).toString().trim();
let userinput = fs.readFileSync(userfds[0], 'utf8');
if (userinput.length > 0) {
console.log("Input received from user " + key + ":");
@@ -21,7 +20,7 @@ Object.keys(hpargs.usrfd).forEach(function (key, index) {
}
});
let hpinput = Buffer.from(pipe.getfdbytes(hpargs.hpfd[0])).toString().trim();
let hpinput = fs.readFileSync(hpargs.hpfd[0], 'utf8');
if (hpinput.length > 0) {
console.log("Input received from hp:");
console.log(hpinput);

View File

@@ -1,46 +0,0 @@
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"fs-extra": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
"requires": {
"graceful-fs": "^4.2.0",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
},
"graceful-fs": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.2.tgz",
"integrity": "sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q=="
},
"jsonfile": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
"requires": {
"graceful-fs": "^4.1.6"
}
},
"nan": {
"version": "2.14.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz",
"integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg=="
},
"posix-pipe-fork-exec": {
"version": "git+https://github.com/codetsunami/posix-pipe-fork-exec.git#362060203b2eb705fa7acb969bf2ecf9e80ab102",
"from": "git+https://github.com/codetsunami/posix-pipe-fork-exec.git",
"requires": {
"nan": "^2.14.0"
}
},
"universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
}
}
}

View File

@@ -1,6 +0,0 @@
{
"dependencies": {
"fs-extra": "^8.1.0",
"posix-pipe-fork-exec": "git+https://github.com/codetsunami/posix-pipe-fork-exec.git"
}
}

View File

@@ -7,29 +7,6 @@
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz",
"integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ=="
},
"fs-extra": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
"requires": {
"graceful-fs": "^4.2.0",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
},
"graceful-fs": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.2.tgz",
"integrity": "sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q=="
},
"jsonfile": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
"requires": {
"graceful-fs": "^4.1.6"
}
},
"libsodium": {
"version": "0.7.5",
"resolved": "https://registry.npmjs.org/libsodium/-/libsodium-0.7.5.tgz",
@@ -43,11 +20,6 @@
"libsodium": "0.7.5"
}
},
"universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
},
"ws": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.1.2.tgz",

View File

@@ -1,7 +1,6 @@
{
"dependencies": {
"fs-extra": "^8.1.0",
"libsodium-wrappers": "^0.7.5",
"ws": "^7.1.2"
"libsodium-wrappers": "0.7.5",
"ws": "7.1.2"
}
}

View File

@@ -1,51 +0,0 @@
#!/bin/bash
# Hot Pocket - create release package
if [ -z "$1" ]
then
echo "Release Version not specified."
exit 1
fi
RELVERSION="hp-${1}"
RELEASEDIR=./release/$RELVERSION
cmake . -DCMAKE_BUILD_TYPE=Release
make
rm -rf ./release
# Copy hpcore binary
mkdir -p $RELEASEDIR
cp build/hpcore $RELEASEDIR/hpcore
$RELEASEDIR/hpcore new $RELEASEDIR/echocontract
# Copy example client
mkdir $RELEASEDIR/hpclient
cp -r examples/hpclient/client.js $RELEASEDIR/hpclient
cp -r examples/hpclient/package.json $RELEASEDIR/hpclient
echo "npm install hpclient"
npm --prefix $RELEASEDIR/hpclient install > /dev/null 2>&1
# Copy example contract
CTRPATH=./bin/contract.js
CFGPATH=${RELEASEDIR}/echocontract/cfg/hp.cfg
CFGJSON=${RELEASEDIR}/echocontract/cfg/hp.json
mv $CFGPATH $CFGJSON
node -p "JSON.stringify({...require('${CFGJSON}'), binary:'/usr/bin/node', binargs:'${CTRPATH}' }, null, 2)" > $CFGPATH
rm $CFGJSON
mkdir -p $RELEASEDIR/echocontract/bin
cp -r examples/echocontract/contract.js $RELEASEDIR/echocontract/bin
cp -r examples/echocontract/package.json $RELEASEDIR/echocontract/bin
echo "npm install echocontract"
npm --prefix $RELEASEDIR/echocontract/bin install > /dev/null 2>&1
echo "Creating tarball"
tar -C ./release -czf ./release/$RELVERSION.tar.gz $RELVERSION
rm -r $RELEASEDIR
echo "Release tarball has been created at ./release/${RELVERSION}.tar.gz"
# Switch cmake back to Debug build mode
cmake . -DCMAKE_BUILD_TYPE=Debug
exit 0