Skip to content

Commit

Permalink
feat(ci): use zig for compilation
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Scolaro <[email protected]>
  • Loading branch information
therealbobo committed Dec 13, 2024
1 parent fe10874 commit fe93a90
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 268 deletions.
55 changes: 55 additions & 0 deletions .github/actions/install-zig/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: 'install-zig'
description: 'Install zig compiler and make it available in PATH.'

runs:
using: "composite"
steps:
- name: Store zig version as local output
shell: bash
id: store
env:
ZIG_VERSION: '0.14.0-dev.2424+7cd2c1ce8'
run: |
echo "zig_version=${ZIG_VERSION}" >> "$GITHUB_OUTPUT"
# TODO: this is only needed because we are using a development version of zig,
# since we need https://github.com/ziglang/zig/pull/21253 to be included.
# Development versions of zig are not kept alive forever, but get overridden.
# We cache it to keep it alive.
- name: Download zig (cached)
id: cache-zig
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: zig
key: zig-${{ runner.os }}-${{ runner.arch }}-${{ steps.store.outputs.zig_version }}

- name: Download zig
if: steps.cache-zig.outputs.cache-hit != 'true'
shell: bash
run: |
curl -L -o zig.tar.xz https://ziglang.org/builds/zig-linux-$(uname -m)-${{ steps.store.outputs.zig_version }}.tar.xz
tar -xvf zig.tar.xz
cat > zig-linux-$(uname -m)-${{ steps.store.outputs.zig_version }}/zig-cc <<EOF
#!/bin/bash
exec zig cc -target $(uname -m)-linux-gnu.2.17 -mcpu=baseline "\$@"
EOF
chmod +x zig-linux-$(uname -m)-${{ steps.store.outputs.zig_version }}/zig-cc
cat > zig-linux-$(uname -m)-${{ steps.store.outputs.zig_version }}/zig-c++ <<EOF
#!/bin/bash
exec zig c++ -target $(uname -m)-linux-gnu.2.17 -mcpu=baseline "\$@"
EOF
chmod +x zig-linux-$(uname -m)-${{ steps.store.outputs.zig_version }}/zig-c++
mv zig-linux-$(uname -m)-${{ steps.store.outputs.zig_version }}/ zig
- name: Setup zig
shell: bash
id: zig
run: |
echo "$(pwd)/zig" >> $GITHUB_PATH
echo "CC=zig-cc" >> $GITHUB_ENV
echo "CXX=zig-c++" >> $GITHUB_ENV
echo "AR=zig ar" >> $GITHUB_ENV
echo "RANLIB=zig ranlib" >> $GITHUB_ENV
199 changes: 36 additions & 163 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
SKEL_BUILDER_IMAGE_BASE: ghcr.io/draios/sysdig-skel-builder-pr
BUILDER_DEV: ghcr.io/draios/sysdig-builder:dev
SKEL_BUILDER_DEV: ghcr.io/draios/sysdig-skel-builder:dev

runs-on: ubuntu-latest
steps:
- name: Checkout Sysdig
Expand All @@ -38,7 +37,7 @@ jobs:

- name: Set up Docker Buildx
if: steps.builder-files.outputs.any_changed == 'true'
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Login to Github Packages
if: steps.builder-files.outputs.any_changed == 'true'
Expand All @@ -47,30 +46,13 @@ jobs:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get new skeleton builder image tag
id: get-new-skeleton-builder
if: steps.builder-files.outputs.any_changed == 'true'
run: |
echo "skeleton_builder_image=${{ (github.event.pull_request.number != '') && format('{0}:{1}', env.SKEL_BUILDER_IMAGE_BASE, github.event.pull_request.number) || env.SKEL_BUILDER_DEV }}" >> $GITHUB_OUTPUT

- name: Get new builder image tag
id: get-new-builder
if: steps.builder-files.outputs.any_changed == 'true'
run: |

Check failure on line 53 in .github/workflows/ci.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] reported by reviewdog 🐶 shellcheck reported issue in this script: SC2086:info:1:172: Double quote to prevent globbing and word splitting [shellcheck] Raw Output: .github/workflows/ci.yaml:53:9: shellcheck reported issue in this script: SC2086:info:1:172: Double quote to prevent globbing and word splitting [shellcheck]
echo "builder_image=${{ (github.event.pull_request.number != '') && format('{0}:{1}', env.BUILDER_IMAGE_BASE, github.event.pull_request.number) || env.BUILDER_DEV }}" >> $GITHUB_OUTPUT
- name: Build new skeleton builder
id: skeleton-builder
if: steps.builder-files.outputs.any_changed == 'true'
uses: docker/build-push-action@v6
with:
context: docker/builder
file: docker/builder/modern_bpf_probe.Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.get-new-skeleton-builder.outputs.skeleton_builder_image }}
push: true

