From f4d829c34d20a65754c89492cbc35e6151c45742 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sat, 7 Aug 2021 14:18:09 +0200 Subject: [PATCH 1/5] Breaking: bump Python from 2.x to 3.x (#15) As is required for latest `node-gyp`. Some images already had Python 3 installed, now alpine and centos7-devtoolset7 do too, additionally with the `python` command linked to `python3`. Meaning `python -V` will print a 3.x version number. On centos7-devtoolset7, Python 2 remains installed because `yum` relies on it. It can also be accessed as the `python2` command. --- README.md | 6 ++---- alpine/Dockerfile | 4 +++- centos7-devtoolset7/Dockerfile | 9 +++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c4b5613..4f36a45 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ ## About -All images include `node`, `npm`, `npx` and a preconfigured build toolchain suitable for `node-gyp` and `prebuildify`. For example: +All images include Node.js LTS, Python 3.x, npm and a preconfigured build toolchain suitable for `node-gyp` and `prebuildify`. For example: ``` -> docker run --rm -it ghcr.io/prebuild/alpine node -v +> docker run --rm ghcr.io/prebuild/alpine node -v v14.17.4 ``` @@ -25,8 +25,6 @@ FROM ghcr.io/prebuild/alpine:1 Within a major version range, we will not change toolchains, environment variables, working directories, users and more. However, the Node.js version will change without notice. We use Node.js [LTS](https://github.com/nodejs/Release) (at the time of building images) for a light maintenance effort. This is okay because `prebuildify` can target (the headers of) older Node.js versions while itself running on a newer version. -We've yet to align Python versions ([#15](https://github.com/prebuild/docker-images/issues/15)). A next major will use Python 3. - Images that are based on [`dockcross`](https://github.com/dockcross/dockcross) (see below) may inadvertently introduce breaking changes because `dockcross` does not use semantic versions ([dockcross/dockcross#399](https://github.com/dockcross/dockcross/issues/399)) and does not maintain a changelog that would allow us to easily categorize changes and then tag our images accordingly. If this concerns you we recommend pinning to an exact version (`x.x.x`) which we treat as immutable. ## Images diff --git a/alpine/Dockerfile b/alpine/Dockerfile index eaa706b..c4e34f0 100644 --- a/alpine/Dockerfile +++ b/alpine/Dockerfile @@ -2,7 +2,9 @@ FROM node:lts-alpine RUN addgroup -g 2000 travis && \ adduser -u 2000 -G travis -s /bin/sh -D travis && \ - apk --no-cache add g++ gcc libgcc libstdc++ linux-headers make python git + apk --no-cache add g++ gcc libgcc libstdc++ linux-headers make python3 git && \ + ln -sf python3 /usr/bin/python && \ + python --version USER node diff --git a/centos7-devtoolset7/Dockerfile b/centos7-devtoolset7/Dockerfile index 1c9b1de..7ce1264 100644 --- a/centos7-devtoolset7/Dockerfile +++ b/centos7-devtoolset7/Dockerfile @@ -5,8 +5,13 @@ USER 0 RUN groupadd -g 1000 node && useradd -g 1000 -u 1000 -m node && \ groupadd -g 2000 travis && useradd -g 2000 -u 2000 -m travis && \ curl -fsSL https://rpm.nodesource.com/setup_lts.x | bash - && \ - yum install -y make nodejs && \ - npm -v + yum install -y make nodejs python3 && \ + sed -i 's/#!\/usr\/bin\/python/#!\/usr\/bin\/python2/' /usr/bin/yum && \ + ln -sf python3 /usr/bin/python && \ + yum clean all && \ + rm -rf /var/cache/yum && \ + npm -v && \ + python --version USER node From 8ef259e2a26ace20447d62c73543b3f50feb7221 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sun, 27 Feb 2022 13:35:39 +0100 Subject: [PATCH 2/5] Fix `strip` location in android images --- android-arm64/Dockerfile | 4 ++-- android-armv7/Dockerfile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/android-arm64/Dockerfile b/android-arm64/Dockerfile index 8d47e55..dcf10ea 100644 --- a/android-arm64/Dockerfile +++ b/android-arm64/Dockerfile @@ -10,12 +10,12 @@ RUN groupadd --gid 1000 node && useradd --uid 1000 --gid node --shell /bin/bash curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \ apt-get -y install nodejs && \ npm -v && \ - test -f ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-strip && \ + test -f ${CROSS_ROOT}/bin/llvm-strip && \ rm -rf /var/lib/apt/lists/* USER node -ENV PREBUILD_STRIP_BIN ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-strip +ENV PREBUILD_STRIP_BIN ${CROSS_ROOT}/bin/llvm-strip ENV PREBUILD_ARCH arm64 ENV PREBUILD_ARMV 8 ENV PREBUILD_PLATFORM android diff --git a/android-armv7/Dockerfile b/android-armv7/Dockerfile index 9acdc07..10ed46f 100644 --- a/android-armv7/Dockerfile +++ b/android-armv7/Dockerfile @@ -10,12 +10,12 @@ RUN groupadd --gid 1000 node && useradd --uid 1000 --gid node --shell /bin/bash curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \ apt-get -y install nodejs && \ npm -v && \ - test -f ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-strip && \ + test -f ${CROSS_ROOT}/bin/llvm-strip && \ rm -rf /var/lib/apt/lists/* USER node -ENV PREBUILD_STRIP_BIN ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-strip +ENV PREBUILD_STRIP_BIN ${CROSS_ROOT}/bin/llvm-strip ENV PREBUILD_ARCH arm ENV PREBUILD_ARMV 7 ENV PREBUILD_PLATFORM android From ff265e9d67a6bf90cd82d70d4cb2aef62cd23452 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sun, 27 Feb 2022 15:59:29 +0100 Subject: [PATCH 3/5] Fix disabling npm update check --- alpine/Dockerfile | 1 + android-arm64/Dockerfile | 1 + android-armv7/Dockerfile | 1 + centos7-devtoolset7/Dockerfile | 1 + linux-arm64/Dockerfile | 1 + linux-armv6/Dockerfile | 1 + linux-armv7/Dockerfile | 1 + 7 files changed, 7 insertions(+) diff --git a/alpine/Dockerfile b/alpine/Dockerfile index c4e34f0..c67923c 100644 --- a/alpine/Dockerfile +++ b/alpine/Dockerfile @@ -10,5 +10,6 @@ USER node # Disable npm update check ENV NO_UPDATE_NOTIFIER true +ENV npm_config_update_notifier false WORKDIR /app diff --git a/android-arm64/Dockerfile b/android-arm64/Dockerfile index dcf10ea..b46c988 100644 --- a/android-arm64/Dockerfile +++ b/android-arm64/Dockerfile @@ -30,6 +30,7 @@ ENV GYP_DEFINES target_arch=arm64 android_target_arch=arm64 host_os=linux OS=and # Disable npm update check ENV NO_UPDATE_NOTIFIER true +ENV npm_config_update_notifier false # Set inherited dockcross labels to empty values. # Labels can't be deleted (https://github.com/moby/moby/issues/3465) diff --git a/android-armv7/Dockerfile b/android-armv7/Dockerfile index 10ed46f..3c0a0c8 100644 --- a/android-armv7/Dockerfile +++ b/android-armv7/Dockerfile @@ -30,6 +30,7 @@ ENV GYP_DEFINES target_arch=arm android_target_arch=arm host_os=linux OS=android # Disable npm update check ENV NO_UPDATE_NOTIFIER true +ENV npm_config_update_notifier false # Set inherited dockcross labels to empty values. # Labels can't be deleted (https://github.com/moby/moby/issues/3465) diff --git a/centos7-devtoolset7/Dockerfile b/centos7-devtoolset7/Dockerfile index 7ce1264..f2cfdb7 100644 --- a/centos7-devtoolset7/Dockerfile +++ b/centos7-devtoolset7/Dockerfile @@ -17,5 +17,6 @@ USER node # Disable npm update check ENV NO_UPDATE_NOTIFIER true +ENV npm_config_update_notifier false WORKDIR /app diff --git a/linux-arm64/Dockerfile b/linux-arm64/Dockerfile index e0f539a..9ecff34 100644 --- a/linux-arm64/Dockerfile +++ b/linux-arm64/Dockerfile @@ -28,6 +28,7 @@ ENV TARGET_PLATFORM ${PREBUILD_PLATFORM} # Disable npm update check ENV NO_UPDATE_NOTIFIER true +ENV npm_config_update_notifier false # Set inherited dockcross labels to empty values. # Labels can't be deleted (https://github.com/moby/moby/issues/3465) diff --git a/linux-armv6/Dockerfile b/linux-armv6/Dockerfile index 82a726f..f92e303 100644 --- a/linux-armv6/Dockerfile +++ b/linux-armv6/Dockerfile @@ -28,6 +28,7 @@ ENV TARGET_PLATFORM ${PREBUILD_PLATFORM} # Disable npm update check ENV NO_UPDATE_NOTIFIER true +ENV npm_config_update_notifier false # Set inherited dockcross labels to empty values. # Labels can't be deleted (https://github.com/moby/moby/issues/3465) diff --git a/linux-armv7/Dockerfile b/linux-armv7/Dockerfile index 0988e47..3d9de4c 100644 --- a/linux-armv7/Dockerfile +++ b/linux-armv7/Dockerfile @@ -28,6 +28,7 @@ ENV TARGET_PLATFORM ${PREBUILD_PLATFORM} # Disable npm update check ENV NO_UPDATE_NOTIFIER true +ENV npm_config_update_notifier false # Set inherited dockcross labels to empty values. # Labels can't be deleted (https://github.com/moby/moby/issues/3465) From 03fb48c4a5d805acef39e9c561da47c1f1582370 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sun, 27 Feb 2022 16:07:50 +0100 Subject: [PATCH 4/5] Fix `HOME` to be `/home/node` in all images --- .github/workflows/test.yml | 3 +++ alpine/Dockerfile | 1 + android-arm64/Dockerfile | 1 + android-armv7/Dockerfile | 1 + centos7-devtoolset7/Dockerfile | 1 + linux-arm64/Dockerfile | 1 + linux-armv6/Dockerfile | 1 + linux-armv7/Dockerfile | 1 + 8 files changed, 10 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d38ac5f..5badf79 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,7 @@ jobs: permissions: contents: read strategy: + fail-fast: false matrix: image: - alpine @@ -31,8 +32,10 @@ jobs: push: false - name: Test run: | + docker run --rm prebuild/${{ matrix.image }}:dev whoami docker run --rm prebuild/${{ matrix.image }}:dev node -v docker run --rm prebuild/${{ matrix.image }}:dev npm -v + docker run --rm prebuild/${{ matrix.image }}:dev npx -v docker run --rm prebuild/${{ matrix.image }}:dev python --version docker run --rm prebuild/${{ matrix.image }}:dev npm ls node-gyp -g docker run --rm prebuild/${{ matrix.image }}:dev env diff --git a/alpine/Dockerfile b/alpine/Dockerfile index c67923c..2f7e96a 100644 --- a/alpine/Dockerfile +++ b/alpine/Dockerfile @@ -7,6 +7,7 @@ RUN addgroup -g 2000 travis && \ python --version USER node +ENV HOME /home/node # Disable npm update check ENV NO_UPDATE_NOTIFIER true diff --git a/android-arm64/Dockerfile b/android-arm64/Dockerfile index b46c988..9dab02a 100644 --- a/android-arm64/Dockerfile +++ b/android-arm64/Dockerfile @@ -14,6 +14,7 @@ RUN groupadd --gid 1000 node && useradd --uid 1000 --gid node --shell /bin/bash rm -rf /var/lib/apt/lists/* USER node +ENV HOME /home/node ENV PREBUILD_STRIP_BIN ${CROSS_ROOT}/bin/llvm-strip ENV PREBUILD_ARCH arm64 diff --git a/android-armv7/Dockerfile b/android-armv7/Dockerfile index 3c0a0c8..60e3861 100644 --- a/android-armv7/Dockerfile +++ b/android-armv7/Dockerfile @@ -14,6 +14,7 @@ RUN groupadd --gid 1000 node && useradd --uid 1000 --gid node --shell /bin/bash rm -rf /var/lib/apt/lists/* USER node +ENV HOME /home/node ENV PREBUILD_STRIP_BIN ${CROSS_ROOT}/bin/llvm-strip ENV PREBUILD_ARCH arm diff --git a/centos7-devtoolset7/Dockerfile b/centos7-devtoolset7/Dockerfile index f2cfdb7..d9b65c1 100644 --- a/centos7-devtoolset7/Dockerfile +++ b/centos7-devtoolset7/Dockerfile @@ -14,6 +14,7 @@ RUN groupadd -g 1000 node && useradd -g 1000 -u 1000 -m node && \ python --version USER node +ENV HOME /home/node # Disable npm update check ENV NO_UPDATE_NOTIFIER true diff --git a/linux-arm64/Dockerfile b/linux-arm64/Dockerfile index 9ecff34..3e8e0d9 100644 --- a/linux-arm64/Dockerfile +++ b/linux-arm64/Dockerfile @@ -14,6 +14,7 @@ RUN groupadd --gid 1000 node && useradd --uid 1000 --gid node --shell /bin/bash rm -rf /var/lib/apt/lists/* USER node +ENV HOME /home/node ENV PREBUILD_STRIP_BIN ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-strip ENV PREBUILD_ARCH arm64 diff --git a/linux-armv6/Dockerfile b/linux-armv6/Dockerfile index f92e303..69fe736 100644 --- a/linux-armv6/Dockerfile +++ b/linux-armv6/Dockerfile @@ -14,6 +14,7 @@ RUN groupadd --gid 1000 node && useradd --uid 1000 --gid node --shell /bin/bash rm -rf /var/lib/apt/lists/* USER node +ENV HOME /home/node ENV PREBUILD_STRIP_BIN ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-strip ENV PREBUILD_ARCH arm diff --git a/linux-armv7/Dockerfile b/linux-armv7/Dockerfile index 3d9de4c..0467cd8 100644 --- a/linux-armv7/Dockerfile +++ b/linux-armv7/Dockerfile @@ -14,6 +14,7 @@ RUN groupadd --gid 1000 node && useradd --uid 1000 --gid node --shell /bin/bash rm -rf /var/lib/apt/lists/* USER node +ENV HOME /home/node ENV PREBUILD_STRIP_BIN ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-strip ENV PREBUILD_ARCH arm From 70ba94101106baded01ccc303dde30a0af78d10a Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sun, 27 Feb 2022 17:09:08 +0100 Subject: [PATCH 5/5] Test `node-gyp` (WIP, disabled for now) --- .github/workflows/test.yml | 10 +++++++--- test/native-addon/.gitignore | 1 + test/native-addon/.npmrc | 1 + test/native-addon/binding.cc | 8 ++++++++ test/native-addon/binding.gyp | 6 ++++++ test/native-addon/package.json | 10 ++++++++++ 6 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 test/native-addon/.gitignore create mode 100644 test/native-addon/.npmrc create mode 100644 test/native-addon/binding.cc create mode 100644 test/native-addon/binding.gyp create mode 100644 test/native-addon/package.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5badf79..2d804b5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,12 +30,16 @@ jobs: tags: | prebuild/${{ matrix.image }}:dev push: false - - name: Test + - name: Print versions run: | - docker run --rm prebuild/${{ matrix.image }}:dev whoami docker run --rm prebuild/${{ matrix.image }}:dev node -v docker run --rm prebuild/${{ matrix.image }}:dev npm -v docker run --rm prebuild/${{ matrix.image }}:dev npx -v docker run --rm prebuild/${{ matrix.image }}:dev python --version docker run --rm prebuild/${{ matrix.image }}:dev npm ls node-gyp -g - docker run --rm prebuild/${{ matrix.image }}:dev env + - name: Print env + run: docker run --rm prebuild/${{ matrix.image }}:dev env + + # TODO: fix WORKDIR and permissions (#10) + # - name: Test node-gyp + # run: docker run --rm -v $(pwd)/test/native-addon:/home/node/app:z -w /home/node/app prebuild/${{ matrix.image }}:dev npm run install diff --git a/test/native-addon/.gitignore b/test/native-addon/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/test/native-addon/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/test/native-addon/.npmrc b/test/native-addon/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/test/native-addon/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/test/native-addon/binding.cc b/test/native-addon/binding.cc new file mode 100644 index 0000000..e255bdf --- /dev/null +++ b/test/native-addon/binding.cc @@ -0,0 +1,8 @@ +#define NAPI_VERSION 3 +#include + +napi_value init(napi_env env, napi_value exports) { + return exports; +} + +NAPI_MODULE(NODE_GYP_MODULE_NAME, init) diff --git a/test/native-addon/binding.gyp b/test/native-addon/binding.gyp new file mode 100644 index 0000000..69c1edd --- /dev/null +++ b/test/native-addon/binding.gyp @@ -0,0 +1,6 @@ +{ + "targets": [{ + "target_name": "native_addon", + "sources": ["binding.cc"] + }] +} diff --git a/test/native-addon/package.json b/test/native-addon/package.json new file mode 100644 index 0000000..1af1a4d --- /dev/null +++ b/test/native-addon/package.json @@ -0,0 +1,10 @@ +{ + "name": "native-addon", + "version": "0.0.0", + "description": "Test package", + "private": true, + "license": "MIT", + "scripts": { + "install": "node-gyp rebuild" + } +}