verida / network-data-api

An API that returns public data from the Verida network
0 stars 0 forks source link

App cannot be deployed from MacOS #6

Open nick-verida opened 1 year ago

nick-verida commented 1 year ago

Currently deploying this app from MacOS doen't work, because we get this when deployed:

"/var/task/node_modules/leveldown/build/Release/leveldown.node: invalid ELF header",

This is because leveldown is build on Mac but deployed on Linux.

Adding this to serverless.xml should work but has stopped for some reason:

  webpack:
    includeModules: true
    packagerOptions:
      scripts:
        - npm_config_platform=linux npm_config_arch=x64 yarn add leveldown

Currently I'm deploy via a docker build. This was non-trivial, but a few notes:

On the Mac, rm -rf node_modules to make sure we get rid of Mac versions

# run docker mapping the path things are checkout out at to a `/working` directory inside docker
docker run -v ~/dev/verida/network-data-api:/working -it --rm ubuntu

# Now we are in docker (Ubuntu)
apt update
apt install unzip nodejs npm curl
cd /root

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip" # NOTE the ARM version is needed!
unzip awscliv2.zip
./aws/install

cd /working
nvm install # install and use the correct node version
nvm use
 # add the AWS deployment keys
# most script now specify which profile to use
/usr/local/bin/aws configure --profile verida-original
/usr/local/bin/aws configure --profile verida-testnet
/usr/local/bin/aws configure --profile verida-mainnet
npm install --global yarn
yarn # do the build
yarn deploy-prod # deploy!
nick-verida commented 10 months ago

I've seen this elsewhere too, so have documented this here: https://github.com/verida/infrastructure/blob/develop/Linux_Build_on_MacOS.md

nick-verida commented 6 months ago

You get this if you are using arm64 architecture (which you want!) in the terminal. You can see by running the arch command.