Skip to content

Commit

Permalink
Package binaries with node-pre-gyp
Browse files Browse the repository at this point in the history
This should avoid having to build from source for some more resource
constrained platforms.

Change-type: minor
  • Loading branch information
pipex committed Sep 21, 2023
1 parent 8d1dcb9 commit 777b583
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
74 changes: 74 additions & 0 deletions .github/actions/publish/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
name: publish binaries
description: package GitHub release for node-pre-gyp
# https://github.com/product-os/flowzone/tree/master/.github/actions
inputs:
json:
description: 'JSON stringified object containing all the inputs from the calling workflow'
required: true
secrets:
description: 'JSON stringified object containing all the secrets from the calling workflow'
required: true
variables:
description: 'JSON stringified object containing all the variables from the calling workflow'
required: true
# --- custom environment
NODE_VERSION:
description: 'Node.js version'
default: '18.x'

RUST_TOOLCHAIN:
description: 'Rust toolchain'
default: 'stable'

runs:
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
using: 'composite'
steps:
- name: Download custom source artifact
uses: actions/download-artifact@v3
with:
name: custom-${{ github.event.pull_request.head.sha || github.event.head_commit.id }}-${{ runner.os }}-${{ runner.arch }}
path: ${{ runner.temp }}

- name: Extract custom source artifact
shell: pwsh
working-directory: .
run: tar -xf ${{ runner.temp }}/custom.tgz

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.NODE_VERSION }}
cache: npm

# - name: Set up Rust targets
# uses: dtolnay/rust-toolchain@master
# with:
# toolchain: ${{ inputs.RUST_TOOLCHAIN }}
# targets: |
# aarch64-unknown-linux-musl,
# armv7-unknown-linux-musleabihf,
# arm-unknown-linux-musleabihf,
# x86_64-unknown-linux-musl,
# i686-unknown-linux-musl
- name: Set-up Rust armv6 target
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ inputs.RUST_TOOLCHAIN }}
target: arm-unknown-linux-musleabihf
override: true

- name: Install Node modules
shell: bash
run: npm i

- name: Build armv6 target
shell: bash
run: npm run build:rust

- name: Package the asset
shell: bash
# This will make a node-pre-gyp package.
run: npx node-pre-gyp package
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ COPY src ./src

# Install dependencies and build
# bindings
RUN npm install
RUN npm install && npm run build:rust

COPY lib ./lib
COPY typings ./typings
Expand Down
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
"clean": "rimraf build",
"lint": "balena-lint --typescript lib tests",
"lint-fix": "balena-lint --typescript --fix lib tests",
"build": "npm run build:rust && npm run build:node",
"build": "npm run build:rust && npm run build:node && cargo clean",
"build:node": "npm run clean && tsc --project tsconfig.release.json",
"build:rust": "RUSTFLAGS='-C target-feature=-crt-static' npx cargo-cp-artifact -ac balena-systemd index.node -- cargo build --message-format=json-render-diagnostics",
"build:rust:debug": "npm run build:rust --",
"build:rust:release": "npm run build:rust -- --release",
"install": "npm run build:rust:release && cargo clean",
"test": "echo 'No tests yet'",
"test:integration": "mocha -r ts-node/register --bail --reporter spec tests/**/*.spec.ts",
"test:compose": "docker compose -f docker-compose.test.yml up --build --remove-orphans --exit-code-from=sut ; npm run compose:down",
Expand All @@ -53,5 +52,15 @@
},
"versionist": {
"publishedAt": "2023-08-16T19:33:04.629Z"
},
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.11"
},
"binary": {
"module_name": "node-systemd",
"module_path": "./",
"host": "https://github.com/balena-io-modules/node-systemd/releases/download/",
"package_name": "{module_name}-v{version}-{node_abi}-{platform}-{arch}-{libc}.tar.gz",
"remote_path": "v{version}"
}
}

0 comments on commit 777b583

Please sign in to comment.