From a53481d131c86788df6494050bba3e3c0e25d22f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E5=BE=AE?= <1067852565@qq.com> Date: Thu, 15 Jun 2023 16:36:22 +0800 Subject: [PATCH] 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. --- .github/workflows/test.yaml | 29 +++++++++++++++++++++++++++++ ChatGPT.md | 8 ++++---- src/0-introduce/README.md | 4 ++-- src/1-helloworld/README.md | 6 +++--- src/14-tcpstates/README.md | 2 +- src/19-lsm-connect/README.md | 2 +- src/20-tc/README.md | 2 +- src/6-sigsnoop/README.md | 2 +- src/7-execsnoop/README.md | 2 +- src/8-exitsnoop/README.md | 2 +- src/9-runqlat/README.md | 2 +- 11 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..fba0050 --- /dev/null +++ b/.github/workflows/test.yaml @@ -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 diff --git a/ChatGPT.md b/ChatGPT.md index badf819..d6cf8f7 100644 --- a/ChatGPT.md +++ b/ChatGPT.md @@ -153,7 +153,7 @@ Packing ebpf object and config into package.json... 或使用 docker 镜像进行编译: ```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 运行编译后的程序: @@ -472,7 +472,7 @@ Packing ebpf object and config into package.json... > 或使用 docker 镜像进行编译: ```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 运行编译后的程序: @@ -894,7 +894,7 @@ Packing ebpf object and config into package.json... 或使用 docker 镜像进行编译: ```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 运行编译后的程序: @@ -1432,7 +1432,7 @@ char __license[] SEC("license") = "GPL"; 编译运行 ```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`: diff --git a/src/0-introduce/README.md b/src/0-introduce/README.md index 0ac46b7..ebf04b1 100644 --- a/src/0-introduce/README.md +++ b/src/0-introduce/README.md @@ -10,7 +10,7 @@ eBPF 是一项革命性的技术,起源于 Linux 内核,可以在操作系 对于浏览器而言,JavaScript 的引入带来的可编程性开启了一场巨大的革命,使浏览器发展成为几乎独立的操作系统。现在让我们回到 eBPF:为了理解 eBPF 对 Linux 内核的可编程性影响,对 Linux 内核的结构以及它如何与应用程序和硬件进行交互有一个高层次的理解是有帮助的[4]。 -![kernel-arch](https://raw.githubusercontent.com/bestgopher/bpf-developer-tutorial/main/src/0-introduce/kernel-arch.webp) +![kernel-arch](https://raw.githubusercontent.com/eunomia-bpf/bpf-developer-tutorial/main/src/0-introduce/kernel-arch.webp) Linux 内核的主要目的是抽象出硬件或虚拟硬件,并提供一个一致的API(系统调用),允许应用程序运行和共享资源。为了实现这个目的,我们维护了一系列子系统和层,以分配这些责任[5]。每个子系统通常允许某种程度的配置,以考虑到用户的不同需求。如果不能配置所需的行为,就需要改变内核,从历史上看,改变内核的行为,或者让用户编写的程序能够在内核中运行,就有两种选择: @@ -22,7 +22,7 @@ Linux 内核的主要目的是抽象出硬件或虚拟硬件,并提供一个 有了 eBPF,就有了一个新的选择,可以重新编程 Linux 内核的行为,而不需要改变内核的源代码或加载内核模块,同时保证在不同内核版本之间一定程度上的行为一致性和兼容性、以及安全性[6]。为了实现这个目的,eBPF 程序也需要有一套对应的 API,允许用户定义的应用程序运行和共享资源 --- 换句话说,某种意义上讲 eBPF 虚拟机也提供了一套类似于系统调用的机制,借助 eBPF 和用户态通信的机制,Wasm 虚拟机和用户态应用也可以获得这套“系统调用”的完整使用权,一方面能可编程地扩展传统的系统调用的能力,另一方面能在网络、文件系统等许多层次实现更高效的可编程 IO 处理。 -![new-os](https://github.com/bestgopher/bpf-developer-tutorial/blob/main/src/0-introduce/new-os-model.jpg) +![new-os](https://github.com/eunomia-bpf/bpf-developer-tutorial/blob/main/src/0-introduce/new-os-model.jpg?raw=true) 正如上图所示,当今的 Linux 内核正在向一个新的内核模型演化:用户定义的应用程序可以在内核态和用户态同时执行,用户态通过传统的系统调用访问系统资源,内核态则通过 BPF Helper Calls 和系统的各个部分完成交互。截止 2023 年初,内核中的 eBPF 虚拟机中已经有 220 多个Helper 系统接口,涵盖了非常多的应用场景。 diff --git a/src/1-helloworld/README.md b/src/1-helloworld/README.md index 57c7805..7809015 100644 --- a/src/1-helloworld/README.md +++ b/src/1-helloworld/README.md @@ -61,7 +61,7 @@ Usage: ecc [OPTIONS] [EXPORT_EVENT_HEADER] 也可以使用 docker 镜像进行编译: ```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 Compiling bpf object... Packing ebpf object and config into /src/package.json... @@ -106,7 +106,7 @@ int handle_tp(void *ctx) 要编译和运行这段程序,可以使用 ecc 工具和 ecli 命令。首先在 Ubuntu/Debian 上,执行以下命令: ```shell -sudo apt install libclang-14-dev +sudo apt install clang llvm ``` 使用 ecc 编译程序: @@ -120,7 +120,7 @@ Packing ebpf object and config into package.json... 或使用 docker 镜像进行编译: ```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 运行编译后的程序: diff --git a/src/14-tcpstates/README.md b/src/14-tcpstates/README.md index a2f8bb0..6b82341 100644 --- a/src/14-tcpstates/README.md +++ b/src/14-tcpstates/README.md @@ -312,7 +312,7 @@ ffff9bf7109d6900 88750 node 127.0.0.1 39755 127.0.0.1 50966 Compile: ```shell -docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest +docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest ``` 或者 diff --git a/src/19-lsm-connect/README.md b/src/19-lsm-connect/README.md index 86767a0..22b970f 100644 --- a/src/19-lsm-connect/README.md +++ b/src/19-lsm-connect/README.md @@ -113,7 +113,7 @@ int BPF_PROG(restrict_connect, struct socket *sock, struct sockaddr *address, in 通过容器编译: ```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` 编译: diff --git a/src/20-tc/README.md b/src/20-tc/README.md index 00ffe6b..85dabab 100644 --- a/src/20-tc/README.md +++ b/src/20-tc/README.md @@ -69,7 +69,7 @@ char __license[] SEC("license") = "GPL"; 通过容器编译: ```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` 编译: diff --git a/src/6-sigsnoop/README.md b/src/6-sigsnoop/README.md index 9fd66ec..5ed928c 100755 --- a/src/6-sigsnoop/README.md +++ b/src/6-sigsnoop/README.md @@ -96,7 +96,7 @@ eunomia-bpf 是一个结合 Wasm 的开源 eBPF 动态加载运行时和开发 编译运行上述代码: ```shell -docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest +docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest ``` 或者 diff --git a/src/7-execsnoop/README.md b/src/7-execsnoop/README.md index 56d6e7d..fa9bc28 100644 --- a/src/7-execsnoop/README.md +++ b/src/7-execsnoop/README.md @@ -83,7 +83,7 @@ eunomia-bpf 是一个结合 Wasm 的开源 eBPF 动态加载运行时和开发 使用容器编译: ```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 编译: diff --git a/src/8-exitsnoop/README.md b/src/8-exitsnoop/README.md index 2b64aea..01300d4 100644 --- a/src/8-exitsnoop/README.md +++ b/src/8-exitsnoop/README.md @@ -125,7 +125,7 @@ eunomia-bpf 是一个结合 Wasm 的开源 eBPF 动态加载运行时和开发 Compile: ```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 diff --git a/src/9-runqlat/README.md b/src/9-runqlat/README.md index 0a3fb64..0148988 100755 --- a/src/9-runqlat/README.md +++ b/src/9-runqlat/README.md @@ -363,7 +363,7 @@ eunomia-bpf 是一个结合 Wasm 的开源 eBPF 动态加载运行时和开发 Compile: ```shell -docker run -it -v `pwd`/:/src/ yunwei37/ebpm:latest +docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest ``` 或者