|
1 | | -# A template for eunomia-bpf programs |
| 1 | +# **eunomia-template** |
2 | 2 |
|
3 | | -This is a template for eunomia-bpf eBPF programs. |
4 | | -You can use it as a template, compile it online with `Github Actions` or offline as a bootstrap template. |
| 3 | + |
| 4 | +[](https://github.com/eunomia-bpf/eunomia-template/actions/workflows/publish.yml) |
| 5 | + |
5 | 6 |
|
6 | | -### Use docker installed ecc and ecli |
| 7 | +Welcome to the **`eunomia-template`**! This project template is designed to help you quickly start |
| 8 | +developing eBPF projects using eunomia-bpf in C. The template provides a solid starting point with a Makefile, |
| 9 | +Dockerfile, and GitHub action, along with all necessary dependencies to simplify your development process. |
7 | 10 |
|
8 | | -Run the following code to access an environment with ecli and ecc, |
9 | | -where you can easily compile and run or debug ebpf programs in this docker. |
| 11 | +借助于 GitHub 模板和 Github Codespace,可以轻松构建 eBPF 项目和开发环境,一键在线编译运行 eBPF 程序。关于中文的文档和详细的 eBPF 开发教程,可以参考:https://github.com/eunomia-bpf/bpf-developer-tutorial |
| 12 | + |
| 13 | +There are other templates for other languages: |
| 14 | + |
| 15 | +- <https://github.com/eunomia-bpf/libbpf-template>: eBPF project template based on the C language and the libbpf framework. |
| 16 | +- <https://github.com/eunomia-bpf/cilium-ebpf-starter-template>: eBPF project template based on the Go language and the cilium/ebpf framework. |
| 17 | +- <https://github.com/eunomia-bpf/libbpf-rs-starter-template>: eBPF project template based on the Rust language and the libbpf-rs framework. |
| 18 | + |
| 19 | +## **Getting Started** |
| 20 | + |
| 21 | +To get started, simply click the "Use this template" button on the GitHub repository page. This will create |
| 22 | +a new repository in your account with the same files and structure as this template. |
| 23 | + |
| 24 | +### Use docker |
| 25 | + |
| 26 | +Run the following code to run the eBPF code from the cloud to your local machine in one line: |
| 27 | + |
| 28 | +```console |
| 29 | +$ sudo docker run --rm -it --privileged ghcr.io/eunomia-bpf/eunomia-template:latest |
| 30 | +TIME EVENT COMM PID PPID FILENAME/EXIT CODE |
| 31 | +09:25:14 EXEC sh 28142 1788 /bin/sh |
| 32 | +09:25:14 EXEC playerctl 28142 1788 /nix/store/vf3rsb7j3p7zzyjpb0a3axl8yq4z1sq5-playerctl-2.4.1/bin/playerctl |
| 33 | +09:25:14 EXIT playerctl 28142 1788 [1] (6ms) |
| 34 | +09:25:15 EXEC sh 28145 1788 /bin/sh |
| 35 | +09:25:15 EXEC playerctl 28145 1788 /nix/store/vf3rsb7j3p7zzyjpb0a3axl8yq4z1sq5-playerctl-2.4.1/bin/playerctl |
| 36 | +09:25:15 EXIT playerctl 28145 1788 [1] (6ms) |
| 37 | +``` |
| 38 | + |
| 39 | +### Use Nix |
| 40 | + |
| 41 | +Using [direnv](https://github.com/direnv/direnv) and nix, you can quickly access a dev shell with a complete development environment. |
| 42 | + |
| 43 | +With direnv, you can automatically load the required dependencies when you enter the directory. |
| 44 | +This way you don't have to worry about installing dependencies to break your other project development environment. |
| 45 | + |
| 46 | +See how to install direnv and Nix: |
| 47 | +- direnv: https://github.com/direnv/direnv/blob/master/docs/installation.md |
| 48 | +- Nix: run |
| 49 | +``` |
| 50 | +sh <(curl -L https://nixos.org/nix/install) --daemon |
| 51 | +``` |
| 52 | + |
| 53 | +Then use the following command to enable direnv support in this directory. |
10 | 54 |
|
11 | 55 | ```sh |
12 | | -docker build -t eunomia-template . |
13 | | -docker run -it eunomia-template:latest |
| 56 | +direnv allow |
14 | 57 | ``` |
15 | 58 |
|
16 | | -### Compile and run the eBPF code as simple as possible! |
| 59 | +If you want use nix flake without direnv, simply run: |
17 | 60 |
|
18 | | -Download the pre-compiled `ecli` binary from here: |
19 | | -[eunomia-bpf/eunomia-bpf](https://github.com/eunomia-bpf/eunomia-bpf/releases) |
| 61 | +```sh |
| 62 | +nix develop |
| 63 | +``` |
20 | 64 |
|
21 | | -To install, just download and use the `ecli` binary from here: |
22 | | -[eunomia-bpf/eunomia-bpf](https://github.com/eunomia-bpf/eunomia-bpf/releases): |
| 65 | +## **Features** |
23 | 66 |
|
24 | | -## use this repo as a github action to compile online |
| 67 | +This starter template includes the following features: |
25 | 68 |
|
26 | | -1. use this repo as a github template: see [creating-a-repository-from-a-template](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template) |
27 | | -2. modify the `template.bpf.c`, commit it and wait for the workflow to stop |
28 | | -3. Run the `ecli` with remote url: |
| 69 | +- A **`Makefile`** that allows you to build the project in one command |
| 70 | +- A **`Dockerfile`** to create a containerized environment for your project |
| 71 | +- A **`flake.nix`** to enter a dev shell with needed dependencies |
| 72 | +- A GitHub action to automate your build and publish process |
| 73 | + and docker image |
| 74 | +- All necessary dependencies for C development with eunomia-bpf |
29 | 75 |
|
30 | | -```console |
31 | | -$ sudo ./ecli run https://eunomia-bpf.github.io/eunomia-template/package.json |
| 76 | +## **How to use** |
| 77 | + |
| 78 | +### **1. Create a new repository using this template** |
| 79 | + |
| 80 | +Click the "Use this template" button on the GitHub repository page to create a new repository based on this template. |
| 81 | + |
| 82 | +### **2. Clone your new repository** |
| 83 | + |
| 84 | +Clone your newly created repository to your local machine: |
| 85 | + |
| 86 | +```sh |
| 87 | +git clone https://github.com/your_username/your_new_repository.git |
| 88 | +``` |
| 89 | + |
| 90 | +### **3. Install dependencies** |
| 91 | + |
| 92 | +For dependencies, it varies from distribution to distribution. You can refer to shell.nix and dockerfile for installation. |
| 93 | + |
| 94 | +On Ubuntu, you may run `make install` or |
| 95 | + |
| 96 | +```sh |
| 97 | +sudo apt-get install -y --no-install-recommends \ |
| 98 | + libelf1 libelf-dev zlib1g-dev \ |
| 99 | + make clang llvm |
| 100 | +``` |
| 101 | + |
| 102 | +to install dependencies. |
| 103 | + |
| 104 | +### **4. Build the project** |
| 105 | + |
| 106 | +To build the project, run the following command: |
| 107 | + |
| 108 | +```sh |
| 109 | +make build |
32 | 110 | ``` |
33 | 111 |
|
34 | | -## quick start |
| 112 | +This will compile your code and create the necessary binaries. You can you the `Github Code space` or `Github Action` to build the project as well. |
| 113 | + |
| 114 | +### ***Run the Project*** |
35 | 115 |
|
36 | | -just write some code in the `bootstrap.bpf.c`, after that, simply run this: |
| 116 | +You can run the binary with: |
37 | 117 |
|
38 | | -```shell |
39 | | -$ docker run -it -v ./:/src yunwei37/ebpm:latest # use absolute path |
| 118 | +```console |
| 119 | +ecli run src/package.json |
40 | 120 | ``` |
41 | 121 |
|
42 | | -you will get a `package.json` in your root dir. Just run: |
| 122 | +Or with Github Packages locally: |
43 | 123 |
|
44 | | -```shell |
45 | | -$ sudo ./ecli run package.json |
| 124 | +```console |
| 125 | +docker run --rm -it --privileged -v $(pwd):/examples ghcr.io/eunomia-bpf/eunomia-template:latest |
46 | 126 | ``` |
47 | 127 |
|
48 | | -The ebpf compiled code can run on different kernel versions(CO-RE). You can just copied the json to another machine. |
49 | | -see: [github.com/eunomia-bpf/eunomia-bpf](https://github.com/eunomia-bpf/eunomia-bpf) for the runtime, and [eunomia-bpf/eunomia-cc](https://github.com/eunomia-bpf/eunomia-cc) for our compiler tool chains. |
| 128 | +### **7. GitHub Actions** |
50 | 129 |
|
51 | | -## The code here |
| 130 | +This template also includes a GitHub action that will automatically build and publish your project when you push to the repository. |
| 131 | +To customize this action, edit the **`.github/workflows/publish.yml`** file. |
52 | 132 |
|
53 | | -This is an example of ebpf code, we copied the bootstrap.bpf.c from [libbpf-bootstrap](https://github.com/libbpf/libbpf-bootstrap/tree/master/examples/c), without any modification. You can read their `README` for details: https://github.com/libbpf/libbpf-bootstrap |
| 133 | +## **Contributing** |
54 | 134 |
|
55 | | -## more examples |
| 135 | +We welcome contributions to improve this template! If you have any ideas or suggestions, |
| 136 | +feel free to create an issue or submit a pull request. |
56 | 137 |
|
57 | | -for more examples, please see: [eunomia-bpf/eunomia-bpf/tree/master/bpftools/examples](https://github.com/eunomia-bpf/eunomia-bpf/tree/master/bpftools/examples) |
| 138 | +## **License** |
58 | 139 |
|
| 140 | +This project is licensed under the MIT License. See the **[LICENSE](LICENSE)** file for more information. |
59 | 141 | ## detail documents |
60 | 142 |
|
61 | 143 | For more documents, please refer to https://eunomia-bpf.github.io/ |
0 commit comments