Ops
Search…
CrossBuilding
OPS has initial support for cross-building Nanos unikernels on a Mac. Nanos uses the ELF binary format just like Linux so when building with OPS on Linux using 'run' or 'instance create' locally libraries are resolved appropriately and loaded onto the disk image.
For many use-cases this works the same on Mac. For statically linked builds produced by Go or Rust you won't have any trouble and for simple projects using official Node, Ruby, Python packages you shouldn't have any trouble.
However, there are times when you might need a native Linux environment to build a c library and then load it in a package.
For instance if you wanted to use the redis-fast-driver in NPM, in the past you might'e spun up a docker container and built it there or spun up a Linux vm and built it there. This is where the OPS cross-build environment capability comes into play. It spins up a small linux vm, executes your build instructions and then allows you to spit out the artifacts to your host system (MacOS in this case). This allows you to build native add-ons without resorting to a full-blown Linux vm or docker (which runs inside of a linux vm regardless).

Example

To get started first you need to create an env. This downloads and instatitates a cross-build environment:
1
$ ops env install
Copied!
Now we'll specify our build steps like so in a build.txt:
1
apt-get install -y nodejs make gcc g++
2
npm install redis-fast-driver --save
Copied!
We'll also specify a config detailing what we'd like to extract from the build-environment. In this case the node_modules directory and the node binary with it's linked libraries:
1
{
2
"Dirs": ["node_modules"],
3
"Program": "/usr/bin/node"
4
}
Copied!
Now we build. This runs the commands found in build.txt in the vm and then copies the artifacts back out to the host:
1
$ ops env build build.txt -c config.json -r .
Copied!
You'll notice you now have all the appropriate files:
1
$ redis-test ls
2
build.txt config.json config_1.json example.js lib
3
lib64 node node_modules usr
Copied!
1
$ redis-test tree lib*
2
lib
3
└── x86_64-linux-gnu
4
├── libc.so.6
5
├── libdl.so.2
6
├── libgcc_s.so.1
7
├── libm.so.6
8
├── libpthread.so.0
9
└── libstdc++.so.6
10
lib64
11
└── ld-linux-x86-64.so.2
12
13
1 directory, 7 files
Copied!
Now we can test with another json for running our custom node build on Mac:
1
{
2
"Dirs": ["node_modules"],
3
"Files": ["/lib/x86_64-linux-gnu/libstdc++.so.6", "example.js"],
4
"Program": "/usr/bin/node",
5
"Args": ["example.js"]
6
}
Copied!
Now your node example is running as a Nanos unikernel on Mac without a linux vm involved.
1
$ redis-test ops run usr/bin/node -c config_1.json -r .
2
3
booting /Users/eyberg/.ops/images/node.img ...
4
en1: assigned 10.0.2.15
5
en1: assigned FE80::FC65:67FF:FEF2:F10D
6
====================================================
7
Start test: PING command 2500 times
Copied!
Last modified 3mo ago
Copy link
Contents
Example