Skip to content

Commit

Permalink
Remove node-pre-gyp, use prebuildify
Browse files Browse the repository at this point in the history
Added Dockerfiles for cross-platform build.
  • Loading branch information
thom-nic committed Oct 27, 2023
1 parent 2a3c445 commit 4de3ed6
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 769 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git/
.vscode/
Dockerfile*
prebuilds/
node_modules/
build*/
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.lock*
build*
build*/
*.node
*.sw[a-z]
node_modules
.idea/
prebuilds/
*.tgz
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.lock*
build*/
*.sw[a-z]
67 changes: 67 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/echo docker build . -f
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: ISC
# Copyright 2021 VoltServer Inc
#{
# ISC License
# Copyright (c) 2004-2010 by Internet Systems Consortium, Inc. ("ISC")
# Copyright (c) 1995-2003 by Internet Software Consortium
# Permission to use, copy, modify, and /or distribute this software
# for any purpose with or without fee is hereby granted,
# provided that the above copyright notice
# and this permission notice appear in all copies.
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS.
# IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE
# OR PERFORMANCE OF THIS SOFTWARE.
#}
#
# Usage:
#
# docker build -t voltserver/bcryptjs-linux-x64-builder .
# docker create --name donut voltserver/bcryptjs-linux-x64-builder
# # Then copy the artifact to your host:
# docker cp donut:/usr/local/opt/bcrypt-js/prebuilds .

FROM node:14-bullseye

ENV project bcrypt-js
ENV DEBIAN_FRONTEND noninteractive
ENV LC_ALL en_US.UTF-8
ENV LANG ${LC_ALL}

RUN echo "#log: ${project}: Setup system" \
&& set -x \
&& apt-get update -y \
&& apt-get install -y \
build-essential \
python3 \
&& apt-get clean \
&& update-alternatives --install /usr/local/bin/python python /usr/bin/python3 20 \
&& npm i -g prebuildify node-gyp \
&& sync

ADD . /usr/local/opt/${project}
WORKDIR /usr/local/opt/${project}

RUN echo "#log: ${project}: Running build" \
&& set -x \
&& npm i \
&& npm run build

ARG RUN_TESTS=true

RUN if "${RUN_TESTS}"; then \
echo "#log ${project}: Running tests" \
&& npm test; \
else \
echo "#log ${project}: Tests were skipped!"; \
fi

CMD /bin/bash -l
43 changes: 43 additions & 0 deletions Dockerfile-arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Usage:
#
# docker build -t bcryptjs-linux-arm-builder -f Dockerfile-arm .
# docker create --name donut bcryptjs-linux-arm-builder
# # Then copy the artifact to your host:
# docker cp donut:/usr/local/opt/bcrypt-js/prebuilds .

FROM arm32v7/node:14-bullseye

ENV project bcrypt-js
ENV DEBIAN_FRONTEND noninteractive
ENV LC_ALL en_US.UTF-8
ENV LANG ${LC_ALL}

RUN echo "#log: ${project}: Setup system" \
&& set -x \
&& apt-get update -y \
&& apt-get install -y \
build-essential \
python3 \
&& apt-get clean \
&& update-alternatives --install /usr/local/bin/python python /usr/bin/python3 20 \
&& npm i -g prebuildify node-gyp \
&& sync

ADD . /usr/local/opt/${project}
WORKDIR /usr/local/opt/${project}

RUN echo "#log: ${project}: Running build" \
&& set -x \
&& npm i \
&& npm run build

ARG RUN_TESTS=true

RUN if "${RUN_TESTS}"; then \
echo "#log ${project}: Running tests" \
&& npm test; \
else \
echo "#log ${project}: Tests were skipped!"; \
fi

CMD /bin/bash -l
44 changes: 44 additions & 0 deletions Dockerfile-arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Usage:
#
# docker build -t bcryptjs-linux-arm64-builder -f Dockerfile-arm64 .
# docker create --name donut-arm64 bcryptjs-linux-arm64-builder
# # Then copy the artifact to your host:
# docker cp donut-arm64:/usr/local/opt/bcrypt-js/prebuilds .

FROM arm64v8/node:14-bullseye

ENV project bcrypt-js
ENV DEBIAN_FRONTEND noninteractive
ENV LC_ALL en_US.UTF-8
ENV LANG ${LC_ALL}

RUN echo "#log: ${project}: Setup system" \
&& set -x \
&& apt-get update -y \
&& apt-get install -y \
build-essential \
python3 \
&& apt-get clean \
&& update-alternatives --install /usr/local/bin/python python /usr/bin/python3 20 \
&& npm i -g prebuildify node-gyp \
&& sync

ADD . /usr/local/opt/${project}
WORKDIR /usr/local/opt/${project}

RUN echo "#log: ${project}: Running build" \
&& set -x \
&& npm i \
&& npm run build

ARG RUN_TESTS=true

RUN if "${RUN_TESTS}"; then \
echo "#log ${project}: Running tests" \
&& npm test; \
else \
echo "#log ${project}: Tests were skipped!"; \
fi

CMD /bin/bash -l

4 changes: 1 addition & 3 deletions bcrypt.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';

var nodePreGyp = require('@mapbox/node-pre-gyp');
var path = require('path');
var binding_path = nodePreGyp.find(path.resolve(path.join(__dirname, './package.json')));
var bindings = require(binding_path);
var bindings = require('node-gyp-build')(path.resolve(__dirname));

var crypto = require('crypto');

Expand Down
11 changes: 0 additions & 11 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,5 @@
}],
],
},
{
"target_name": "action_after_build",
"type": "none",
"dependencies": [ "<(module_name)" ],
"copies": [
{
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
"destination": "<(module_path)"
}
]
}
]
}
39 changes: 39 additions & 0 deletions build-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash -ue

CLEAN=${CLEAN:-""}
RUN_TESTS=${RUN_TESTS:-false} # tests presently fail on arm :(

if [ -n "$CLEAN" ]; then
rm -rf build build-tmp*
rm -rf prebuilds
fi

npm i
npm i -g prebuildify node-gyp
npm run build

# build for linux/x64:
if [ ! -d prebuilds/linux-x64 ]; then
docker build -t voltserver/bcryptjs-linux-x64-builder .
CONTAINER=$(docker create voltserver/bcryptjs-linux-x64-builder)
docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" .
docker rm "$CONTAINER"
fi

# build for linux/arm32:
if [ ! -d prebuilds/linux-arm ]; then
docker build -t voltserver/bcryptjs-linux-arm-builder -f Dockerfile-arm --build-arg RUN_TESTS="$RUN_TESTS" .
CONTAINER=$(docker create --platform linux/arm/v7 voltserver/bcryptjs-linux-arm-builder)
docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" .
docker rm "$CONTAINER"
fi

# build for linux/arm64:
if [ ! -d prebuilds/linux-arm64 ]; then
docker build -t voltserver/bcryptjs-linux-arm64-builder -f Dockerfile-arm64 --build-arg RUN_TESTS="$RUN_TESTS" .
CONTAINER=$(docker create --platform linux/arm64/v8 voltserver/bcryptjs-linux-arm64-builder)
docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" .
docker rm "$CONTAINER"
fi

ls -lF prebuilds/
Loading

0 comments on commit 4de3ed6

Please sign in to comment.