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

Add job to update amazon 2 in cron workflow #103

Closed
wants to merge 16 commits into from
156 changes: 93 additions & 63 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,99 @@
name: Update BTFHub Archive
on:
push: {}
schedule:
- cron: "0 1 * * *"
workflow_dispatch: {}
jobs:
build:
archive-checkout:
name: Checkout BTFHub Archive
runs-on: ubuntu-latest
steps:
- name: Checkout BTFHub Archive
uses: actions/checkout@v4
with:
repository: aquasecurity/btfhub-archive
path: archive
# token: ${{ secrets.PAT_RAFAEL }}

commit-changes:
name: Commit archive changes
needs: [amazon-update, host-update]
runs-on: ubuntu-latest
steps:
- name: Check Status
run: |
cd archive
git status
# - name: Commit and Push to BTFHub Archive
# run: |
# cd archive
# git config --local user.name "Rafael David Tinoco"
# git config --local user.email "[email protected]"
# git add -A
# git diff-index --quiet HEAD || git commit -m "Update BTFHUB Archive from BTFHUB"
# git push

amazon-update:
name: Update Amazon 2 BTF Archive
needs: archive-checkout
runs-on: ubuntu-latest
container:
image: amazonlinux:2
volumes:
- archive:/root/archive
steps:
- name: Install needed amazon packages
run: |
yum install -y yum-utils tar gzip xz clang make cmake git libdwarf-devel elfutils-libelf-devel elfutils-devel
yum-config-manager -y --enable amzn2-core-debuginfo
shell: bash

# - name: Authenticate
# run: |
# gh auth login --with-token <<<'${{ secrets.PAT_RAFAEL }}'

- uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Check out BTFHub
uses: actions/checkout@v4
with:
submodules: 'recursive'
# token: ${{ secrets.PAT_RAFAEL }}

- run: git config --system --add safe.directory $(pwd)
shell: bash

- name: build pahole
run: |
cd ./3rdparty/dwarves
mkdir build
cd build
cmake -D__LIB=lib -DDWARF_INCLUDE_DIR=/usr/include ..
make install
echo "/usr/local/lib" >> /etc/ld.so.conf.d/pahole.conf
ldconfig
shell: bash

- name: Compile BTFHub Tool
run: |
make
shell: bash

- name: Fetch and Generate new BTFs (AMAZON 2)
run: |
./btfhub -workers 6 -d amzn -r 2

