Skip to content

Commit 8c25f24

Browse files
committed
fix: Implimentation
1 parent aeb150a commit 8c25f24

File tree

22 files changed

+382
-305
lines changed

22 files changed

+382
-305
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,32 @@
1-
name: CI and Release
1+
name: Release Workflow
22

33
on:
44
push:
5-
branches: [main]
5+
branches:
6+
- main
67
pull_request:
7-
branches: [main]
8+
branches:
9+
- main
10+
11+
permissions:
12+
contents: write
813

914
jobs:
10-
check-version:
11-
name: Check VERSION.txt updated in PR
15+
release:
1216
runs-on: ubuntu-latest
13-
if: github.event_name == 'pull_request'
1417
steps:
1518
- name: Checkout code
16-
uses: actions/checkout@v3
17-
with:
18-
fetch-depth: 0
19-
20-
- name: Ensure VERSION.txt is updated
21-
run: |
22-
git fetch origin main
23-
CHANGED=$(git diff --name-only origin/main...HEAD)
24-
if ! echo "$CHANGED" | grep -qx VERSION.txt; then
25-
echo "Error: VERSION.txt must be updated in this pull request."
26-
exit 1
27-
fi
28-
29-
build:
30-
name: Build Go project
31-
runs-on: ubuntu-latest
32-
steps:
33-
- uses: actions/checkout@v3
19+
uses: actions/checkout@v4
3420

3521
- name: Set up Go
36-
uses: actions/setup-go@v4
22+
uses: actions/setup-go@v5
3723
with:
38-
go-version: 1.20
39-
40-
- name: Download dependencies
41-
run: go mod tidy
24+
go-version: '1.23'
4225

43-
- name: Build binary
44-
run: go build -o listener
26+
- name: Install GoReleaser
27+
run: go install github.com/goreleaser/goreleaser@latest
4528

46-
release:
47-
- name: Check version
29+
- name: Check version
4830
run: |
4931
VERSION=$(cat VERSION.txt)
5032
echo "version=$VERSION" >> $GITHUB_ENV
@@ -63,18 +45,19 @@ jobs:
6345
git tag "v${{ env.version }}"
6446
git push origin "v${{ env.version }}"
6547
66-
- name: Create GitHub Release
48+
- name: Run build using goreleaser on local
49+
run: goreleaser release --snapshot --skip=publish --clean
50+
51+
- name: Run GoReleaser Release
6752
if: |
6853
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
6954
(github.event_name == 'pull_request' &&
7055
github.event.action == 'closed' &&
7156
github.event.pull_request.merged == true &&
7257
github.event.pull_request.base.ref == 'main')
73-
uses: softprops/action-gh-release@v2
74-
with:
75-
tag_name: v${{ env.version }}
76-
name: Release v${{ env.version }}
77-
files: build/monitor.bpf.o
78-
# generate_release_notes: true
58+
run: |
59+
export GORELEASER_CURRENT_TAG="v${{ env.version }}"
60+
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
61+
goreleaser release --clean --rm-dist
7962
env:
80-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ go.work.sum
2323

2424
# env file
2525
.env
26+
27+
# build
28+
dist

.goreleaser.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
project_name: go-ebpf-logger
2+
3+
builds:
4+
- main: ./main.go
5+
goos:
6+
- linux
7+
- darwin
8+
- windows
9+
goarch:
10+
- amd64
11+
- arm64
12+
13+
archives:
14+
- format: tar.gz
15+
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
16+
17+
release:
18+
github:
19+
owner: siddh34
20+
name: go-ebpf-logger

Dockerfile.amd64

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM debian:stable-slim
2+
3+
ARG TARGETARCH
4+
5+
WORKDIR /app
6+
7+
COPY dist/go-ebpf-logger_linux_${TARGETARCH}_v1/go-ebpf-logger /app/go-ebpf-logger
8+
9+
COPY monitor.bpf.o /app/monitor.bpf.o
10+
11+
RUN chmod +x /app/go-ebpf-logger
12+
13+
ENTRYPOINT ["/app/go-ebpf-logger"]

Dockerfile.arm64

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM debian:stable-slim
2+
3+
ARG TARGETARCH
4+
5+
WORKDIR /app
6+
7+
COPY dist/go-ebpf-logger_linux_${TARGETARCH}/go-ebpf-logger /app/go-ebpf-logger
8+
9+
COPY monitor.bpf.o /app/monitor.bpf.o
10+
11+
RUN chmod +x /app/go-ebpf-logger
12+
13+
ENTRYPOINT ["/app/go-ebpf-logger"]

LICENSE

Whitespace-only changes.

Makefile

Lines changed: 0 additions & 15 deletions
This file was deleted.

README.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,62 @@
1-
# go-ebpf-logger
1+
# go-ebpf-logger
2+
3+
The golang code that actually runs the file monitor ebpf code
4+
5+
## Pre-requisite
6+
7+
Install golang, visit [link](https://go.dev/doc/install)
8+
9+
Install goreleaser, visit [link](https://goreleaser.com/install/#aur)
10+
11+
Install gh, visit [link](https://cli.github.com/)
12+
13+
## Screenshots
14+
15+
It works!
16+
17+
![Screenshot showing go-ebpf-logger in action](./docs/assets/working.png)
18+
19+
20+
## Run it on Local
21+
22+
Get file monitor binary from the repo
23+
24+
Put the version accordingly here in the below command at `vX.Y.Z`
25+
26+
```sh
27+
gh release download vX.Y.Z --repo SentinalFS/file-monitor --pattern "monitor.bpf.o"
28+
```
29+
30+
Run it
31+
32+
```sh
33+
sudo go run main.go
34+
```
35+
36+
## Run it on docker
37+
38+
Get file monitor binary from the repo
39+
40+
Put the version accordingly here in the below command at `vX.Y.Z`
41+
42+
```sh
43+
gh release download vX.Y.Z --repo SentinalFS/file-monitor --pattern "monitor.bpf.o"
44+
```
45+
46+
Run go releaser on local
47+
48+
```sh
49+
goreleaser release --snapshot --skip=publish --clean
50+
```
51+
52+
Build it
53+
54+
```sh
55+
docker build --build-arg TARGETARCH=amd64 -t go-ebpf-logger -f Dockerfile.amd64 .
56+
```
57+
58+
Run it
59+
60+
```sh
61+
sudo docker run --rm -it --privileged -v /sys/fs/bpf:/sys/fs/bpf:rw go-ebpf-logger
62+
```

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.0.1

bpf/pin_maps.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package bpf
2+
3+
import (
4+
"os"
5+
6+
"github.com/cilium/ebpf"
7+
8+
"fmt"
9+
10+
"go-ebp-logger/constants"
11+
)
12+
13+
func pinMaps(m *ebpf.Map) error {
14+
if m != nil {
15+
path := "/sys/fs/bpf/" + constants.InodeMapName
16+
if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
17+
fmt.Printf("Warning: failed to remove existing pin at %s: %v", path, err)
18+
}
19+
if err := m.Pin(path); err != nil {
20+
fmt.Printf("Failed to pin map %s to %s: %v", constants.InodeMapName,path, err)
21+
}
22+
fmt.Printf("Map %s pinned succesfully", constants.InodeMapName)
23+
return nil
24+
}
25+
26+
fmt.Printf("Map %s not found", constants.InodeMapName)
27+
return fmt.Errorf("no map was pinned")
28+
}

0 commit comments

Comments
 (0)