- name: Build new builder
id: build-builder
if: steps.builder-files.outputs.any_changed == 'true'
Expand All @@ -80,166 +62,59 @@ jobs:
platforms: linux/amd64,linux/arm64
tags: ${{ steps.get-new-builder.outputs.builder_image }}
push: true

outputs:
builder_image: ${{ (steps.builder-files.outputs.any_changed == 'true') && steps.get-new-builder.outputs.builder_image || env.BUILDER_DEV }}
skeleton_builder_image: ${{ (steps.builder-files.outputs.any_changed == 'true') && steps.get-new-skeleton-builder.outputs.skeleton_builder_image || env.SKEL_BUILDER_DEV }}

build-skeleton-sysdig-linux-amd64:
needs: builder
runs-on: ubuntu-latest
container:
image: ${{ needs.builder.outputs.skeleton_builder_image }}
steps:
- name: Checkout Sysdig
uses: actions/checkout@v4
with:
path: sysdig
- name: Link paths
run: |
mkdir -p /source
ln -s "$GITHUB_WORKSPACE/sysdig" /source/sysdig
- name: Prepare build skeleton
run: build cmake-skeleton
- name: Build skeleton
run: build make-skeleton
- name: Cache build skeleton
uses: actions/cache/save@v3
if: always()
id: cache
with:
path: /build-skeleton
key: build-skeleton-${{ github.run_id }}

build-sysdig-linux-amd64:
needs: [builder,build-skeleton-sysdig-linux-amd64]
build-sysdig-linux:
needs: [builder]
runs-on: ubuntu-latest
container:
image: ${{ needs.builder.outputs.builder_image }}
volumes:
- '/node20217:/node20217:rw,rshared'
- '/node20217:/__e/node20:ro,rshared'
env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
strategy:
matrix:
platform:
- linux/amd64
- linux/arm64

steps:
- name: install nodejs20glibc2.17
run: |
yum install curl -yyq
curl -LO https://unofficial-builds.nodejs.org/download/release/v20.9.0/node-v20.9.0-linux-x64-glibc-217.tar.xz
tar -xf node-v20.9.0-linux-x64-glibc-217.tar.xz --strip-components 1 -C /node20217
ldd /__e/node20/bin/node
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Checkout Sysdig
uses: actions/checkout@v4
with:
path: sysdig
- name: Link paths
fetch-depth: 0

- name: Build Sysdig
run: |
mkdir -p /source
ln -s "$GITHUB_WORKSPACE/sysdig" /source/sysdig
- name: Restore build skeleton
id: cache
uses: actions/cache/restore@v3
with:
path: /build-skeleton
key: build-skeleton-${{ github.run_id }}
restore-keys: build-skeleton-
- name: Build
run: build cmake
- name: Build packages
run: build package
- name: Upload rpm package
uses: actions/upload-artifact@v3
with:
name: sysdig-dev-linux-x86_64.rpm
path: |
/build/release/sysdig-*.rpm
- name: Upload deb package
uses: actions/upload-artifact@v3
with:
name: sysdig-dev-linux-x86_64.deb
path: |
/build/release/sysdig-*.deb
- name: Upload tar.gz package
uses: actions/upload-artifact@v3
with:
name: sysdig-dev-linux-x86_64.tar.gz
path: |
/build/release/sysdig-*.tar.gz
cmake -DUSE_BUNDLED_DEPS=ON -DBUILD_BPF=OFF -DBUILD_DRIVER=OFF -DCMAKE_BUILD_TYPE=Release -S . -B build -G Ninja
cmake --build build --target package --config Release
build-sysdig-linux-arm64:
needs: builder
env:
REGISTRY: ghcr.io
BUILDER_IMAGE_BASE: ghcr.io/draios/sysdig-builder-pr
SKEL_BUILDER_IMAGE_BASE: ghcr.io/draios/sysdig-skel-builder-pr
BUILDER_DEV: ghcr.io/draios/sysdig-builder:dev
SKEL_BUILDER_DEV: ghcr.io/draios/sysdig-skel-builder:dev
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
runs-on: ubuntu-latest
steps:
- name: Checkout Sysdig
uses: actions/checkout@v4
with:
path: sysdig
- name: Create build dir
- name: Set artifact name
id: artifact_name
run: |

Check failure on line 95 in .github/workflows/ci.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] reported by reviewdog 🐶 shellcheck reported issue in this script: SC2086:info:1:77: Double quote to prevent globbing and word splitting [shellcheck] Raw Output: .github/workflows/ci.yaml:95:9: shellcheck reported issue in this script: SC2086:info:1:77: Double quote to prevent globbing and word splitting [shellcheck]
mkdir -p ${{ github.workspace }}/sysdig-build-aarch64
echo "name=sysdig-dev-$(echo ${{ matrix.platform }} | sed -e 's|/|-|g')" >> $GITHUB_OUTPUT
- name: Login to Github Packages
uses: docker/login-action@v3
- name: Upload rpm package
uses: actions/upload-artifact@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
name: ${{ steps.artifact_name.outputs.name }}.rpm
path: |
build/sysdig-*.rpm
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: 'amd64,arm64'
- name: Run the build skeleton process with Docker
uses: addnab/docker-run-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ${{ env.REGISTRY }}
image: ${{ needs.builder.outputs.skeleton_builder_image }}
options: --platform=linux/arm64 -v ${{ github.workspace }}/sysdig:/source/sysdig -v ${{ github.workspace }}/sysdig-build-aarch64:/build/dev-packages -v ${{ github.workspace }}/skeleton-build:/build-skeleton
run: |
mkdir -p /build/dev-packages && \
build cmake-skeleton && \
build make-skeleton
- name: Run the build process with Docker
uses: addnab/docker-run-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ${{ env.REGISTRY }}
image: ${{ needs.builder.outputs.builder_image }}
options: --platform=linux/arm64 -v ${{ github.workspace }}/sysdig:/source/sysdig -v ${{ github.workspace }}/sysdig-build-aarch64:/build/dev-packages -v ${{ github.workspace }}/skeleton-build:/build-skeleton
run: |
mkdir -p /build/dev-packages && \
build cmake && \
build package && \
cp /build/release/sysdig-* /build/dev-packages
- name: Upload deb package
uses: actions/upload-artifact@v3
with:
name: sysdig-dev-linux-aarch64.deb
path: |
${{ github.workspace }}/sysdig-build-aarch64/sysdig-*.deb
- name: Upload rpm package
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: sysdig-dev-linux-aarch64.rpm
name: ${{ steps.artifact_name.outputs.name }}.deb
path: |
${{ github.workspace }}/sysdig-build-aarch64/sysdig-*.rpm
build/sysdig-*.deb
- name: Upload tar.gz package
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: sysdig-dev-linux-aarch64.tar.gz
name: ${{ steps.artifact_name.outputs.name }}.tar.gz
path: |
${{ github.workspace }}/sysdig-build-aarch64/sysdig-*.tar.gz
build/sysdig-*.tar.gz
build-sysdig-others-amd64:
name: build-sysdig-other-amd64
Expand All @@ -259,9 +134,8 @@ jobs:
uses: actions/checkout@v4
- name: Build
run: |
mkdir -p build
cd build && cmake -Wno-dev ..
cmake --build . --target package --config Release
cmake -Wno-dev -S . -B build
cmake --build build --target package --config Release
- name: Upload artifacts
uses: actions/upload-artifact@v3

Check failure on line 140 in .github/workflows/ci.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] reported by reviewdog 🐶 the runner of "actions/upload-artifact@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue [action] Raw Output: .github/workflows/ci.yaml:140:15: the runner of "actions/upload-artifact@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue [action]
with:
Expand All @@ -284,9 +158,8 @@ jobs:
uses: actions/checkout@v4
- name: Build
run: |
mkdir -p build
cd build && cmake -Wno-dev ..
cmake --build . --target package --config Release
cmake -Wno-dev -S . -B build
cmake --build build --target package --config Release
- name: Upload artifacts
uses: actions/upload-artifact@v3

Check failure on line 164 in .github/workflows/ci.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] reported by reviewdog 🐶 the runner of "actions/upload-artifact@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue [action] Raw Output: .github/workflows/ci.yaml:164:15: the runner of "actions/upload-artifact@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue [action]
with:
Expand Down
Loading

0 comments on commit fe93a90

Please sign in to comment.