Skip to content

Commit ccd0e66

Browse files
committed
Update cd-download-grype-scan.yml
more fun with GPT - echo DOWNLOAD_URL to env variable (overwritten by in-script version of same name), and echo license_id to environment; fix issues with download on ubuntu not a .tar.gz but .deb (same for Windows --> MSI) - this may be product specific!
1 parent 318b400 commit ccd0e66

1 file changed

Lines changed: 61 additions & 13 deletions

File tree

.github/workflows/cd-download-grype-scan.yml

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# CD pipeline to download packages from Commercial and/or Community downloads API and run Grype security scan
22

33
# test inputs:
4-
# product: chef
5-
# product-version: 19.0.6
4+
# product: chef (or chef-workstation)
5+
# product-version: 18.8.54 (for chef), 25.12.1102 (for chef-workstation)
66
# channel: stable
77
# architecture: x86_64
88
# os-platform: both (ubuntu and windows)
9-
# os-platform-version: not specified
9+
# os-platform-version: 24.04 (TODO: make this selectable by Windows and linux separately later)
1010
# download-site: commercial
1111
# license-id: (not specified, uses secret)
1212

@@ -262,17 +262,39 @@ jobs:
262262
echo "Using license ID in download URL"
263263
fi
264264
fi
265+
echo "Full DOWNLOAD_URL: ${DOWNLOAD_URL}"
266+
echo "DOWNLOAD_URL=${DOWNLOAD_URL}" >> $GITHUB_ENV
265267
266-
# download the specified product from https://chefdownload-community.chef.io/stable/<PRODUCT>/download?p=<PLATFORM>&pv=<PLATFORM_VERSION>&m=<ARCHITECTURE>&v=<PRODUCT_VERSION>
267-
# OR https://chefdownload-commercial.chef.io/stable/chef/download?p=windows&pv=11&m=x86_64&v=25.12.1102&license_id=LICENSE_ID
268-
269268
# Download the package
270269
curl -L -o /tmp/package_downloaded "${DOWNLOAD_URL}"
271270
272-
# Extract the package based on its type (assuming .tar.gz for this example)
273-
mkdir -p /tmp/extracted_packages
274-
tar -xzf /tmp/package_downloaded -C /tmp/extracted_packages
275-
echo "Package downloaded and extracted to /tmp/extracted_packages"
271+
# Handle package extraction based on platform
272+
if [ "${{ inputs.os-platform }}" = "ubuntu" ]; then
273+
# Ubuntu downloads are .deb packages - install them
274+
echo "Installing .deb package..."
275+
sudo dpkg -i /tmp/package_downloaded
276+
277+
# Echo where it was installed
278+
echo "Package installed. Listing installed files:"
279+
dpkg -L ${{ inputs.product }} || dpkg -L $(dpkg -I /tmp/package_downloaded | grep Package: | awk '{print $2}')
280+
281+
# Set extraction path for grype scan
282+
mkdir -p /tmp/extracted_packages
283+
# Copy installed files to extraction directory for scanning
284+
echo "Copying installed files for scanning..."
285+
if [ "${{ inputs.product }}" = "chef" ]; then
286+
sudo cp -r /opt/chef /tmp/extracted_packages/ 2>/dev/null || true
287+
elif [ "${{ inputs.product }}" = "chef-workstation" ]; then
288+
sudo cp -r /opt/chef-workstation /tmp/extracted_packages/ 2>/dev/null || true
289+
else
290+
sudo cp -r /opt/${{ inputs.product }} /tmp/extracted_packages/ 2>/dev/null || true
291+
fi
292+
else
293+
# Extract the package based on its type (assuming .tar.gz for non-Ubuntu)
294+
mkdir -p /tmp/extracted_packages
295+
tar -xzf /tmp/package_downloaded -C /tmp/extracted_packages
296+
echo "Package downloaded and extracted to /tmp/extracted_packages"
297+
fi
276298
277299
ls -l /tmp/extracted_packages
278300
@@ -365,11 +387,37 @@ jobs:
365387
# Download the package
366388
Invoke-WebRequest -Uri $DownloadUrl -OutFile "$env:TEMP\package_downloaded" -FollowRelLink
367389

368-
# Extract the package based on its type (assuming .zip for Windows)
390+
# Handle package extraction/installation based on platform
369391
$ExtractPath = "$env:TEMP\extracted_packages"
370392
New-Item -ItemType Directory -Force -Path $ExtractPath
371-
Expand-Archive -Path "$env:TEMP\package_downloaded" -DestinationPath $ExtractPath -Force
372-
Write-Host "Package downloaded and extracted to $ExtractPath"
393+
394+
if ("${{ inputs.os-platform }}" -eq "windows") {
395+
# Windows downloads are .msi packages - install them
396+
Write-Host "Installing .msi package..."
397+
Start-Process msiexec.exe -ArgumentList "/i", "$env:TEMP\package_downloaded", "/qn", "/norestart" -Wait
398+
399+
# Echo where it was installed
400+
Write-Host "Package installed. Common installation paths:"
401+
if (Test-Path "C:\opscode\chef") {
402+
Write-Host "Found installation at: C:\opscode\chef"
403+
Get-ChildItem -Path "C:\opscode\chef" -Recurse -Depth 1
404+
Copy-Item -Path "C:\opscode\chef" -Destination $ExtractPath -Recurse -Force
405+
}
406+
if (Test-Path "C:\opscode\chef-workstation") {
407+
Write-Host "Found installation at: C:\opscode\chef-workstation"
408+
Get-ChildItem -Path "C:\opscode\chef-workstation" -Recurse -Depth 1
409+
Copy-Item -Path "C:\opscode\chef-workstation" -Destination $ExtractPath -Recurse -Force
410+
}
411+
if (Test-Path "C:\opscode\${{ inputs.product }}") {
412+
Write-Host "Found installation at: C:\opscode\${{ inputs.product }}"
413+
Get-ChildItem -Path "C:\opscode\${{ inputs.product }}" -Recurse -Depth 1
414+
Copy-Item -Path "C:\opscode\${{ inputs.product }}" -Destination $ExtractPath -Recurse -Force
415+
}
416+
} else {
417+
# Extract the package based on its type (assuming .zip for non-Windows platforms)
418+
Expand-Archive -Path "$env:TEMP\package_downloaded" -DestinationPath $ExtractPath -Force
419+
Write-Host "Package downloaded and extracted to $ExtractPath"
420+
}
373421

374422
Get-ChildItem -Path $ExtractPath
375423

0 commit comments

Comments
 (0)