Skip to content

Commit

Permalink
chore: add dockerfile fro windows x64 & x86, improve .yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Dafyh committed Jul 26, 2024
1 parent ab55d6d commit b040c8e
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 47 deletions.
11 changes: 11 additions & 0 deletions .github/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ARG PLATFORM
ARG ARCH
FROM myunisoft91/heif-converter.$PLATFORM:v0.0.1
LABEL maintainer="Nicolas Marteau <[email protected]>"

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
50 changes: 25 additions & 25 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -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": {
Expand Down
10 changes: 0 additions & 10 deletions platform/Dockerfile

This file was deleted.

17 changes: 17 additions & 0 deletions platform/win32-ia32/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM mcr.microsoft.com/windows/servercore:ltsc2022
LABEL maintainer="Nicolas Marteau <[email protected]>"

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"]
17 changes: 17 additions & 0 deletions platform/win32-x64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM mcr.microsoft.com/windows/servercore:ltsc2022
LABEL maintainer="Nicolas Marteau <[email protected]>"

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"]
47 changes: 36 additions & 11 deletions src/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"defines": [ "NAPI_CPP_EXCEPTIONS" ],
"conditions": [
[
"OS==\"linux\"", {
'OS=="linux"', {
"variables": {
"VCPKG_LIB_ROOT%": "<!(echo $VCPKG_LIB_ROOT)",
"conditions": [
[
"\"<!(echo $VCPKG_LIB_ROOT)\" == \"\"", {
'"<!(echo $VCPKG_LIB_ROOT)" == ""', {
"VCPKG_LIB_ROOT%": "/vcpkg/installed/x64-linux"
}
]
Expand All @@ -42,17 +42,42 @@
}
],
[
"OS==\"win\"", {
"variables": {
"VCPKG_LIB_ROOT%": "<!(node -e \"console.log(process.env.VCPKG_LIB_ROOT)\")",
"conditions": [
[
"\"<!(node -e \"console.log(process.env.VCPKG_LIB_ROOT)\")\" == \"undefined\"", {
"VCPKG_LIB_ROOT%": "C:/vcpkg/installed/x64-windows"
'OS=="win"',
{
"conditions": [
[
'target_arch=="x64"',
{
"variables": {
"VCPKG_LIB_ROOT%": '<!(node -e "console.log(process.env.VCPKG_LIB_ROOT)")',
"conditions": [
[
'"<!(node -e "console.log(process.env.VCPKG_LIB_ROOT)")" == "undefined"',
{
"VCPKG_LIB_ROOT%": "C:/vcpkg/installed/x64-windows"
}
]
]
}
]
}
],
[
'target_arch=="ia32"',
{
"variables": {
"VCPKG_LIB_ROOT%": '<!(node -e "console.log(process.env.VCPKG_LIB_ROOT)")',
"conditions": [
[
'"<!(node -e "console.log(process.env.VCPKG_LIB_ROOT)")" == "undefined"',
{
"VCPKG_LIB_ROOT%": "C:/vcpkg/installed/x86-windows"
}
]
]
}
}
]
},
],
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": 1
Expand Down

0 comments on commit b040c8e

Please sign in to comment.