Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Add docker build files of 4 linux distros
Browse files Browse the repository at this point in the history
The intention of these docker files is to run build test before send PR
and to solve build failure issues derived from less common distros.

Docker version 20 is required to build images correctly. In docker
version 19, when some conditions related to kernel and glibc versions
are satisfied, `[' command fails during building docker images. Because
`faccessat2' syscall is not whitelisted.

References
https://bugzilla.redhat.com/show_bug.cgi?id=1900021
https://github.com/moby/moby/pull/41353/files
  • Loading branch information
rhdxmr committed Mar 31, 2021
1 parent 8232722 commit 2855bc3
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scripts/Dockerfile-alpine-20210212
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM alpine:20210212
RUN apk update && apk add llvm11-dev clang-dev build-base zlib-dev curl clang-static llvm-static libxml2-dev linux-headers
ENV CARGO_HOME /usr/local
ENV RUSTUP_HOME /usr/local
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ARG KERNEL_HEADERS_TAR
ADD $KERNEL_HEADERS_TAR /
ARG REDBPF_TAR
ADD $REDBPF_TAR /
WORKDIR /redbpf
ENV RUSTFLAGS -Ctarget-feature=-crt-static
CMD cargo build
11 changes: 11 additions & 0 deletions scripts/Dockerfile-arch-20210321
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM archlinux:base-devel-20210321.0.17674
RUN pacman -Sy --noconfirm llvm clang zlib
ENV CARGO_HOME /usr/local
ENV RUSTUP_HOME /usr/local
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
ARG KERNEL_HEADERS_TAR
ADD $KERNEL_HEADERS_TAR /
ARG REDBPF_TAR
ADD $REDBPF_TAR /
WORKDIR /redbpf
CMD cargo build
11 changes: 11 additions & 0 deletions scripts/Dockerfile-fedora-35
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM fedora:rawhide
RUN yum update -y && yum install -y clang llvm-devel zlib-devel
ENV CARGO_HOME /usr/local
ENV RUSTUP_HOME /usr/local
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
ARG KERNEL_HEADERS_TAR
ADD $KERNEL_HEADERS_TAR /
ARG REDBPF_TAR
ADD $REDBPF_TAR /
WORKDIR /redbpf
CMD cargo build
11 changes: 11 additions & 0 deletions scripts/Dockerfile-ubuntu-20.10
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ubuntu:groovy
RUN apt update && apt install -y build-essential zlib1g-dev llvm-11-dev libclang-11-dev curl
ENV CARGO_HOME /usr/local
ENV RUSTUP_HOME /usr/local
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
ARG KERNEL_HEADERS_TAR
ADD $KERNEL_HEADERS_TAR /
ARG REDBPF_TAR
ADD $REDBPF_TAR /
WORKDIR /redbpf
CMD cargo build
43 changes: 43 additions & 0 deletions scripts/build-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

DISTRO=$1
case $DISTRO in
fedora-35|ubuntu-20.10|arch-20210321|alpine-20210212)
;;
*)
echo "error: unknown distro. choose one of <ubuntu-20.10|fedora-35|arch-20210321>" >&2
exit 1
;;
esac

if [[ -z $KERNEL_SOURCE ]]; then
KERNEL_SOURCE=/lib/modules/$(uname -r)
fi

if ! [[ -e $KERNEL_SOURCE ]]; then
echo "error: kernel headers not found" >&2
exit 1
fi

BINDIR=$(readlink -f $(dirname $0))
cd $BINDIR
ROOTDIR=$(git rev-parse --show-toplevel)
cd $ROOTDIR
UNIQUE=$(tr -dc '[:alnum:]' < /dev/urandom |head -c 16)
TEMPDIR=$(mktemp -p $ROOTDIR -d)
git archive --prefix=redbpf/ --format=tar -o $TEMPDIR/$UNIQUE.tar HEAD
while read SM_TAR; do
tar -Af $TEMPDIR/${UNIQUE}.tar ${SM_TAR}
rm -f ${SM_TAR}
done < <(git submodule foreach -q \
"git archive --prefix=redbpf/\$sm_path/ --format=tar -o ${UNIQUE}.tar HEAD; echo \$sm_path/${UNIQUE}.tar")
cd $TEMPDIR
KERNEL_HEADERS_TAR=$(uname -r).tar
tar -hcf $KERNEL_HEADERS_TAR $KERNEL_SOURCE

cp $BINDIR/Dockerfile-${DISTRO} Dockerfile
docker build -t redbpf-build-env:${DISTRO} \
--build-arg REDBPF_TAR=${UNIQUE}.tar \
--build-arg KERNEL_HEADERS_TAR=${KERNEL_HEADERS_TAR} .

rm -rf ${TEMPDIR:?}
10 changes: 10 additions & 0 deletions scripts/build-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

BINDIR=$(dirname $(readlink -f $0))
cd $BINDIR
for DISTRO in fedora-35 ubuntu-20.10 arch-20210321 alpine-20210212; do
./build-image.sh $DISTRO
done

# Make a machine sounds like a jet or melt CPUs..
docker-compose up
10 changes: 10 additions & 0 deletions scripts/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3"
services:
fedora-35:
image: redbpf-build-env:fedora-35
ubuntu-20.10:
image: redbpf-build-env:ubuntu-20.10
arch-20210321:
image: redbpf-build-env:arch-20210321
alpine-20210212:
image: redbpf-build-env:alpine-20210212

0 comments on commit 2855bc3

Please sign in to comment.