Docker environment for aya rust ebpf compilation - Stack Overflow
I am trying to create a eBPF program that runs on Ubuntu. It is written in rust using the aya
library.
My computer is running MacOs so as far as I understand, I cant install all the kernel related things on my computer, also the resulting project is meant to run in Docker containers, so I am trying to do this in Docker.
My approach is a Multistage build.
- Install all the tools needed for the builds
- Compile dependencies so this is not repeated every time
- Build the project
- Run the project.
FROM ubuntu:latest AS build_environment
SHELL ["/bin/bash", "-c"]
# Install tools
RUN apt-get update && apt-get install -y build-essential curl
RUN curl -sSf | bash -s -- -y && \
source $HOME/.cargo/env && \
rustup install stable && \
rustup toolchain install nightly --component rust-src && \
source $HOME/.cargo/env && rustup target add bpfel-unknown-none --toolchain nightly \
cargo install bpf-linker
# Install only dependencies.
FROM build_environment AS prebuild
# Creates temporary files to compile with
WORKDIR /usr/src/middleware
COPY Cargo.toml Cargo.lock ./
RUN mkdir -p src/bin && \
echo "fn main() {println!(\"hi\"); loop{};}" > src/main.rs && \
echo "fn main() {}" > src/bin/hook.rs
RUN source $HOME/.cargo/env && cargo build # Install only dependencies
RUN source $HOME/.cargo/env && cargo clean -p middleware # Remove the dummy code
FROM prebuild AS build
# Add actual source code
COPY src src
# Compile source code
RUN source $HOME/.cargo/env && cargo build --target bpfel-unknown-none --bin hook && cargo build
FROM ubuntu:latest AS runtime
WORKDIR /app
RUN apt-get update && apt-get install -y curl
RUN apt-get install -y net-tools
#RUN apt-get -y install llvm
RUN apt install -y llvm
COPY --from=build /usr/src/middleware/target .
COPY --from=build /usr/src/middleware/target/debug/hook ./
COPY --from=build /usr/src/middleware/target/debug/middleware ./
CMD ["sh", "-c", "RUST_LOG=debug ./middleware"]
The hook.rs and main.rs files are the same as here: /book/start/hello-xdp/#verifying-the-program
However, hook.rs is in the bin folder rather than in a separate project (no extra Cargo.toml
).
I previously got this to run, however I would always get an error about the .init section in the hook binary (invalid program section '.init'
, when the program started. I figured this might be because of the missing target, so I added
10: source $HOME/.cargo/env && rustup target add bpfel-unknown-none --toolchain nightly \
and added the —target in
31: RUN source $HOME/.cargo/env && cargo build --target bpfel-unknown-none --bin hook && cargo build
which now fails because of
156.8
156.8 nightly-x86_64-unknown-linux-gnu installed - rustc 1.85.0-nightly (dd84b7d5e 2024-12-27)
156.8
156.8 info: checking for self-update
157.2 error: component 'rust-std' for target 'bpfel-unknown-none' is unavailable for download for channel 'nightly'
Since this is my first time working with ebpf and my second project with rust i am out of depth. I would appreciate any help or pointers towards what i have to change to get the program to work and why that needs to be changed.
EDIT:
Leaving only line 31 but removing line 10 leads to:
4.856 error[E0463]: can't find crate for `core`
4.857 |
4.858 = note: the `bpfel-unknown-none` target may not be installed
4.858 = help: consider downloading the target with `rustup target add bpfel-unknown-none`
- 纳德拉:微软所有软件将转向包年订户模式
- 大本营不保?美国安卓系统激活量超iOS
- 谷歌无人驾驶汽车或将带来下一轮失业大潮
- How do I convert a saved tensorflow model to pytorch which is not compatible with ONNX? - Stack Overflow
- python - Adding quotes to list objects to format as a dictionary pyspark - Stack Overflow
- wordpress - How do I write a plugin using jQuery to extend FooGallery plugin without "initialize failed" and &
- Unable to deploy flex consumption function app using azure bicep - Stack Overflow
- sirishortcuts - How to Set Custom Icon for iOS App Shortcut? - Stack Overflow
- ios - AccessorySetupKit picker doesn't show accessory unless previously paired in Setting app first - Stack Overflow
- Flutter upload document : file key is missing in payload - Stack Overflow
- How to make smooth animations in Android Compose for expanding TextField? - Stack Overflow
- python - How to display only the tags translated into the corresponding language on a multilingual site? - Stack Overflow
- docker - Python Telegram bot freezes when run by Airflow - Stack Overflow
- augmented reality - Applying 2d image to a 3d object in xcode tutorials? - Stack Overflow
- docker - Pulling AWS Parameter Store secrets into a deployed Dockerized app on EC2 - Stack Overflow
- php - Add Algorithm to the XML tag generated by SOAP - Stack Overflow
- Font Size Mismatch When Using Fallback Fonts in FFmpeg ASS Subtitles - Stack Overflow