Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker container for building native images #4073

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) eBPF for Windows contributors
# SPDX-License-Identifier: MIT

# This yaml builds the Docker image for the eBPF for Windows project.

name: Build Docker Image

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
build:
runs-on: windows-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build Docker image
working-directory: ${{github.workspace}}\\scripts\build_native
run: |
docker build -t bpf_build_native:0.20.0 -m 2GB .

- name: Push Docker image
run: |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login ghcr.io -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
docker tag ebpf-for-windows:latest ghcr.io/ebpf-for-windows/ebpf-for-windows:latest
docker push ghcr.io/ebpf-for-windows/ebpf-for-windows:latest
48 changes: 48 additions & 0 deletions scripts/build_native/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# escape=`
# Copyright (c) eBPF for Windows contributors
# SPDX-License-Identifier: MIT

# Use the latest Windows Server Core 2022 image.
FROM mcr.microsoft.com/windows/servercore:ltsc2022

# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]

RUN `
# Download the Build Tools bootstrapper.
curl -SL --output vs_community.exe https://aka.ms/vs/17/release/vs_community.exe `
`
# Install Build Tools with the Microsoft.VisualStudio.Workload.AzureBuildTools workload, excluding workloads and components with known issues.
&& (start /w vs_community.exe --quiet --wait --norestart --nocache `
--installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" `
# Add the Azure build tools workload.
--add Microsoft.VisualStudio.Workload.AzureBuildTools `
# Add the Windows 11 SDK.
--add Microsoft.VisualStudio.Component.Windows11SDK.26100 `
# Add the Visual C++ build tools workload.
--add Microsoft.VisualStudio.Workload.VCTools `
# Add Spectre libraries.
--add Microsoft.VisualStudio.Component.VC.Runtimes.x86.x64.Spectre `
--add Microsoft.VisualStudio.Component.VC.Runtimes.ARM64.Spectre `
--add Component.Microsoft.Windows.DriverKit `
|| IF "%ERRORLEVEL%"=="3010" EXIT 0) `
`
# Cleanup
&& del /q vs_community.exe `
# Install the NuGet CLI.
&& mkdir c:\packages `
&& cd c:\packages `
&& curl -o nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe `
# Install the Windows 10 SDK and WDK.
&& .\nuget.exe install Microsoft.Windows.SDK.CPP -Version 10.0.26100.2161 `
&& .\nuget.exe install Microsoft.Windows.WDK.x64 -Version 10.0.26100.2161 `
&& .\nuget.exe install -ExcludeVersion eBPF-for-Windows.x64

RUN C:\packages\eBPF-for-Windows.x64\build\native\bin\export_program_info.exe

WORKDIR c:\data
COPY build.ps1 c:\build.ps1

# Define the entry point for the docker container.
# This entry point starts the developer command prompt and launches the PowerShell shell.
ENTRYPOINT ["C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass", "\\build.ps1" ]
17 changes: 17 additions & 0 deletions scripts/build_native/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Docker container for building native BPF drivers

This docker image provides a simplified method for building native BPF drivers from ELF files.

## Building the container
docker build -t build_native:latest -m 2GB .

## Usage
docker run -it --rm -v "d:\data:c:\data" build_native \build.ps1 my_program.o

The folder "d:\data" is where the ELF file to be processed is and "my_program.o" is the name of the ELF file.

Once this completes the container produces the following:

1) my_program.cer
2) my_program.pdb
3) my_program.sys
33 changes: 33 additions & 0 deletions scripts/build_native/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) eBPF for Windows contributors
# SPDX-License-Identifier: MIT

# Wrapper script to pass the correct parameters to the Convert-BpfToNative.ps1 script.

param(
[parameter(Mandatory = $true)]
[ValidateScript({
if(-Not (Test-Path $_) ) {
throw "File does not exist"
}
if(-Not ($_ -match "\.o$")) {
throw "File must be an object file (.o extension)"
}
return $true
})]
[string] $FileName
)

$convertScript = "C:\packages\eBPF-for-Windows.x64\build\native\bin\Convert-BpfToNative.ps1"
if (-Not (Test-Path $convertScript)) {
throw "Convert-BpfToNative.ps1 not found at expected location"
}
try {
& $convertScript -Packages c:\packages -FileName $FileName
if ($LASTEXITCODE -ne 0) {
throw "Convert-BpfToNative.ps1 failed with exit code $LASTEXITCODE"
}
} catch {
Write-Error "Failed to convert BPF file: $_"
exit 1
}
exit 0
Loading