Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing and invalid compilation of virgil_js.node #7

Closed
the-boj opened this issue Jan 23, 2018 · 2 comments
Closed

Missing and invalid compilation of virgil_js.node #7

the-boj opened this issue Jan 23, 2018 · 2 comments

Comments

@the-boj
Copy link

the-boj commented Jan 23, 2018

First of all, the file virgil_js.node require by ./src/node/index.js is missing, he should be in main folder.
When i DL the lib by npm, the file is here this time, but when added to the whole folder, we get this error when require in a nodeJS project :
"errorMessage": "/var/task/virgil/src/virgil-crypto/virgil_js.node: invalid ELF header"
and i found that the file was missing thanks to this error line :
"Object. (/var/task/virgil/src/virgil-crypto/src/node/index.js:1:76)"

I'm building on a lambda machine on AWS, i tried nodeJS 6.10 and nodeJS 4.3 too
May someone could help me ?
Thanks

@vadimavdeev
Copy link
Contributor

vadimavdeev commented Jan 23, 2018

The virgil_js.node is a binary native addon. It has to be compiled for the target Node.js version, OS and architecture. Normally, addons are compiled on your system when you install the package that has them using a tool called node-gyp. However, due to complexity of using that tool to build C++ virgil-crypto library, we decided to take a different approach. We pre-compile the binaries and store them on our CDN. When you install the virgil-crypto package, it tries to download a binary that is compatible with your Node.js version and OS and save it as virgil_js.node. It prints an error message to the console if there is no matching binary. The most likely reason it failed to download the file, is because you have a Node.js version 7 or higher. Currently, only versions 4.x - 6.x are supported.
So to install and test locally, you can either install Node.js 6 using a tool like nvm, or if you have Node 8 or later, use npx.
As for deploying to AWS Lambda, you can use this script as an example of how to package your app:

#!/bin/bash

E_ASSERT_FAILED=99

if [ ! ${LAMBDA_FUNCTION_NAME} ]
then
    echo "Environment variable LAMBDA_FUNCTION_NAME is not set."
    echo "Must be the name of the Lambda Function to update."
    exit ${E_ASSERT_FAILED}
fi

# build the project
if ! npm run build; then
    echo "Build failed. Exiting."
    exit $?
fi

# create a folder to temporarily store build files
mkdir temp

# copy source files to temporary folder
rsync -a node_modules/ temp/node_modules --exclude '.bin'
cp -a ./dist/index.js temp

# copy package.json so we can "npm prune" later
cp -a ./package.json temp

# replace the native crypto library in virgil-crypto module with the one
# supported by Amazon Lambda (nodejs-6.1.0-linux-x86_64) You can get it form Virgil CDN
cp ./virgil-crypto-2.1.2-nodejs-6.1.0-linux-x86_64.node temp/node_modules/virgil-crypto/virgil_js.node

cd temp

# remove devDependencies from node_modules
npm prune --production

# zip source files together
zip -rq ./index.zip index.js node_modules/

# update AWS Lambda
aws lambda update-function-code --function-name ${LAMBDA_FUNCTION_NAME} --zip-file fileb://index.zip

# copy latest zip to the dist folder
cp -a index.zip ../dist
cd ..

# remove temp dir
rm -r temp

echo "Done!"

Place this script in your project's root folder as deploy.sh and then run

LAMBDA_FUNCTION_NAME=MyFunction ./deploy.sh

Please note, that you need aws-cli installed for this script to succeed.

@the-boj
Copy link
Author

the-boj commented Jan 24, 2018

Thank you very much, exactly what i needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants