Skip to content

Commit 9776de4

Browse files
committed
feat: docker release
1 parent da8b672 commit 9776de4

File tree

9 files changed

+183
-52
lines changed

9 files changed

+183
-52
lines changed

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,61 @@ jobs:
6161
goreleaser release --clean --rm-dist
6262
env:
6363
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
65+
- name: Run GoReleaser Docker Push
66+
if: |
67+
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
68+
(github.event_name == 'pull_request' &&
69+
github.event.action == 'closed' &&
70+
github.event.pull_request.merged == true &&
71+
github.event.pull_request.base.ref == 'main')
72+
run: |
73+
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
74+
goreleaser release --rm-dist --skip-publish --snapshot
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
78+
- name: Set up QEMU
79+
uses: docker/setup-qemu-action@v3
80+
81+
- name: Set up Docker Buildx
82+
uses: docker/setup-buildx-action@v3
83+
84+
- name: Download BPF object file
85+
run: |
86+
gh release download --repo SentinalFS/file-monitor --clobber --pattern "monitor.bpf.o"
87+
env:
88+
GH_TOKEN: ${{ github.token }}
89+
90+
- name: Decide to push or not
91+
id: decide
92+
run: |
93+
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then
94+
echo "PUSH=true" >> $GITHUB_ENV
95+
else
96+
echo "PUSH=false" >> $GITHUB_ENV
97+
fi
98+
99+
- name: Build Image
100+
if: env.PUSH == 'false'
101+
run: |
102+
docker buildx build \
103+
--platform linux/amd64,linux/arm64 \
104+
--build-arg TARGETARCH=amd64 \
105+
--file Dockerfile \
106+
-t siddh34/go-ebpf-logger:latest \
107+
.
108+
109+
- name: Login to DockerHub
110+
if: env.PUSH == 'true'
111+
run: echo "${{ secrets.DOCKER_ACCESS_TOKEN }}" | docker login -u "siddh34" --password-stdin
112+
113+
- name: Build & Push Docker images
114+
if: env.PUSH == 'true'
115+
run: |
116+
docker buildx build \
117+
--platform linux/amd64,linux/arm64 \
118+
--file Dockerfile \
119+
--push \
120+
-t siddh34/go-ebpf-logger:latest \
121+
.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ go.work.sum
2828
dist
2929

3030
# object files
31-
monitor.bpf.o
31+
monitor.bpf.o
32+
33+
# log files
34+
*.log

Dockerfile

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

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.2
1+
0.0.3

bpf/pin_maps.go

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

bpf/setup.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ func SetupBPF(bpfObj string) (*ebpf.Map, *ebpf.Map, func()) {
3333
links = append(links, &kp)
3434
}
3535

36-
monitored_inode_map := coll.Maps["monitored_inodes"]
37-
err = pinMaps(monitored_inode_map)
38-
if err != nil {
39-
panic(err)
40-
}
41-
4236
events := coll.Maps["events"]
4337
if events == nil {
4438
fmt.Printf("Map 'events' not found\n")

build-docker.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
echo "Enter version of file monitor to use with docker (e.g. 1.0.0):"
2+
3+
if [ -z "$1" ]; then
4+
read -r version
5+
else
6+
version="$1"
7+
fi
8+
9+
echo "Building Docker image with version: $version"
10+
11+
if ! command -v gh &> /dev/null; then
12+
echo "gh CLI is not installed. Please install it first and proceed with authentication."
13+
exit 1
14+
fi
15+
16+
if ! gh auth status &> /dev/null; then
17+
echo "You are not authenticated with GitHub CLI. Please authenticate first."
18+
exit 1
19+
fi
20+
21+
gh release download v${version} --repo SentinalFS/file-monitor --clobber --pattern "monitor.bpf.o"
22+
23+
if [ $? -ne 0 ]; then
24+
echo "Failed to download the file monitor binary. Please check the version and try again."
25+
exit 1
26+
fi
27+
28+
echo "Running go releaser"
29+
30+
if ! command -v go &> /dev/null; then
31+
echo "Go is not installed. Please install Go and try again."
32+
exit 1
33+
fi
34+
35+
if ! command -v goreleaser &> /dev/null; then
36+
echo "Goreleaser is not installed. Please install Goreleaser and try again."
37+
exit 1
38+
fi
39+
40+
goreleaser release --snapshot --skip=publish --clean
41+
42+
43+
if docker --version &> /dev/null; then
44+
echo "Docker is installed. Proceeding with build."
45+
else
46+
echo "Docker is not installed. Please install Docker and try again."
47+
exit 1
48+
fi
49+
50+
arch=$(uname -m)
51+
if [ "$arch" = "aarch64" ] || [ "$arch" = "arm64" ]; then
52+
echo "Detected ARM architecture. Building Docker image for ARM."
53+
docker build -t go-logger-arm:latest -f Dockerfile.amd64 --build-arg TARGETARCH=arm64 .
54+
if [ $? -ne 0 ]; then
55+
echo "Docker build for ARM failed."
56+
exit 1
57+
fi
58+
elif [ "$arch" = "x86_64" ]; then
59+
echo "Detected x86_64 architecture. Building Docker image for x86_64."
60+
docker build -t go-logger-amd64:latest -f Dockerfile.amd64 --build-arg TARGETARCH=amd64 .
61+
if [ $? -ne 0 ]; then
62+
echo "Docker build for x86_64 failed."
63+
exit 1
64+
fi
65+
else
66+
echo "Non-ARM architecture detected. No additional ARM build required."
67+
fi

changelog.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"version": "0.0.3",
4+
"changes": [
5+
"Removed map pinning"
6+
]
7+
},
8+
{
9+
"version": "0.0.2",
10+
"changes": [
11+
"Updated maps"
12+
]
13+
},
14+
{
15+
"version": "0.0.1",
16+
"changes": [
17+
"Initial release with basic functionality."
18+
]
19+
}
20+
]

models/models.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
package models
22

33
type BaseEventData struct {
4-
Pid uint32
5-
Uid uint32
6-
Filename [144]byte
7-
Comm [32]byte
8-
Timestamp uint64
9-
CgroupId uint64
10-
Otype [16]byte
4+
Pid uint32
5+
Uid uint32
6+
Filename [176]byte
7+
ParentFilename [176]byte
8+
Inode uint64
9+
Comm [32]byte
10+
Timestamp uint64
11+
CgroupId uint64
12+
Otype [16]byte
1113
}
1214

1315
type RenameData struct {
14-
Pid uint32
15-
Uid uint32
16-
OldFileName [144]byte
17-
NewFileName [144]byte
18-
Comm [32]byte
19-
Timestamp uint64
20-
CgroupId uint64
21-
Otype [16]byte
22-
}
16+
Pid uint32
17+
Uid uint32
18+
OldFileName [176]byte
19+
OldParentFilename [176]byte
20+
NewFileName [176]byte
21+
NewParentFilename [176]byte
22+
InodeOld uint64
23+
InodeNew uint64
24+
Comm [32]byte
25+
Timestamp uint64
26+
CgroupId uint64
27+
Otype [16]byte
28+
}

0 commit comments

Comments
 (0)