mirror of
https://github.com/eunomia-bpf/bpf-developer-tutorial.git
synced 2026-04-09 21:59:35 +08:00
fix docker image content and add basic CI check (#41)
Replace ``` docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest ``` with: ``` docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest ``` Add a basic CI check for the hello world BPF program.
This commit is contained in:
29
.github/workflows/test.yaml
vendored
Normal file
29
.github/workflows/test.yaml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
name: Test example CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "main" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "main" ]
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * 0'
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
submodules: 'recursive'
|
||||||
|
- name: install deps
|
||||||
|
run: sudo apt install clang llvm
|
||||||
|
- name: test hello world
|
||||||
|
run: |
|
||||||
|
wget https://github.com/eunomia-bpf/eunomia-bpf/releases/latest/download/ecc && chmod +x ./ecc
|
||||||
|
wget https://aka.pw/bpf-ecli -O ecli && chmod +x ./ecli
|
||||||
|
./ecc src/1-helloworld/minimal.bpf.c
|
||||||
|
sudo timeout -s 2 3 ./ecli run src/1-helloworld/package.json || if [ $? = 124 ]; then exit 0; else exit $?; fi
|
||||||
|
- name: install deps
|
||||||
|
run: |
|
||||||
|
sudo apt-get install -y --no-install-recommends \
|
||||||
|
libelf1 libelf-dev zlib1g-dev libclang-13-dev \
|
||||||
|
make git clang llvm pkg-config build-essential
|
||||||
@@ -153,7 +153,7 @@ Packing ebpf object and config into package.json...
|
|||||||
或使用 docker 镜像进行编译:
|
或使用 docker 镜像进行编译:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest
|
docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
然后使用 ecli 运行编译后的程序:
|
然后使用 ecli 运行编译后的程序:
|
||||||
@@ -472,7 +472,7 @@ Packing ebpf object and config into package.json...
|
|||||||
> 或使用 docker 镜像进行编译:
|
> 或使用 docker 镜像进行编译:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest
|
docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
> 然后使用 ecli 运行编译后的程序:
|
> 然后使用 ecli 运行编译后的程序:
|
||||||
@@ -894,7 +894,7 @@ Packing ebpf object and config into package.json...
|
|||||||
或使用 docker 镜像进行编译:
|
或使用 docker 镜像进行编译:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest
|
docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
然后使用 ecli 运行编译后的程序:
|
然后使用 ecli 运行编译后的程序:
|
||||||
@@ -1432,7 +1432,7 @@ char __license[] SEC("license") = "GPL";
|
|||||||
编译运行
|
编译运行
|
||||||
|
|
||||||
```console
|
```console
|
||||||
docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest
|
docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
or compile with `ecc`:
|
or compile with `ecc`:
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ eBPF 是一项革命性的技术,起源于 Linux 内核,可以在操作系
|
|||||||
|
|
||||||
对于浏览器而言,JavaScript 的引入带来的可编程性开启了一场巨大的革命,使浏览器发展成为几乎独立的操作系统。现在让我们回到 eBPF:为了理解 eBPF 对 Linux 内核的可编程性影响,对 Linux 内核的结构以及它如何与应用程序和硬件进行交互有一个高层次的理解是有帮助的[4]。
|
对于浏览器而言,JavaScript 的引入带来的可编程性开启了一场巨大的革命,使浏览器发展成为几乎独立的操作系统。现在让我们回到 eBPF:为了理解 eBPF 对 Linux 内核的可编程性影响,对 Linux 内核的结构以及它如何与应用程序和硬件进行交互有一个高层次的理解是有帮助的[4]。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Linux 内核的主要目的是抽象出硬件或虚拟硬件,并提供一个一致的API(系统调用),允许应用程序运行和共享资源。为了实现这个目的,我们维护了一系列子系统和层,以分配这些责任[5]。每个子系统通常允许某种程度的配置,以考虑到用户的不同需求。如果不能配置所需的行为,就需要改变内核,从历史上看,改变内核的行为,或者让用户编写的程序能够在内核中运行,就有两种选择:
|
Linux 内核的主要目的是抽象出硬件或虚拟硬件,并提供一个一致的API(系统调用),允许应用程序运行和共享资源。为了实现这个目的,我们维护了一系列子系统和层,以分配这些责任[5]。每个子系统通常允许某种程度的配置,以考虑到用户的不同需求。如果不能配置所需的行为,就需要改变内核,从历史上看,改变内核的行为,或者让用户编写的程序能够在内核中运行,就有两种选择:
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ Linux 内核的主要目的是抽象出硬件或虚拟硬件,并提供一个
|
|||||||
|
|
||||||
有了 eBPF,就有了一个新的选择,可以重新编程 Linux 内核的行为,而不需要改变内核的源代码或加载内核模块,同时保证在不同内核版本之间一定程度上的行为一致性和兼容性、以及安全性[6]。为了实现这个目的,eBPF 程序也需要有一套对应的 API,允许用户定义的应用程序运行和共享资源 --- 换句话说,某种意义上讲 eBPF 虚拟机也提供了一套类似于系统调用的机制,借助 eBPF 和用户态通信的机制,Wasm 虚拟机和用户态应用也可以获得这套“系统调用”的完整使用权,一方面能可编程地扩展传统的系统调用的能力,另一方面能在网络、文件系统等许多层次实现更高效的可编程 IO 处理。
|
有了 eBPF,就有了一个新的选择,可以重新编程 Linux 内核的行为,而不需要改变内核的源代码或加载内核模块,同时保证在不同内核版本之间一定程度上的行为一致性和兼容性、以及安全性[6]。为了实现这个目的,eBPF 程序也需要有一套对应的 API,允许用户定义的应用程序运行和共享资源 --- 换句话说,某种意义上讲 eBPF 虚拟机也提供了一套类似于系统调用的机制,借助 eBPF 和用户态通信的机制,Wasm 虚拟机和用户态应用也可以获得这套“系统调用”的完整使用权,一方面能可编程地扩展传统的系统调用的能力,另一方面能在网络、文件系统等许多层次实现更高效的可编程 IO 处理。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
正如上图所示,当今的 Linux 内核正在向一个新的内核模型演化:用户定义的应用程序可以在内核态和用户态同时执行,用户态通过传统的系统调用访问系统资源,内核态则通过 BPF Helper Calls 和系统的各个部分完成交互。截止 2023 年初,内核中的 eBPF 虚拟机中已经有 220 多个Helper 系统接口,涵盖了非常多的应用场景。
|
正如上图所示,当今的 Linux 内核正在向一个新的内核模型演化:用户定义的应用程序可以在内核态和用户态同时执行,用户态通过传统的系统调用访问系统资源,内核态则通过 BPF Helper Calls 和系统的各个部分完成交互。截止 2023 年初,内核中的 eBPF 虚拟机中已经有 220 多个Helper 系统接口,涵盖了非常多的应用场景。
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ Usage: ecc [OPTIONS] <SOURCE_PATH> [EXPORT_EVENT_HEADER]
|
|||||||
也可以使用 docker 镜像进行编译:
|
也可以使用 docker 镜像进行编译:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest # 使用 docker 进行编译。`pwd` 应该包含 *.bpf.c 文件和 *.h 文件。
|
$ docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest # 使用 docker 进行编译。`pwd` 应该包含 *.bpf.c 文件和 *.h 文件。
|
||||||
export PATH=PATH:~/.eunomia/bin
|
export PATH=PATH:~/.eunomia/bin
|
||||||
Compiling bpf object...
|
Compiling bpf object...
|
||||||
Packing ebpf object and config into /src/package.json...
|
Packing ebpf object and config into /src/package.json...
|
||||||
@@ -106,7 +106,7 @@ int handle_tp(void *ctx)
|
|||||||
要编译和运行这段程序,可以使用 ecc 工具和 ecli 命令。首先在 Ubuntu/Debian 上,执行以下命令:
|
要编译和运行这段程序,可以使用 ecc 工具和 ecli 命令。首先在 Ubuntu/Debian 上,执行以下命令:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
sudo apt install libclang-14-dev
|
sudo apt install clang llvm
|
||||||
```
|
```
|
||||||
|
|
||||||
使用 ecc 编译程序:
|
使用 ecc 编译程序:
|
||||||
@@ -120,7 +120,7 @@ Packing ebpf object and config into package.json...
|
|||||||
或使用 docker 镜像进行编译:
|
或使用 docker 镜像进行编译:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest
|
docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
然后使用 ecli 运行编译后的程序:
|
然后使用 ecli 运行编译后的程序:
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ ffff9bf7109d6900 88750 node 127.0.0.1 39755 127.0.0.1 50966
|
|||||||
Compile:
|
Compile:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest
|
docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
或者
|
或者
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ int BPF_PROG(restrict_connect, struct socket *sock, struct sockaddr *address, in
|
|||||||
通过容器编译:
|
通过容器编译:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest
|
docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
或是通过 `ecc` 编译:
|
或是通过 `ecc` 编译:
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ char __license[] SEC("license") = "GPL";
|
|||||||
通过容器编译:
|
通过容器编译:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest
|
docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
或是通过 `ecc` 编译:
|
或是通过 `ecc` 编译:
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ eunomia-bpf 是一个结合 Wasm 的开源 eBPF 动态加载运行时和开发
|
|||||||
编译运行上述代码:
|
编译运行上述代码:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest
|
docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
或者
|
或者
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ eunomia-bpf 是一个结合 Wasm 的开源 eBPF 动态加载运行时和开发
|
|||||||
使用容器编译:
|
使用容器编译:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest
|
docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
或者使用 ecc 编译:
|
或者使用 ecc 编译:
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ eunomia-bpf 是一个结合 Wasm 的开源 eBPF 动态加载运行时和开发
|
|||||||
Compile:
|
Compile:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest
|
docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
Or
|
Or
|
||||||
|
|||||||
@@ -363,7 +363,7 @@ eunomia-bpf 是一个结合 Wasm 的开源 eBPF 动态加载运行时和开发
|
|||||||
Compile:
|
Compile:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest
|
docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
或者
|
或者
|
||||||
|
|||||||
Reference in New Issue
Block a user