Skip to content

Commit

Permalink
Add Linux AMD64-specific package (#28)
Browse files Browse the repository at this point in the history
* Add Linux AMD64-specific package

Signed-off-by: Satwik Sai Prakash Sahoo <[email protected]>

* feat(build): Optimize build script for Linux AMD64

- Added dynamic handling for Trivy and Osquery plugins with validation for existing binaries.
- Integrated Dosai binary download and checksum generation.
- Improved error handling and added compression for binaries using UPX.
- Included warnings for missing source files in plugin directories.

Signed-off-by: Satwik Sai Prakash Sahoo <[email protected]>

---------

Signed-off-by: Satwik Sai Prakash Sahoo <[email protected]>
  • Loading branch information
satwiksps authored Jan 16, 2025
1 parent fa32c53 commit 85b628f
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 7 deletions.
49 changes: 47 additions & 2 deletions .github/workflows/native-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: true
matrix:
os: ['ubuntu-latest', 'macos-13', 'macos-15']
os: ['ubuntu-latest', 'macos-13', 'macos-15', 'windows-latest']
runs-on: ${{ matrix.os }}
permissions:
contents: write
Expand All @@ -28,7 +28,17 @@ jobs:
- run: oras version
- name: Build
run: |
bash thirdparty/sourcekitten/build.sh
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
bash thirdparty/sourcekitten/build.sh
bash packages/linux-arm64/build-linux-arm64.sh
bash packages/linux-arm/build-linux-arm.sh
bash packages/ppc64/build-ppc64.sh
elif [ "${{ matrix.os }}" == "windows-latest" ]; then
powershell ./packages/windows-amd64/build-windows-amd64.ps1
powershell ./packages/windows-arm64/build-windows-arm64.ps1
else
bash thirdparty/sourcekitten/build.sh
fi
ls -l thirdparty/sourcekitten/SourceKitten/.build/release
echo $GITHUB_TOKEN | oras login ghcr.io -u $GITHUB_USERNAME --password-stdin
env:
Expand All @@ -42,6 +52,20 @@ jobs:
./sourcekitten:application/vnd.cyclonedx.plugins.layer.v1+tar \
./sourcekitten.sha256:application/vnd.cyclonedx.plugins.layer.v1+tar
if: matrix.os == 'ubuntu-latest'
- name: Upload linux arm64
run: |
cd packages/linux-arm64/release/
oras push ghcr.io/cyclonedx/cdxgen-plugins-bin:linux-arm64 \
--artifact-type application/vnd.oras.config.v1+json \
./arm64-binary:application/vnd.cyclonedx.plugins.layer.v1+tar
if: matrix.os == 'ubuntu-latest'
- name: Upload linux arm
run: |
cd packages/linux-arm/release/
oras push ghcr.io/cyclonedx/cdxgen-plugins-bin:linux-arm \
--artifact-type application/vnd.oras.config.v1+json \
./arm-binary:application/vnd.cyclonedx.plugins.layer.v1+tar
if: matrix.os == 'ubuntu-latest'
- name: Upload darwin amd64
run: |
cd thirdparty/sourcekitten/SourceKitten/.build/release/
Expand All @@ -58,3 +82,24 @@ jobs:
./sourcekitten:application/vnd.cyclonedx.plugins.layer.v1+tar \
./sourcekitten.sha256:application/vnd.cyclonedx.plugins.layer.v1+tar
if: matrix.os == 'macos-15'
- name: Upload windows amd64
run: |
cd packages/windows-amd64/release/
oras push ghcr.io/cyclonedx/cdxgen-plugins-bin:windows-amd64 \
--artifact-type application/vnd.oras.config.v1+json \
./windows-binary:application/vnd.cyclonedx.plugins.layer.v1+tar
if: matrix.os == 'windows-latest'
- name: Upload windows arm64
run: |
cd packages/windows-arm64/release/
oras push ghcr.io/cyclonedx/cdxgen-plugins-bin:windows-arm64 \
--artifact-type application/vnd.oras.config.v1+json \
./windows-arm64-binary:application/vnd.cyclonedx.plugins.layer.v1+tar
if: matrix.os == 'windows-latest'
- name: Upload ppc64
run: |
cd packages/ppc64/release/
oras push ghcr.io/cyclonedx/cdxgen-plugins-bin:ppc64 \
--artifact-type application/vnd.oras.config.v1+json \
./ppc64-binary:application/vnd.cyclonedx.plugins.layer.v1+tar
if: matrix.os == 'ubuntu-latest'
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ jobs:
contents: read
packages: write
steps:
- name: Upload Linux AMD64 Package
uses: actions/upload-artifact@v3
with:
name: linux-amd64-package
path: packages/linux-amd64/*.tgz

- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
Expand Down
13 changes: 8 additions & 5 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
New-Item -ItemType Directory -Path plugins\osquery -Force
New-Item -ItemType Directory -Path plugins\dosai -Force
New-Item -ItemType Directory -Path plugins\trivy -Force

Invoke-WebRequest -Uri https://github.com/upx/upx/releases/download/v4.2.4/upx-4.2.4-win64.zip -UseBasicParsing -OutFile upx-4.2.4-win64.zip
Expand-Archive -Path upx-4.2.4-win64.zip -DestinationPath . -Force
Expand All @@ -12,18 +13,20 @@ plugins\osquery\osqueryi-windows-amd64.exe --help

Invoke-WebRequest -Uri https://github.com/owasp-dep-scan/dosai/releases/latest/download/Dosai.exe -UseBasicParsing -OutFile plugins/dosai/dosai-windows-amd64.exe

set CGO_ENABLED=0
set GOOS=windows
set GOARCH=amd64

New-Item -ItemType Directory -Path plugins\trivy -Force
cd thirdparty\trivy
go build -ldflags "-H=windowsgui -s -w" -o build\trivy-windows-amd64.exe
..\..\upx-4.2.4-win64\upx.exe -9 --lzma build\trivy-windows-amd64.exe
copy build\* ..\..\plugins\trivy\
Remove-Item build -Recurse -Force
cd ..\..

Write-Host "Building Linux AMD64 package..."
Set-Location -Path packages/linux-amd64
Copy-Item -Path ../../plugins/* -Destination plugins/
npm install
npm pack
Set-Location -Path ../../

Remove-Item osquery-5.14.1.windows_x86_64 -Recurse -Force
Remove-Item osquery-5.14.1.windows_x86_64.zip -Recurse -Force
Remove-Item upx-4.2.4-win64 -Recurse -Force
Expand Down
7 changes: 7 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ upx -9 --lzma ./plugins/trivy/trivy-cdxgen-linux-amd64
./plugins/trivy/trivy-cdxgen-linux-amd64 -v
./plugins/dosai/dosai-linux-amd64 --help

echo "Building Linux AMD64 package..."
cd packages/linux-amd64
cp ../../plugins/* plugins/
npm install
npm pack
cd ../../

for flavours in windows-amd64 linux-arm64 linux-arm windows-arm64 darwin-arm64 darwin-amd64 ppc64
do
chmod +x packages/$flavours/build-$flavours.sh
Expand Down
28 changes: 28 additions & 0 deletions packages/linux-amd64/build-linux-amd64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -e # Exit on error

echo "Building Linux AMD64 package..."

# Remove old plugin directories to ensure a clean build
rm -rf plugins/trivy plugins/osquery plugins/dosai
mkdir -p plugins/trivy plugins/osquery plugins/dosai

# Download the Dosai binary
curl -L https://github.com/owasp-dep-scan/dosai/releases/latest/download/Dosai-linux-amd64 -o plugins/dosai/dosai-linux-amd64
chmod +x plugins/dosai/dosai-linux-amd64
sha256sum plugins/dosai/dosai-linux-amd64 > plugins/dosai/dosai-linux-amd64.sha256

# Handle additional plugins: Trivy and Osquery
for plug in trivy osquery; do
mkdir -p plugins/$plug
# Check if the source plugin directory exists and is not empty
if [ -d "../../plugins/$plug" ] && [ "$(ls -A ../../plugins/$plug/*linux-amd64* 2>/dev/null)" ]; then
cp ../../plugins/$plug/*linux-amd64* plugins/$plug/
upx -9 --lzma plugins/$plug/*linux-amd64* || true # Compress files if possible
else
echo "Warning: No files found for $plug in ../../plugins/$plug/"
fi
done

# Final output message
echo "Linux AMD64 build completed successfully!"
1 change: 1 addition & 0 deletions packages/linux-amd64/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Linux AMD64 package initialized.');
17 changes: 17 additions & 0 deletions packages/linux-amd64/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@cyclonedx/cdxgen-plugins-bin-linux-amd64",
"version": "1.0.0",
"description": "CycloneDX plugins binary for Linux AMD64",
"main": "index.js",
"scripts": {
"build": "./build-linux-amd64.sh"
},
"keywords": [
"CycloneDX",
"plugins",
"linux",
"amd64"
],
"license": "MIT"
}

6 changes: 6 additions & 0 deletions packages/linux-amd64/plugins/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
goversion/
trivy/
cargo-auditable/
osquery/
dosai/
sourcekitten/
Empty file.
Empty file.

0 comments on commit 85b628f

Please sign in to comment.