Welcome to the eunomia-template
! This project template is designed to help you quickly start
developing eBPF projects using eunomia-bpf in C. The template provides a solid starting point with a Makefile,
Dockerfile, and GitHub action, along with all necessary dependencies to simplify your development process.
借助于 GitHub 模板和 Github Codespace,可以轻松构建 eBPF 项目和开发环境,一键在线编译运行 eBPF 程序。关于中文的文档和详细的 eBPF 开发教程,可以参考:https://github.com/eunomia-bpf/bpf-developer-tutorial
There are other templates for other languages:
- https://github.com/eunomia-bpf/libbpf-template: eBPF project template based on the C language and the libbpf framework.
- https://github.com/eunomia-bpf/cilium-ebpf-starter-template: eBPF project template based on the Go language and the cilium/ebpf framework.
- https://github.com/eunomia-bpf/libbpf-rs-starter-template: eBPF project template based on the Rust language and the libbpf-rs framework.
To get started, simply click the "Use this template" button on the GitHub repository page. This will create a new repository in your account with the same files and structure as this template.
Run the following code to run the eBPF code from the cloud to your local machine in one line:
$ sudo docker run --rm -it --privileged ghcr.io/eunomia-bpf/eunomia-template:latest
TIME EVENT COMM PID PPID FILENAME/EXIT CODE
09:25:14 EXEC sh 28142 1788 /bin/sh
09:25:14 EXEC playerctl 28142 1788 /nix/store/vf3rsb7j3p7zzyjpb0a3axl8yq4z1sq5-playerctl-2.4.1/bin/playerctl
09:25:14 EXIT playerctl 28142 1788 [1] (6ms)
09:25:15 EXEC sh 28145 1788 /bin/sh
09:25:15 EXEC playerctl 28145 1788 /nix/store/vf3rsb7j3p7zzyjpb0a3axl8yq4z1sq5-playerctl-2.4.1/bin/playerctl
09:25:15 EXIT playerctl 28145 1788 [1] (6ms)
Using direnv and nix, you can quickly access a dev shell with a complete development environment.
With direnv, you can automatically load the required dependencies when you enter the directory. This way you don't have to worry about installing dependencies to break your other project development environment.
See how to install direnv and Nix:
- direnv: https://github.com/direnv/direnv/blob/master/docs/installation.md
- Nix: run
sh <(curl -L https://nixos.org/nix/install) --daemon
Then use the following command to enable direnv support in this directory.
direnv allow
If you want use nix flake without direnv, simply run:
nix develop
This starter template includes the following features:
- A
Makefile
that allows you to build the project in one command - A
Dockerfile
to create a containerized environment for your project - A
flake.nix
to enter a dev shell with needed dependencies - A GitHub action to automate your build and publish process and docker image
- All necessary dependencies for C development with eunomia-bpf
Click the "Use this template" button on the GitHub repository page to create a new repository based on this template.
Clone your newly created repository to your local machine:
git clone https://github.com/your_username/your_new_repository.git
For dependencies, it varies from distribution to distribution. You can refer to shell.nix and dockerfile for installation.
On Ubuntu, you may run make install
or
sudo apt-get install -y --no-install-recommends \
libelf1 libelf-dev zlib1g-dev \
make clang llvm
to install dependencies.
To build the project, run the following command:
make build
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.
You can run the binary with:
ecli run src/package.json
Or with Github Packages locally:
docker run --rm -it --privileged -v $(pwd):/examples ghcr.io/eunomia-bpf/eunomia-template:latest
This template also includes a GitHub action that will automatically build and publish your project when you push to the repository.
To customize this action, edit the .github/workflows/publish.yml
file.
We welcome contributions to improve this template! If you have any ideas or suggestions, feel free to create an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for more information.
For more documents, please refer to https://eunomia-bpf.github.io/