host-update:
name: Update BTF Archive
env:
HOME: "/tmp/root"
GOPATH: "/tmp/go"
GOCACHE: "/tmp/go-cache"
GOROOT: "/usr/local/go"
runs-on:
[
"github-self-hosted_ami-0f4881c8d69684001_${{ github.event.number }}-${{ github.run_id }}",
]
needs: archive-checkout
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.20'
#
- name: Setup Swap File
run: |
Expand Down Expand Up @@ -73,89 +151,41 @@ jobs:
--slave /usr/bin/cc cc /usr/bin/clang-14
shell: bash
#
- name: Authenticate
run: |
gh auth login --with-token <<<'${{ secrets.PAT_RAFAEL }}'
# - name: Authenticate
# run: |
# gh auth login --with-token <<<'${{ secrets.PAT_RAFAEL }}'
#
- name: Check out BTFHub
uses: actions/checkout@v3
with:
repository: aquasecurity/btfhub
path: ./btfhub
token: ${{ secrets.PAT_RAFAEL }}
# Authenticate
- name: Checkout BTFHub Archive
uses: actions/checkout@v3
with:
repository: aquasecurity/btfhub-archive
path: ./btfhub-archive
token: ${{ secrets.PAT_RAFAEL }}
uses: actions/checkout@v4
# token: ${{ secrets.PAT_RAFAEL }}
#
- name: Install pahole
run: |
cd btfhub
./3rdparty/pahole.sh
shell: bash
#
- name: Install bpftool
run: |
cd btfhub
./3rdparty/bpftool.sh
shell: bash
#
- name: Bring current BTFHub Archive
run: |
cd btfhub
make bring
shell: bash
#
- name: Compile BTFHub Tool
run: |
cd btfhub
make
shell: bash
#
- name: Fetch and Generate new BTFs (UBUNTU)
run: |
cd btfhub
./btfhub -workers 6 -d ubuntu
# debian stretch seems to be gone, updates for buster and bullseye only
- name: Fetch and Generate new BTFs (DEBIAN)
run: |
cd btfhub
./btfhub -workers 6 -d debian -r buster
./btfhub -workers 6 -d debian -r bullseye
#
- name: Fetch and Generate new BTFs (CENTOS)
run: |
cd btfhub
./btfhub -workers 6 -d centos
#
- name: Fetch and Generate new BTFs (FEDORA)
run: |
cd btfhub
./btfhub -workers 6 -d fedora
#
- name: Fetch and Generate new BTFs (ORACLE)
run: |
cd btfhub
./btfhub -workers 6 -d ol
#
- name: Take new BTFs to BTFHub Archive
run: |
cd btfhub
make take
#
- name: Check Status
run: |
cd btfhub-archive
git status
#
- name: Commit and Push to BTFHub Archive
run: |
cd btfhub-archive
git config --local user.name "Rafael David Tinoco"
git config --local user.email "[email protected]"
git add -A
git diff-index --quiet HEAD || git commit -m "Update BTFHUB Archive from BTFHUB"
git push
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# binary
btfhub
# arvhices
archive/*
custom-archive/*
# archives
archive/
# makefile leftovers
.check*
# binary
# JetBrains
.idea/
1 change: 0 additions & 1 deletion archive/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion custom-archive/.gitignore

This file was deleted.

5 changes: 2 additions & 3 deletions pkg/pkg/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ func yumDownload(ctx context.Context, pkg string, destdir string) error {

destDirParam := fmt.Sprintf("--downloaddir=%s", destdir)

cmd := exec.CommandContext(ctx,
"sudo", "yum", "install", "-y", "--downloadonly", destDirParam, pkg,
)
binary, args := utils.SudoCMD("yum", "install", "-y", "--downloadonly", destDirParam, pkg)
cmd := exec.CommandContext(ctx, binary, args...)

cmd.Stdout = os.Stdout
cmd.Stderr = stderr
Expand Down
3 changes: 2 additions & 1 deletion pkg/repo/rhel.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func (d *RHELRepo) GetKernelPackages(
) error {
altArch := d.archs[arch]
rver := d.releaseVersions[release+":"+altArch]
if err := utils.RunCMD(ctx, "", "sudo", "subscription-manager", "release", fmt.Sprintf("--set=%s", rver)); err != nil {
binary, args := utils.SudoCMD("subscription-manager", "release", fmt.Sprintf("--set=%s", rver))
if err := utils.RunCMD(ctx, "", binary, args...); err != nil {
return err
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/repo/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
"path/filepath"
"strings"

"golang.org/x/exp/maps"

"github.com/aquasecurity/btfhub/pkg/job"
"github.com/aquasecurity/btfhub/pkg/kernel"
"github.com/aquasecurity/btfhub/pkg/pkg"
"github.com/aquasecurity/btfhub/pkg/utils"
"golang.org/x/exp/maps"
)

func parseYumPackages(rdr io.Reader, minVersion kernel.Version) ([]pkg.Package, error) {
Expand Down Expand Up @@ -62,7 +63,8 @@ func parseYumPackages(rdr io.Reader, minVersion kernel.Version) ([]pkg.Package,
func yumSearch(ctx context.Context, pkg string) (*bytes.Buffer, error) {
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
cmd := exec.CommandContext(ctx, "sudo", "yum", "search", "--showduplicates", pkg)
binary, args := utils.SudoCMD("yum", "search", "--showduplicates", pkg)
cmd := exec.CommandContext(ctx, binary, args...)
cmd.Stdout = stdout
cmd.Stderr = stderr
if err := cmd.Run(); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/utils/btf.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ func RunCMD(ctx context.Context, cwd string, binary string, args ...string) erro

return nil
}

func SudoCMD(binary string, args ...string) (string, []string) {
_, err := exec.LookPath("sudo")
if err == nil {
return "sudo", append([]string{binary}, args...)
}
return binary, args
}
Loading