Skip to content

Commit 8350853

Browse files
authored
Merge pull request #890 from thom-nic/prebuildify-and-docker-build
2 parents 2a3c445 + ae21bf1 commit 8350853

17 files changed

+367
-901
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.git/
2+
.vscode/
3+
Dockerfile*
4+
prebuilds/
5+
node_modules/
6+
build*/
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Prebuildify, package, publish
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
release:
9+
types: [ prereleased, released ]
10+
11+
jobs:
12+
13+
build:
14+
runs-on: ubuntu-22.04
15+
strategy:
16+
matrix:
17+
os: [linux]
18+
arch: [amd64, arm64, arm]
19+
steps:
20+
- uses: actions/checkout@v4
21+
- uses: docker/setup-qemu-action@v3
22+
with:
23+
image: tonistiigi/binfmt:latest
24+
platforms: arm,arm64
25+
26+
- run: >
27+
docker build .
28+
--build-arg TEST_TIMEOUT_SECONDS=30
29+
--tag node-bcrypt-builder
30+
--platform ${{ matrix.os }}/${{ matrix.arch }}
31+
- run: >
32+
docker create
33+
--name node-bcryptjs-builder
34+
--platform ${{ matrix.os }}/${{ matrix.arch }}
35+
node-bcrypt-builder
36+
- run: docker cp "node-bcryptjs-builder:/usr/local/opt/bcrypt-js/prebuilds" .
37+
38+
# build for Alpine:
39+
- run: >
40+
docker build -f Dockerfile-alpine .
41+
--build-arg TEST_TIMEOUT_SECONDS=30
42+
--tag node-bcrypt-builder-alpine
43+
--platform ${{ matrix.os }}/${{ matrix.arch }}
44+
- run: >
45+
docker create
46+
--name node-bcryptjs-builder-alpine
47+
--platform ${{ matrix.os }}/${{ matrix.arch }}
48+
node-bcrypt-builder-alpine
49+
- run: docker cp "node-bcryptjs-builder-alpine:/usr/local/opt/bcrypt-js/prebuilds" .
50+
51+
- run: find prebuilds
52+
- uses: actions/upload-artifact@v3
53+
with:
54+
name: prebuild-${{ matrix.os }}-${{ matrix.arch }}
55+
path: ./prebuilds
56+
57+
pack:
58+
needs: build
59+
runs-on: ubuntu-22.04
60+
steps:
61+
- uses: actions/checkout@v4
62+
- uses: actions/setup-node@v3
63+
with:
64+
node-version: 20
65+
registry-url: 'https://registry.npmjs.org'
66+
- run: npm ci
67+
- uses: actions/download-artifact@v2
68+
with:
69+
path: /tmp/prebuilds/
70+
- name: Coalesce prebuilds from build matrix
71+
run: |
72+
mkdir prebuilds
73+
for d in /tmp/prebuilds/*; do
74+
cp -Rav $d/* prebuilds/
75+
done
76+
- run: chmod a+x prebuilds/*/*.node && find prebuilds -executable -type f
77+
- run: echo "PACK_FILE=$(npm pack)" >> $GITHUB_ENV
78+
- uses: actions/upload-artifact@v3
79+
with:
80+
name: package-tgz
81+
path: ${{ env.PACK_FILE }}
82+
83+
publish-npm:
84+
needs: pack
85+
if: github.event_name == 'release'
86+
runs-on: ubuntu-22.04
87+
steps:
88+
- uses: actions/checkout@v4
89+
- uses: actions/setup-node@v3
90+
with:
91+
node-version: 20
92+
registry-url: 'https://registry.npmjs.org'
93+
- uses: actions/download-artifact@v2
94+
with:
95+
name: package-tgz
96+
path: /tmp/package/
97+
- run: npm publish /tmp/package/bcrypt*.tgz
98+
env:
99+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
100+
101+
publish-gpr:
102+
needs: pack
103+
if: github.event_name == 'release'
104+
runs-on: ubuntu-22.04
105+
permissions:
106+
contents: read
107+
packages: write
108+
steps:
109+
- uses: actions/checkout@v4
110+
- uses: actions/setup-node@v3
111+
with:
112+
node-version: 20
113+
registry-url: https://npm.pkg.github.com/
114+
- uses: actions/download-artifact@v2
115+
with:
116+
name: package-tgz
117+
path: /tmp/package/
118+
- run: npm publish /tmp/package/bcrypt*.tgz
119+
env:
120+
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
121+
122+
123+
124+

.github/workflows/ci.yaml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,30 @@ jobs:
1313
runs-on: ubuntu-22.04
1414
strategy:
1515
matrix:
16-
node-version: [14.x, 16.x, 18.x]
16+
node-version: [18, 20]
1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v4
1919
- name: Use Node.js ${{ matrix.node-version }}
20-
uses: actions/setup-node@v1
20+
uses: actions/setup-node@v3
2121
with:
2222
node-version: ${{ matrix.node-version }}
23-
- name: Install dependencies
24-
run: |
25-
sudo apt-get install -y python3 make g++
23+
- run: npm ci
2624
- name: Test
2725
run: npm test
2826

