diff --git a/.github/workflows/build-pack-publish.yml b/.github/workflows/build-pack-publish.yml index a5ef4a0..4236c4f 100644 --- a/.github/workflows/build-pack-publish.yml +++ b/.github/workflows/build-pack-publish.yml @@ -14,21 +14,35 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - arch: [x64, arm, arm64, alpine, alpine-arm, alpine-arm64] + platform: [linux/amd64, linux/arm64/v8, linux/arm/v7] steps: - uses: actions/checkout@v2 - uses: docker/setup-qemu-action@v1 with: image: tonistiigi/binfmt:latest - platforms: arm,arm64 #all - - run: docker build . -f ./Dockerfile-${{ matrix.arch }} - --tag node-bcrypt-builder-${{ matrix.arch }} - - run: docker create --name node-bcryptjs-builder node-bcrypt-builder-${{ matrix.arch }} + platforms: arm,arm64 + + - run: docker build . + --tag node-bcrypt-builder + --platform ${{ matrix.platform }} + - run: docker create node-bcrypt-builder + --platform ${{ matrix.platform }} + --name node-bcryptjs-builder - run: docker cp "node-bcryptjs-builder:/usr/local/opt/bcrypt-js/prebuilds" . + + # build for Alpine: + - run: docker build -f Dockerfile-alpine . + --tag node-bcrypt-builder-alpine + --platform ${{ matrix.platform }} + - run: docker create node-bcrypt-builder-alpine + --platform ${{ matrix.platform }} + --name node-bcryptjs-builder-alpine + - run: docker cp "node-bcryptjs-builder-alpine:/usr/local/opt/bcrypt-js/prebuilds" . + - run: find prebuilds - uses: actions/upload-artifact@v2 with: - name: prebuild-${{ matrix.arch }} + name: prebuild-${{ matrix.platform }} path: ./prebuilds pack: diff --git a/Dockerfile-arm b/Dockerfile similarity index 55% rename from Dockerfile-arm rename to Dockerfile index 3e13638..da3b22f 100755 --- a/Dockerfile-arm +++ b/Dockerfile @@ -1,11 +1,24 @@ # Usage: # -# docker build -t bcryptjs-linux-arm-builder -f Dockerfile-arm . -# docker create --name donut bcryptjs-linux-arm-builder +# docker build -t bcryptjs-builder . +# CONTAINER=$(docker create bcryptjs-builder) # # Then copy the artifact to your host: -# docker cp donut:/usr/local/opt/bcrypt-js/prebuilds . +# 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" + -FROM arm32v7/node:16-bullseye +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 diff --git a/Dockerfile-alpine b/Dockerfile-alpine index 8d700ae..7ee6206 100755 --- a/Dockerfile-alpine +++ b/Dockerfile-alpine @@ -6,7 +6,8 @@ # docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" . # docker rm "$CONTAINER" -FROM node:16-alpine +ARG FROM_IMAGE=node:18-alpine +FROM ${FROM_IMAGE} ENV project bcrypt-js ENV DEBIAN_FRONTEND noninteractive diff --git a/Dockerfile-alpine-arm b/Dockerfile-alpine-arm deleted file mode 100755 index 8e1421e..0000000 --- a/Dockerfile-alpine-arm +++ /dev/null @@ -1,39 +0,0 @@ -# Usage: -# -# docker build -t bcryptjs-alpine-arm-builder -f Dockerfile-arm . -# CONTAINER=$(docker create bcryptjs-alpine-arm-builder) -# # Then copy the artifact to your host: -# docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" . -# docker rm "$CONTAINER" - -FROM arm32v7/node:16-alpine - -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 - -RUN if "${RUN_TESTS}"; then \ - echo "#log ${project}: Running tests" \ - && npm test; \ - else \ - echo "#log ${project}: Tests were skipped!"; \ - fi - -CMD /bin/bash -l diff --git a/Dockerfile-alpine-arm64 b/Dockerfile-alpine-arm64 deleted file mode 100755 index 0ea04fe..0000000 --- a/Dockerfile-alpine-arm64 +++ /dev/null @@ -1,39 +0,0 @@ -# Usage: -# -# docker build -t bcryptjs-alpine-arm-builder -f Dockerfile-arm . -# CONTAINER=$(docker create bcryptjs-alpine-arm-builder) -# # Then copy the artifact to your host: -# docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" . -# docker rm "$CONTAINER" - -FROM arm64v8/node:16-alpine - -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 - -RUN if "${RUN_TESTS}"; then \ - echo "#log ${project}: Running tests" \ - && npm test; \ - else \ - echo "#log ${project}: Tests were skipped!"; \ - fi - -CMD /bin/bash -l diff --git a/Dockerfile-arm64 b/Dockerfile-arm64 deleted file mode 100755 index 8d356f1..0000000 --- a/Dockerfile-arm64 +++ /dev/null @@ -1,44 +0,0 @@ -# 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:16-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@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 - -RUN if "${RUN_TESTS}"; then \ - echo "#log ${project}: Running tests" \ - && npm test; \ - else \ - echo "#log ${project}: Tests were skipped!"; \ - fi - -CMD /bin/bash -l - diff --git a/Dockerfile-x64 b/Dockerfile-x64 deleted file mode 100755 index e6fc7a3..0000000 --- a/Dockerfile-x64 +++ /dev/null @@ -1,43 +0,0 @@ -# Usage: -# -# docker build -t bcryptjs-linux-x64-builder . -# docker create --name donut bcryptjs-linux-x64-builder -# # Then copy the artifact to your host: -# docker cp donut:/usr/local/opt/bcrypt-js/prebuilds . - -FROM node:16-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@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 - -RUN if "${RUN_TESTS}"; then \ - echo "#log ${project}: Running tests" \ - && npm test; \ - else \ - echo "#log ${project}: Tests were skipped!"; \ - fi - -CMD /bin/bash -l diff --git a/build-all.sh b/build-all.sh index fcd89ab..5c99566 100755 --- a/build-all.sh +++ b/build-all.sh @@ -1,39 +1,37 @@ #!/bin/bash -ue CLEAN=${CLEAN:-""} -RUN_TESTS=${RUN_TESTS:-true} +RUN_TESTS=${RUN_TESTS:-true}l if [ -n "$CLEAN" ]; then rm -rf build build-tmp* + rm -rf lib/binding rm -rf prebuilds fi -npm i npm i -g prebuildify node-gyp -npm run build +npm ci +#npm run build -# build for linux/x64: -if [ ! -d prebuilds/linux-x64 ]; then - docker build -t bcryptjs-linux-x64-builder -f Dockerfile-x64 --build-arg RUN_TESTS="$RUN_TESTS" . - CONTAINER=$(docker create bcryptjs-linux-x64-builder) +for PLATFORM in linux/amd64 linux/arm64/v8 linux/arm/v7; do + echo -- build for $PLATFORM -- + BUILDER_NAME="bcryptjs-${PLATFORM//\/-}-builder" + docker build -t "$BUILDER_NAME" \ + --build-arg RUN_TESTS="$RUN_TESTS" \ + --platform "$PLATFORM" . + CONTAINER=$(docker create --platform "$PLATFORM" "$BUILDER_NAME") 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 bcryptjs-linux-arm-builder -f Dockerfile-arm --build-arg RUN_TESTS="$RUN_TESTS" . - CONTAINER=$(docker create --platform linux/arm/v7 bcryptjs-linux-arm-builder) + echo -- build for $PLATFORM Alpine -- + BUILDER_NAME="bcryptjs-${PLATFORM//\/-}-alpine-builder" + docker build -t "$BUILDER_NAME" -f Dockerfile-alpine \ + --build-arg RUN_TESTS="$RUN_TESTS" \ + --platform "$PLATFORM" . + CONTAINER=$(docker create --platform "$PLATFORM" "$BUILDER_NAME") 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 bcryptjs-linux-arm64-builder -f Dockerfile-arm64 --build-arg RUN_TESTS="$RUN_TESTS" . - CONTAINER=$(docker create --platform linux/arm64/v8 bcryptjs-linux-arm64-builder) - docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" . - docker rm "$CONTAINER" -fi +done ls -lF prebuilds/