Skip to content

Commit

Permalink
Merge pull request #890 from thom-nic/prebuildify-and-docker-build
Browse files Browse the repository at this point in the history
  • Loading branch information
recrsn authored Nov 2, 2023
2 parents 2a3c445 + ae21bf1 commit 8350853
Show file tree
Hide file tree
Showing 17 changed files with 367 additions and 901 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*/
124 changes: 124 additions & 0 deletions .github/workflows/build-pack-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Prebuildify, package, publish

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
release:
types: [ prereleased, released ]

jobs:

build:
runs-on: ubuntu-22.04
strategy:
matrix:
os: [linux]
arch: [amd64, arm64, arm]
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:latest
platforms: arm,arm64

- run: >
docker build .
--build-arg TEST_TIMEOUT_SECONDS=30
--tag node-bcrypt-builder
--platform ${{ matrix.os }}/${{ matrix.arch }}
- run: >
docker create
--name node-bcryptjs-builder
--platform ${{ matrix.os }}/${{ matrix.arch }}
node-bcrypt-builder
- run: docker cp "node-bcryptjs-builder:/usr/local/opt/bcrypt-js/prebuilds" .

# build for Alpine:
- run: >
docker build -f Dockerfile-alpine .
--build-arg TEST_TIMEOUT_SECONDS=30
--tag node-bcrypt-builder-alpine
--platform ${{ matrix.os }}/${{ matrix.arch }}
- run: >
docker create
--name node-bcryptjs-builder-alpine
--platform ${{ matrix.os }}/${{ matrix.arch }}
node-bcrypt-builder-alpine
- run: docker cp "node-bcryptjs-builder-alpine:/usr/local/opt/bcrypt-js/prebuilds" .

- run: find prebuilds
- uses: actions/upload-artifact@v3
with:
name: prebuild-${{ matrix.os }}-${{ matrix.arch }}
path: ./prebuilds

pack:
needs: build
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- uses: actions/download-artifact@v2
with:
path: /tmp/prebuilds/
- name: Coalesce prebuilds from build matrix
run: |
mkdir prebuilds
for d in /tmp/prebuilds/*; do
cp -Rav $d/* prebuilds/
done
- run: chmod a+x prebuilds/*/*.node && find prebuilds -executable -type f
- run: echo "PACK_FILE=$(npm pack)" >> $GITHUB_ENV
- uses: actions/upload-artifact@v3
with:
name: package-tgz
path: ${{ env.PACK_FILE }}

publish-npm:
needs: pack
if: github.event_name == 'release'
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
- uses: actions/download-artifact@v2
with:
name: package-tgz
path: /tmp/package/
- run: npm publish /tmp/package/bcrypt*.tgz
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

publish-gpr:
needs: pack
if: github.event_name == 'release'
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
registry-url: https://npm.pkg.github.com/
- uses: actions/download-artifact@v2
with:
name: package-tgz
path: /tmp/package/
- run: npm publish /tmp/package/bcrypt*.tgz
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}




15 changes: 7 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,30 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [18, 20]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: |
sudo apt-get install -y python3 make g++
- run: npm ci
- name: Test
run: npm test

build-alpine:
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [14, 16, 18]
node-version: [18, 20]
container:
image: node:${{ matrix.node-version }}-alpine
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install dependencies
run: |
apk add make g++ python3
- run: npm ci
- name: Test
run: |
npm test --unsafe-perm
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]
62 changes: 0 additions & 62 deletions .travis.yml

This file was deleted.

57 changes: 57 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Usage:
#
# docker build -t bcryptjs-builder .
# CONTAINER=$(docker create bcryptjs-builder)
# # Then copy the artifact to your host:
# docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" .
# docker rm "$CONTAINER"
#
# Use --platform to build cross-platform i.e. for ARM:
#
# docker build -t bcryptjs-builder --platform "linux/arm64/v8" .
# CONTAINER=$docker create --platform "linux/arm64/v8" bcryptjs-builder)
# # this copies the prebuilds/linux-arm artifacts
# docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" .
# docker rm "$CONTAINER"


ARG FROM_IMAGE=node:18-bullseye
#ARG FROM_IMAGE=arm32v7/node:16-bullseye
#ARG FROM_IMAGE=arm64v8/node:16-bullseye
FROM ${FROM_IMAGE}

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@5 node-gyp@9 \
&& sync

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

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

ARG RUN_TESTS=true
ARG TEST_TIMEOUT_SECONDS=

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

CMD /bin/bash -l
41 changes: 41 additions & 0 deletions Dockerfile-alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Usage:
#
# docker build -t bcryptjs-linux-alpine-builder -f Dockerfile-alpine .
# CONTAINER=$(docker create bcryptjs-linux-alpine-builder)
# # Then copy the artifact to your host:
# docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" .
# docker rm "$CONTAINER"

ARG FROM_IMAGE=node:18-alpine
FROM ${FROM_IMAGE}

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 \
&& apk add --update build-base python3 \
&& npm i -g prebuildify@5 node-gyp@9 \
&& sync

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

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

ARG RUN_TESTS=true
ARG TEST_TIMEOUT_SECONDS=

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

CMD /bin/bash -l
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ compile:
npm run install

test: build
@./node_modules/nodeunit/bin/nodeunit \
@./node_modules/.bin/jest \
$(TESTS)

clean:
Expand Down
39 changes: 0 additions & 39 deletions appveyor.yml

This file was deleted.

Loading

0 comments on commit 8350853

Please sign in to comment.