2927
build-alpine:
3028
runs-on: ubuntu-22.04
3129
strategy:
3230
matrix:
33-
node-version: [14, 16, 18]
31+
node-version: [18, 20]
3432
container:
3533
image: node:${{ matrix.node-version }}-alpine
3634
steps:
37-
- uses: actions/checkout@v2
35+
- uses: actions/checkout@v4
3836
- name: Install dependencies
3937
run: |
4038
apk add make g++ python3
39+
- run: npm ci
4140
- name: Test
4241
run: |
4342
npm test --unsafe-perm

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.lock*
2-
build*
2+
build*/
33
*.node
44
*.sw[a-z]
55
node_modules
66
.idea/
7+
prebuilds/
8+
*.tgz

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.lock*
2+
build*/
3+
*.sw[a-z]

.travis.yml

Lines changed: 0 additions & 62 deletions
This file was deleted.

Dockerfile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Usage:
2+
#
3+
# docker build -t bcryptjs-builder .
4+
# CONTAINER=$(docker create bcryptjs-builder)
5+
# # Then copy the artifact to your host:
6+
# docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" .
7+
# docker rm "$CONTAINER"
8+
#
9+
# Use --platform to build cross-platform i.e. for ARM:
10+
#
11+
# docker build -t bcryptjs-builder --platform "linux/arm64/v8" .
12+
# CONTAINER=$docker create --platform "linux/arm64/v8" bcryptjs-builder)
13+
# # this copies the prebuilds/linux-arm artifacts
14+
# docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" .
15+
# docker rm "$CONTAINER"
16+
17+
18+
ARG FROM_IMAGE=node:18-bullseye
19+
#ARG FROM_IMAGE=arm32v7/node:16-bullseye
20+
#ARG FROM_IMAGE=arm64v8/node:16-bullseye
21+
FROM ${FROM_IMAGE}
22+
23+
ENV project bcrypt-js
24+
ENV DEBIAN_FRONTEND noninteractive
25+
ENV LC_ALL en_US.UTF-8
26+
ENV LANG ${LC_ALL}
27+
28+
RUN echo "#log: ${project}: Setup system" \
29+
&& set -x \
30+
&& apt-get update -y \
31+
&& apt-get install -y \
32+
build-essential \
33+
python3 \
34+
&& apt-get clean \
35+
&& update-alternatives --install /usr/local/bin/python python /usr/bin/python3 20 \
36+
&& npm i -g prebuildify@5 node-gyp@9 \
37+
&& sync
38+
39+
ADD . /usr/local/opt/${project}
40+
WORKDIR /usr/local/opt/${project}
41+
42+
RUN echo "#log: ${project}: Running build" \
43+
&& set -x \
44+
&& npm ci \
45+
&& npm run build
46+
47+
ARG RUN_TESTS=true
48+
ARG TEST_TIMEOUT_SECONDS=
49+
50+
RUN if "${RUN_TESTS}"; then \
51+
echo "#log ${project}: Running tests" \
52+
&& npm test; \
53+
else \
54+
echo "#log ${project}: Tests were skipped!"; \
55+
fi
56+
57+
CMD /bin/bash -l

Dockerfile-alpine

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Usage:
2+
#
3+
# docker build -t bcryptjs-linux-alpine-builder -f Dockerfile-alpine .
4+
# CONTAINER=$(docker create bcryptjs-linux-alpine-builder)
5+
# # Then copy the artifact to your host:
6+
# docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" .
7+
# docker rm "$CONTAINER"
8+
9+
ARG FROM_IMAGE=node:18-alpine
10+
FROM ${FROM_IMAGE}
11+
12+
ENV project bcrypt-js
13+
ENV DEBIAN_FRONTEND noninteractive
14+
ENV LC_ALL en_US.UTF-8
15+
ENV LANG ${LC_ALL}
16+
17+
RUN echo "#log: ${project}: Setup system" \
18+
&& set -x \
19+
&& apk add --update build-base python3 \
20+
&& npm i -g prebuildify@5 node-gyp@9 \
21+
&& sync
22+
23+
ADD . /usr/local/opt/${project}
24+
WORKDIR /usr/local/opt/${project}
25+
26+
RUN echo "#log: ${project}: Running build" \
27+
&& set -x \
28+
&& npm ci \
29+
&& npm run build
30+
31+
ARG RUN_TESTS=true
32+
ARG TEST_TIMEOUT_SECONDS=
33+
34+
RUN if "${RUN_TESTS}"; then \
35+
echo "#log ${project}: Running tests" \
36+
&& npm test; \
37+
else \
38+
echo "#log ${project}: Tests were skipped!"; \
39+
fi
40+
41+
CMD /bin/bash -l

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ compile:
99
npm run install
1010

1111
test: build
12-
@./node_modules/nodeunit/bin/nodeunit \
12+
@./node_modules/.bin/jest \
1313
$(TESTS)
1414

1515
clean:

appveyor.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)