Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify CI #3

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,8 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: docker build -t gmonbuildenv -f Dockerfile.buildenv .
- name: Build gmon
run: |
docker run --rm -v ${{ github.workspace }}:/src \
-e GOFLAGS="-buildvcs=false" \
-e BPF_CLANG="clang" \
-e BPF_CFLAGS="-O2 -g -Wall -Werror" \
gmonbuildenv \
script/build.sh
- name: Format gmon
run: |
docker run --rm -v ${{ github.workspace }}:/src \
-e GOFLAGS="-buildvcs=false" \
gmonbuildenv \
script/format.sh
- name: Build & Format
run: ./gmon.sh format
- name: Check changes
run: |
if ! git diff --quiet || ! git diff --staged --quiet; then
Expand All @@ -35,7 +22,4 @@ jobs:
git diff --staged
exit 1
fi
- run: docker build -t gmone2e -f Dockerfile.e2e .
- name: Run e2e tests
run: |
docker run --rm --privileged -v ${{ github.workspace }}/bin/gmon:/usr/bin/gmon -v /sys/kernel/debug:/sys/kernel/debug:ro gmone2e
- run: ./gmon.sh test
25 changes: 0 additions & 25 deletions Dockerfile.buildenv

This file was deleted.

7 changes: 0 additions & 7 deletions Dockerfile.e2e

This file was deleted.

27 changes: 0 additions & 27 deletions Makefile

This file was deleted.

14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,8 @@ gmon_goroutine_uptime_count{stack_0="runtime.goexit",stack_1="main.main.gowrap1"

Follow [the Docker installation guide](https://docs.docker.com/engine/install/#supported-platforms) to build and run tests.

Build

```bash
make
# Ensure that the binary is created
./bin/gmon -help
```

Test

```bash
make test
./gmon.sh build
./gmon.sh install
./gmon.sh test
```
84 changes: 84 additions & 0 deletions gmon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

set -e -x

arch=$(uname -m)
if [ "$arch" != "x86_64" ]; then
echo "Unsupported architecture: $arch"
exit 1
fi

if [ "$1" = "build" ] || [ "$1" = "install" ] || [ "$1" = "test" ] || [ "$1" = "format" ]; then
echo "Running $1 on $arch"
else
echo "Unsupported command: $1"
exit 1
fi

image_buildenv=gmon-buildenv-$arch
dockerfile_buildenv=$(mktemp)
cat > "$dockerfile_buildenv" <<EOF
FROM debian:bookworm-2024031@sha256:e97ee92bf1e11a2de654e9f3da827d8dce32b54e0490ac83bfc65c8706568116
RUN apt-get update && apt-get install -y --no-install-recommends \
wget \
llvm-14 \
clang-14 \
libbpf-dev \
ca-certificates \
clang-format-14 && \
ln -s /usr/bin/llvm-strip-14 /usr/bin/llvm-strip && \
ln -s /usr/bin/clang-14 /usr/bin/clang && \
ln -s /usr/bin/clang-format-14 /usr/bin/clang-format
RUN wget -O- --no-check-certificate https://github.com/libbpf/bpftool/releases/download/v7.3.0/bpftool-v7.3.0-amd64.tar.gz | tar -xzf - -C /usr/bin && chmod +x /usr/bin/bpftool
RUN wget -O- --no-check-certificate https://go.dev/dl/go1.22.1.linux-amd64.tar.gz | tar -xzf - -C /usr/local && chmod +x /usr/local/go/bin/go && ln -s /usr/local/go/bin/go /usr/bin/go
WORKDIR /usr/src
COPY go.mod go.mod
RUN go mod download
EOF
docker build --platform linux/$arch -t $image_buildenv -f "$dockerfile_buildenv" .
rm "$dockerfile_buildenv"

docker run --platform linux/$arch -i \
-v $(pwd):/usr/src \
-e BPF_CLANG="clang" \
-e BPF_CFLAGS="-O2 -g -Wall -Werror" \
--rm $image_buildenv bash -c '\
bpftool btf dump file /sys/kernel/btf/vmlinux format c > ./ebpf/c/vmlinux.h && \
go generate -x ./... && \
GOFLAGS="-buildvcs=false" CGO_ENABLED=0 go build -o /usr/src/bin/gmon'
if [ "$1" = "build" ]; then
exit 0
fi

if [ "$1" = "install" ]; then
sudo install ./bin/gmon /usr/bin/
exit 0
fi

if [ "$1" = "format" ]; then
docker run --platform linux/$arch -i \
-v $(pwd):/usr/src \
--rm $image_buildenv bash -c '\
go mod tidy && \
go vet ./... && \
find . -type f \( -name '*.[ch]' -and -not -name 'vmlinux.h' \) -exec clang-format -i {} \;'
exit 0
fi

if [ "$1" = "test" ]; then
image_e2e=gmon-e2e-$arch
dockerfile_e2e=$(mktemp)
cat > "$dockerfile_e2e" <<EOF
FROM $image_buildenv
WORKDIR /src/fixture
COPY ./fixture .
RUN go mod tidy && go build && install fixture /usr/bin/
WORKDIR /src
COPY . .
CMD ["go", "test", "-v", "./..."]
EOF
docker build --platform linux/$arch -t $image_e2e -f "$dockerfile_e2e" .
rm "$dockerfile_e2e"
docker run --rm --privileged --platform linux/$arch -i -v /sys/kernel/debug:/sys/kernel/debug:ro -v ./bin/gmon:/usr/bin/gmon $image_e2e
exit 0
fi
7 changes: 0 additions & 7 deletions script/build.sh

This file was deleted.

8 changes: 0 additions & 8 deletions script/format.sh

This file was deleted.