Skip to content

Commit 2497410

Browse files
authored
fix: remove build assets and add node-pre-gyp support (#41)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Chores** - Updated the cleanup process to remove all redundant output directories. - Introduced a new automation step to prepare the project build. - Added an enhanced packaging script to streamline the installation and testing process. - Added a new job for pre-building binaries in the GitHub Actions workflow. - Updated dependencies to include `@mapbox/node-pre-gyp` with its specified version. - Simplified the Dockerfile by adjusting the file copying process for improved build efficiency. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 484b524 commit 2497410

4 files changed

Lines changed: 250 additions & 56 deletions

File tree

.github/workflows/main.yml

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
id: release
2222
with:
2323
release-type: node
24+
2425
build:
2526
runs-on: ubuntu-latest
2627
needs: [release-please]
@@ -72,12 +73,6 @@ jobs:
7273
- name: Build
7374
run: pnpm run build
7475

75-
- name: Set up Docker Buildx
76-
uses: docker/setup-buildx-action@v3
77-
with:
78-
install: true
79-
80-
8176
- name: Setup NPM Authentication
8277
if: ${{ needs.release-please.outputs.release_created }}
8378
run: |
@@ -88,3 +83,77 @@ jobs:
8883
run: pnpm publish
8984
env:
9085
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
86+
87+
prebuild:
88+
name: Build and (Possibly) Publish Pre-built Binaries
89+
needs: [release-please]
90+
runs-on: ubuntu-latest
91+
strategy:
92+
matrix:
93+
node-version: [22]
94+
arch: [amd64, arm64]
95+
os: [ubuntu-latest, macos-latest]
96+
fail-fast: false
97+
98+
steps:
99+
- name: Checkout code
100+
uses: actions/checkout@v4
101+
with:
102+
ref: ${{ needs.release-please.outputs.tag_name }}
103+
104+
- uses: actions/setup-python@v5
105+
with:
106+
python-version: "3.13"
107+
108+
- name: Set Node.js
109+
uses: actions/setup-node@v4
110+
with:
111+
node-version: ${{ matrix.node-version }}
112+
113+
- name: Install pnpm
114+
uses: pnpm/action-setup@v4
115+
with:
116+
run_install: false
117+
118+
- name: Get pnpm store directory
119+
id: pnpm-cache
120+
shell: bash
121+
run: |
122+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
123+
124+
125+
- name: Install build dependencies
126+
run: |
127+
if [ "${{ runner.os }}" == "Linux" ]; then
128+
sudo apt-get update
129+
sudo apt-get install -y libvirt-dev
130+
elif [ "${{ runner.os }}" == "macOS" ]; then
131+
brew install libvirt
132+
fi
133+
134+
- name: Install dependencies
135+
run: pnpm install --frozen-lockfile
136+
137+
- name: Build native module
138+
run: pnpm build/native
139+
140+
- name: Package binary
141+
run: |
142+
mkdir -p deploy
143+
cd ${{ github.workspace }}/build/Release
144+
tar -czf ${{ github.workspace }}/deploy/libvirt-v${{ needs.release-please.outputs.tag_name }}-node-${{ matrix.node-version }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz .
145+
146+
- name: Validate tarball
147+
run: |
148+
tar -tf ${{ github.workspace }}/deploy/libvirt-v${{ needs.release-please.outputs.tag_name }}-node-${{ matrix.node-version }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
149+
150+
- name: Upload Release Assets
151+
if: ${{ needs.release-please.outputs.release_created }}
152+
env:
153+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
154+
run: |
155+
# Use the tag name directly from release-please output
156+
for file in deploy/*; do
157+
echo "Uploading $file to release..."
158+
gh release upload "${{ needs.release-please.outputs.tag_name }}" "$file" --clobber
159+
done

Dockerfile

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,4 @@
1-
# Build stage
2-
FROM node:22-slim AS builder
3-
4-
# Prevent interactive prompts during package installation
5-
ENV DEBIAN_FRONTEND=noninteractive
6-
7-
# Install build dependencies
8-
RUN apt-get update && apt-get install -y \
9-
build-essential \
10-
python3 \
11-
libvirt-dev \
12-
&& rm -rf /var/lib/apt/lists/*
13-
14-
# Set up the build environment
15-
WORKDIR /app
16-
17-
# Copy package files first to leverage caching
18-
COPY package*.json ./
19-
COPY pnpm-lock.yaml ./
20-
21-
# Install pnpm and dependencies
22-
RUN npm install -g pnpm && \
23-
pnpm install --frozen-lockfile
24-
25-
# Copy source files
26-
COPY . .
27-
28-
# Build the project
29-
RUN pnpm run build
30-
31-
# Test stage
32-
FROM node:22-slim AS test
1+
FROM node:22-slim
332

343
# Prevent interactive prompts during package installation
354
ENV DEBIAN_FRONTEND=noninteractive
@@ -58,18 +27,12 @@ RUN useradd -m -s /bin/bash -g libvirt libvirt && \
5827
# Set up the test environment
5928
WORKDIR /app
6029

61-
# Copy package files and install all dependencies (including dev)
62-
COPY package*.json ./
63-
COPY pnpm-lock.yaml ./
64-
RUN npm install -g pnpm && \
65-
pnpm install --frozen-lockfile
30+
# Copy package files and binding.gyp first
31+
COPY . .
6632

67-
# Copy built files and test files from builder stage
68-
COPY --from=builder /app/dist ./dist
69-
COPY --from=builder /app/lib ./lib
70-
COPY --from=builder /app/__tests__ ./__tests__
71-
COPY --from=builder /app/vitest.config.ts ./vitest.config.ts
72-
COPY --from=builder /app/build ./build
33+
# Install pnpm and dependencies
34+
RUN corepack enable pnpm && \
35+
pnpm install --frozen-lockfile
7336

7437
# Set up libvirt configuration
7538
RUN mkdir -p /etc/libvirt && \

package.json

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@
99
"access": "public"
1010
},
1111
"gypfile": true,
12+
"binary": {
13+
"module_name": "libvirt",
14+
"module_path": "build/Release",
15+
"host": "https://github.com/unraid/libvirt/releases/download/",
16+
"remote_path": "{version}",
17+
"package_name": "{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz",
18+
"target": ">=14.0.0",
19+
"target_platform": [
20+
"linux",
21+
"darwin"
22+
],
23+
"target_arch": [
24+
"x64",
25+
"arm64"
26+
],
27+
"runtime": "node"
28+
},
1229
"exports": {
1330
".": {
1431
"import": "./dist/index.js",
@@ -17,22 +34,25 @@
1734
},
1835
"files": [
1936
"dist",
20-
"build"
37+
"binding.gyp",
38+
"src"
2139
],
2240
"scripts": {
23-
"prebuild": "pnpm clean",
24-
"clean": "rimraf dist",
41+
"clean": "rimraf dist build",
2542
"build": "pnpm build/validate && pnpm build/native && pnpm build/ts",
2643
"build/validate": "node scripts/validate-platform.js",
2744
"build/native": "node-gyp rebuild",
2845
"build/ts": "tsc --build --verbose",
46+
"prepare": "pnpm build",
2947
"test": "vitest run",
3048
"test:coverage": "vitest run --coverage",
3149
"test:ui": "vitest --ui",
50+
"test:package": "rimraf /tmp/libvirt && mkdir /tmp/libvirt && cp -r dist package.json README.md LICENSE binding.gyp src /tmp/libvirt/ && cd /tmp/libvirt && pnpm install",
3251
"examples/list": "node examples/list.js",
3352
"examples/start": "node examples/start.js",
3453
"examples/shutdown": "node examples/shutdown.js",
35-
"examples/builder": "node examples/builder.js"
54+
"examples/builder": "node examples/builder.js",
55+
"install": "node-pre-gyp install --fallback-to-build"
3656
},
3757
"repository": {
3858
"type": "git",
@@ -63,7 +83,8 @@
6383
"bindings": "^1.5.0",
6484
"node-addon-api": "^8.3.0",
6585
"tsx": "^4.19.2",
66-
"xml2js": "^0.6.2"
86+
"xml2js": "^0.6.2",
87+
"@mapbox/node-pre-gyp": "^2.0.0"
6788
},
6889
"devDependencies": {
6990
"@types/bindings": "^1.5.5",

0 commit comments

Comments
 (0)