Skip to content

Commit

Permalink
Install libbpf archive to allow running tests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
bobrik committed Oct 16, 2022
1 parent e06bb8a commit decd677
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
50 changes: 46 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ jobs:
run: |
git fetch --prune --unshallow --tags --force
- name: Build ebpf_exporter
- name: Build libbpf and ebpf_exporter
run: |
docker buildx build --progress plain --tag ebpf-exporter-build .
id=$(docker create ebpf-exporter-build)
docker cp $id:/usr/sbin/ebpf_exporter ebpf_exporter.x86_64
docker cp $id:/build/libbpf.tar.gz libbpf.x86_64.tar.gz
- name: Upload libbpf.tar.gz
uses: actions/upload-artifact@v2
with:
name: libbpf.x86_64.tar.gz
path: libbpf.x86_64.tar.gz

- name: Upload ebpf_exporter
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -53,7 +60,14 @@ jobs:
run: |
docker buildx build --progress plain --tag ebpf-exporter-build --platform linux/arm64 .
id=$(docker create ebpf-exporter-build)
docker cp $id:/root/go/bin/ebpf_exporter ebpf_exporter.aarch64
docker cp $id:/usr/bin/ebpf_exporter ebpf_exporter.aarch64
docker cp $id:/build/libbpf.tar.gz libbpf.aarch64.tar.gz
- name: Upload libbpf.tar.gz
uses: actions/upload-artifact@v2
with:
name: libbpf.aarch64.tar.gz
path: libbpf.aarch64.tar.gz

- name: Upload ebpf_exporter
uses: actions/upload-artifact@v2
Expand All @@ -72,15 +86,28 @@ jobs:

- uses: actions/checkout@v2

- name: Download libbpf.tar.gz
uses: actions/download-artifact@v2
with:
name: libbpf.x86_64.tar.gz

- name: Install libbpf
run: |
sudo tar -C / -xvvf libbpf.x86_64.tar.gz
- name: Install libelf-dev
run: |
sudo apt-get install -y libelf-dev
- name: Check vendored dependencies
run: |
go mod verify
- name: Build
run: go build -v ./...
run: CGO_LDFLAGS="-l bpf" go build -v ./...

- name: Test
run: go test -v ./...
run: CGO_LDFLAGS="-l bpf" go test -v ./...

lint-ebpf-exporter-x86_64:
name: Lint ebpf_exporter (x86_64)
Expand All @@ -93,7 +120,22 @@ jobs:

- uses: actions/checkout@v2

- name: Download libbpf.tar.gz
uses: actions/download-artifact@v2
with:
name: libbpf.x86_64.tar.gz

- name: Install libbpf
run: |
sudo tar -C / -xvvf libbpf.x86_64.tar.gz
- name: Install libelf-dev
run: |
sudo apt-get install -y libelf-dev
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.50.0
env:
CGO_LDFLAGS: "-l bpf"
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ RUN mkdir /build
RUN git clone --branch v1.0.1 --depth 1 https://github.com/libbpf/libbpf.git /build/libbpf && \
make -C /build/libbpf/src BUILD_STATIC_ONLY=y LIBSUBDIR=lib install

RUN tar -czf /build/libbpf.tar.gz /usr/lib/libbpf.a /usr/lib/pkgconfig/libbpf.pc /usr/include/bpf

COPY ./ /build/ebpf_exporter

RUN cd /build/ebpf_exporter && PATH="/usr/lib/go-1.19/bin:$PATH" CGO_LDFLAGS="-l bpf" GOFLAGS="-mod=vendor" go build -o /usr/sbin/ebpf_exporter -v -ldflags=" \
Expand Down

0 comments on commit decd677

Please sign in to comment.