From b040c8ecee322a6308bd6b689e4a9b1f97dc7f04 Mon Sep 17 00:00:00 2001 From: Nicolas MARTEAU Date: Fri, 26 Jul 2024 15:21:16 +0200 Subject: [PATCH] chore: add dockerfile fro windows x64 & x86, improve .yml --- .github/Dockerfile | 11 ++++++++ .github/workflows/build.yml | 50 +++++++++++++++++----------------- package.json | 5 +++- platform/Dockerfile | 10 ------- platform/win32-ia32/Dockerfile | 17 ++++++++++++ platform/win32-x64/Dockerfile | 17 ++++++++++++ src/binding.gyp | 47 ++++++++++++++++++++++++-------- 7 files changed, 110 insertions(+), 47 deletions(-) create mode 100644 .github/Dockerfile delete mode 100644 platform/Dockerfile create mode 100644 platform/win32-ia32/Dockerfile create mode 100644 platform/win32-x64/Dockerfile diff --git a/.github/Dockerfile b/.github/Dockerfile new file mode 100644 index 0000000..baa311b --- /dev/null +++ b/.github/Dockerfile @@ -0,0 +1,11 @@ +ARG PLATFORM +ARG ARCH +FROM myunisoft91/heif-converter.$PLATFORM:v0.0.1 +LABEL maintainer="Nicolas Marteau " + +WORKDIR heif-converter +COPY . . +RUN npm install +RUN npm run configure -- --arch=${ARCH:-x64} +RUN npm run build -- --arch=${ARCH:-x64} +RUN npm run test \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fa314a2..fc79f06 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,13 +15,19 @@ jobs: matrix: include: - os: ubuntu-22.04 - platform: linuxmusl-x64 + platform: linuxmusl + arch: x64 - os: ubuntu-22.04 - platform: linux-x64 - - os: macos-11 - platform: darwin-x64 + platform: linux + arch: x64 + # - os: macos-11 + # platform: darwin-x64 - os: windows-2020 - platform: windows-x64 + platform: win32 + arch: x64 + - os: windows-2020 + platform: win32 + arch: ia32 steps: - name: Checkout repository @@ -38,34 +44,28 @@ jobs: - name: Create a folder for the tarball run: mkdir release - - name: Build with Docker (${{ matrix.platform }}) - if: contains(matrix.os, 'ubuntu') + - name: Build with Docker (Windows) + if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'windows') + env: + PLATFORM: ${{ matrix.platform }}-${{ matrix.arch }} run: | - docker build --build-arg PLATFORM=${{ matrix.platform }} --build-arg LIBHEIF_V=v1.17.6 -t ${{ matrix.platform }} . -f ./platform/Dockerfile - docker run --name ${{ matrix.platform }} ${{ matrix.platform }} - docker cp ${{ matrix.platform }}:/heif-converter/src/build/Release/converter.node ./release/converter.${{ matrix.platform }}.node - docker container rm ${{ matrix.platform }} + # Build image + docker build --build-arg PLATFORM=${{ env.PLATFORM }} --build-arg ARCH=${{ matrix.arch }} -t ${{ env.PLATFORM }} . -f ./.github/Dockerfile + + # Run container and copy the built file + docker run --name ${{ env.PLATFORM }} ${{ env.PLATFORM }} + docker cp ${{ env.PLATFORM }}:C:/heif-converter/src/build/Release/converter.node ./release/converter.${{ env.PLATFORM }}.node - # - name: Build natively (Windows) - # if: runner.os == 'Windows' - # run: | - # git clone https://github.com/microsoft/vcpkg.git - # .\vcpkg\bootstrap-vcpkg.bat - # .\vcpkg\vcpkg.exe install libheif - # echo "::add-path::$(pwd)\vcpkg\installed\x64-windows\bin" - # echo "::add-path::$(pwd)\vcpkg\installed\x64-windows\lib" - # npm install -g node-gyp - # node-gyp configure -C src - # node-gyp build -C src - # cp ./src/build/Release/converter.node ./src/build/Release/converter-windows-x64.node + # Clean up the Docker container + docker container rm ${{ env.PLATFORM }} - name: Create tarball of the release folder run: | cd ./release - tar -czf ${{ matrix.platform }}.tar.gz * + tar -czf ${{ matrix.platform }}-${{ matrix.arch }}.tar.gz * - name: Upload artifact uses: actions/upload-artifact@v2 with: name: release - path: ./release/${{ matrix.platform }}.tar.gz + path: ./release/${{ matrix.platform }}-${{ matrix.arch }}.tar.gz diff --git a/package.json b/package.json index 3c6fa55..2d0ff91 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,9 @@ "main": "index.js", "scripts": { "test": "node --test test/test.spec.js", - "build": "node-gyp configure --directory=src && node-gyp build --directory=src" + "clear": "rimraf src/build src/node_modules", + "configure": "node-gyp configure --directory=src", + "build": "node-gyp build --directory=src" }, "publishConfig": { "@myunisoft:registry": "https://registry.npmjs.org/" @@ -45,6 +47,7 @@ "heic-convert": "^2.1.0", "node-addon-api": "^8.0.0", "node-gyp": "^10.1.0", + "rimraf": "^6.0.1", "tinybench": "^2.8.0" }, "optionalDependencies": { diff --git a/platform/Dockerfile b/platform/Dockerfile deleted file mode 100644 index c94b0cf..0000000 --- a/platform/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -ARG PLATFORM -ARG LIBHEIF_V -FROM myunisoft91/heif-converter.$PLATFORM:$LIBHEIF_V -LABEL maintainer="Nicolas Marteau " - -WORKDIR heif-converter -COPY . . -RUN npm install && \ - npm run build && \ - npm run test \ No newline at end of file diff --git a/platform/win32-ia32/Dockerfile b/platform/win32-ia32/Dockerfile new file mode 100644 index 0000000..9455978 --- /dev/null +++ b/platform/win32-ia32/Dockerfile @@ -0,0 +1,17 @@ +FROM mcr.microsoft.com/windows/servercore:ltsc2022 +LABEL maintainer="Nicolas Marteau " + +RUN powershell -NoProfile -ExecutionPolicy Bypass -Command \ + "Set-ExecutionPolicy Bypass -Scope Process; \ + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; \ + iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" + +RUN choco install -y nodejs --version=18.12.0 --x86 +RUN choco install -y git visualstudio2019buildtools visualstudio2019-workload-vctools +RUN choco install -y python3 + +RUN git clone https://github.com/microsoft/vcpkg.git +RUN .\vcpkg\bootstrap-vcpkg.bat +RUN .\vcpkg\vcpkg install libheif:x86-windows libpng:x86-windows libjpeg-turbo:x86-windows + +CMD ["powershell"] diff --git a/platform/win32-x64/Dockerfile b/platform/win32-x64/Dockerfile new file mode 100644 index 0000000..9f4a766 --- /dev/null +++ b/platform/win32-x64/Dockerfile @@ -0,0 +1,17 @@ +FROM mcr.microsoft.com/windows/servercore:ltsc2022 +LABEL maintainer="Nicolas Marteau " + +RUN powershell -NoProfile -ExecutionPolicy Bypass -Command \ + "Set-ExecutionPolicy Bypass -Scope Process; \ + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; \ + iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" + +RUN choco install -y nodejs --version=18.12.0 +RUN choco install -y git visualstudio2019buildtools visualstudio2019-workload-vctools +RUN choco install -y python3 + +RUN git clone https://github.com/microsoft/vcpkg.git +RUN .\vcpkg\bootstrap-vcpkg.bat +RUN .\vcpkg\vcpkg install libheif libpng libjpeg-turbo + +CMD ["powershell"] diff --git a/src/binding.gyp b/src/binding.gyp index c1af34b..41d8aa2 100644 --- a/src/binding.gyp +++ b/src/binding.gyp @@ -16,12 +16,12 @@ "defines": [ "NAPI_CPP_EXCEPTIONS" ], "conditions": [ [ - "OS==\"linux\"", { + 'OS=="linux"', { "variables": { "VCPKG_LIB_ROOT%": "