On Mon, Feb 13, 2023 at 6:44 PM Mark Michelson <mmich...@redhat.com> wrote:

> On 2/10/23 04:28, Ales Musil wrote:
> > Add simple script that allows user to run tests and builds
> > using container. At the same time add example Dockerfile for
> > Fedora 37.
> >
> > Basic usage is:
> > ./utilities/containers/ci.sh
> >
> > This will compile the project with GCC, it expects podman
> > as container platform with default image being "ovn-org/ovn-tests".
> >
> > The test parameters can be specified as environment variables.
> >
> > Signed-off-by: Ales Musil <amu...@redhat.com>
> > ---
> > v2: Fix "ARH" typo.
> > ---
> >   utilities/automake.mk                  |   3 +
> >   utilities/containers/Makefile          |   7 ++
> >   utilities/containers/ci.sh             | 137 +++++++++++++++++++++++++
> >   utilities/containers/fedora/Dockerfile |  59 +++++++++++
> >   4 files changed, 206 insertions(+)
> >   create mode 100644 utilities/containers/Makefile
> >   create mode 100755 utilities/containers/ci.sh
> >   create mode 100755 utilities/containers/fedora/Dockerfile
> >
> > diff --git a/utilities/automake.mk b/utilities/automake.mk
> > index 67b04cbff..83d38ae9a 100644
> > --- a/utilities/automake.mk
> > +++ b/utilities/automake.mk
> > @@ -37,6 +37,9 @@ EXTRA_DIST += \
> >       utilities/ovn_detrace.py.in \
> >       utilities/ovndb-servers.ocf \
> >       utilities/checkpatch.py \
> > +    utilities/containers/ci.sh \
> > +    utilities/containers/Makefile \
> > +    utilities/containers/fedora/Dockerfile \
> >       utilities/docker/Makefile \
> >       utilities/docker/start-ovn \
> >       utilities/docker/ovn_default_nb_port \
> > diff --git a/utilities/containers/Makefile
> b/utilities/containers/Makefile
> > new file mode 100644
> > index 000000000..8b39e3493
> > --- /dev/null
> > +++ b/utilities/containers/Makefile
> > @@ -0,0 +1,7 @@
> > +CONTAINER_CMD ?= podman
> > +DISTRO ?= fedora
> > +IMAGE_NAME ?= "ovn-org/ovn-tests"
> > +
> > +.PHONY: build
> > +
> > +build: ;$(CONTAINER_CMD) build --no-cache --rm -t $(IMAGE_NAME) -f
> $(DISTRO)/Dockerfile .
> > diff --git a/utilities/containers/ci.sh b/utilities/containers/ci.sh
> > new file mode 100755
> > index 000000000..0a380f88c
> > --- /dev/null
> > +++ b/utilities/containers/ci.sh
> > @@ -0,0 +1,137 @@
> > +#!/bin/bash -xe
> > +# Copyright (c) 2022, Red Hat, Inc.
> > +#
> > +# Licensed under the Apache License, Version 2.0 (the "License");
> > +# you may not use this file except in compliance with the License.
> > +# You may obtain a copy of the License at:
> > +#
> > +#     http://www.apache.org/licenses/LICENSE-2.0
> > +#
> > +# Unless required by applicable law or agreed to in writing, software
> > +# distributed under the License is distributed on an "AS IS" BASIS,
> > +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
> > +# See the License for the specific language governing permissions and
> > +# limitations under the License.
> > +#
> > +
> > +OVN_PATH=${OVN_PATH:-$PWD}
> > +OVS_PATH=${OVS_PATH:-$OVN_PATH/ovs}
> > +CONTAINER_CMD=${CONTAINER_CMD:-podman}
> > +CONTAINER_WORKSPACE="/workspace"
> > +CONTAINER_WORKDIR="/workspace/ovn-tmp"
> > +IMAGE_NAME=${IMAGE_NAME:-"ovn-org/ovn-tests"}
> > +
> > +# Test variables
> > +ARCH=${ARH:-$(uname -i)}
>
> This should be
>
> ARCH=${ARCH:-$(uname -i)}
>

I've thought that v2 is fixing that. Nevermind it will be fixed in v3.


>
> > +CC=${CC:-gcc}
> > +
> > +
> > +test -t 1 && USE_TTY="t"
> > +
> > +function container_exec() {
> > +    ${CONTAINER_CMD} exec "-i$USE_TTY" "$CONTAINER_ID" /bin/bash -c "$1"
> > +}
> > +
> > +function container_shell() {
> > +    ${CONTAINER_CMD} exec "-i$USE_TTY" "$CONTAINER_ID" /bin/bash
> > +}
> > +
> > +function remove_container() {
> > +    res=$?
> > +    [ "$res" -ne 0 ] && echo "*** ERROR: $res ***"
> > +    ${CONTAINER_CMD} rm -f "$CONTAINER_ID"
> > +}
> > +
> > +function copy_sources_to_workdir() {
> > +    container_exec "
> > +        mkdir -p $CONTAINER_WORKDIR \
> > +        && \
> > +        cp -a $CONTAINER_WORKSPACE/ovn/. $CONTAINER_WORKDIR \
> > +        && \
> > +        rm -rf $CONTAINER_WORKDIR/ovs \
> > +        &&
> > +        cp -a $CONTAINER_WORKSPACE/ovs/. $CONTAINER_WORKDIR/ovs
> > +    "
> > +}
> > +
> > +function overwrite_jobs() {
> > +    container_exec "
> > +        sed -i s/-j[0-9]/-j$jobs/ $CONTAINER_WORKDIR/.ci/linux-build.sh
> > +    "
> > +}
> > +
> > +function run_tests() {
> > +    container_exec "
> > +        cd $CONTAINER_WORKDIR \
> > +        && \
> > +        ARCH=$ARCH CC=$CC LIBS=$LIBS OPTS=$OPTS TESTSUITE=$TESTSUITE \
> > +        TEST_RANGE=$TEST_RANGE SANITIZERS=$SANITIZERS \
> > +        ./.ci/linux-build.sh
> > +    "
> > +}
> > +
> > +options=$(getopt --options "" \
> > +    --long help,shell,jobs:,ovn-path:,ovs-path:,image-name:\
> > +    -- "${@}")
> > +eval set -- "$options"
> > +while true; do
> > +    case "$1" in
> > +    --shell)
> > +        shell="1"
> > +        ;;
> > +    --jobs)
> > +        shift
> > +        jobs="$1"
> > +        ;;
> > +    --ovn-path)
> > +        shift
> > +        OVN_PATH="$1"
> > +        ;;
> > +    --ovs-path)
> > +        shift
> > +        OVS_PATH="$1"
> > +        ;;
> > +    --image-name)
> > +        shift
> > +        IMAGE_NAME="$1"
> > +        ;;
> > +    --help)
> > +        set +x
> > +        printf "$0 [--shell] [--help] [--jobs=<JOBS>]
> [--ovn-path=<OVN_PATH>]"
> > +        printf "[--ovs-path=<OVS_PATH>] [--image-name=<IMAGE_NAME>]\n"
> > +        exit
> > +        ;;
> > +    --)
> > +        shift
> > +        break
> > +        ;;
> > +    esac
> > +    shift
> > +done
> > +
> > +# Workaround for https://bugzilla.redhat.com/2153359
> > +if [ "$ARCH" = "aarch64" ]; then
> > +    ASAN_OPTIONS="detect_leaks=0"
> > +fi
> > +
> > +CONTAINER_ID="$($CONTAINER_CMD run --privileged -d \
> > +    --pids-limit=-1 \
> > +    --env ASAN_OPTIONS=$ASAN_OPTIONS \
> > +    -v /lib/modules/$(uname -r):/lib/modules/$(uname -r):ro \
> > +    -v $OVN_PATH:$CONTAINER_WORKSPACE/ovn:Z \
> > +    -v $OVS_PATH:$CONTAINER_WORKSPACE/ovs:Z \
> > +    $IMAGE_NAME)"
> > +trap remove_container EXIT
> > +
> > +copy_sources_to_workdir
> > +
> > +if [ -n "$jobs" ]; then
> > +    overwrite_jobs
> > +fi
> > +
> > +if [ -n "$shell" ];then
> > +    container_shell
> > +    exit 0
> > +fi
> > +
> > +run_tests
> > diff --git a/utilities/containers/fedora/Dockerfile
> b/utilities/containers/fedora/Dockerfile
> > new file mode 100755
> > index 000000000..0fcf11b8e
> > --- /dev/null
> > +++ b/utilities/containers/fedora/Dockerfile
> > @@ -0,0 +1,59 @@
> > +FROM quay.io/fedora/fedora:37
> > +
> > +# Update distro, install packages and clean any possible leftovers
> > +RUN dnf -y update \
> > +    && \
> > +    dnf -y install \
> > +        autoconf \
> > +        automake \
> > +        checkpolicy \
> > +        clang \
> > +        curl \
> > +        dhcp-server \
> > +        ethtool \
> > +        gcc \
> > +        gcc-c++ \
> > +        git \
> > +        glibc-langpack-en \
> > +        groff \
> > +        iproute \
> > +        iproute-tc \
> > +        iputils \
> > +        kernel-devel \
> > +        libcap-ng-devel \
> > +        libtool \
> > +        net-tools \
> > +        nmap-ncat \
> > +        openssl \
> > +        openssl-devel \
> > +        procps-ng \
> > +        python3-devel \
> > +        python3-pip \
> > +        rpmdevtools \
> > +        rsync \
> > +        selinux-policy-devel \
> > +        tcpdump \
> > +        unbound \
> > +        unbound-devel \
> > +        wget \
> > +        which \
> > +    && \
> > +    dnf clean all
> > +
> > +# Compile sparse from source
> > +WORKDIR /workspace/sparse
> > +
> > +RUN git clone git://git.kernel.org/pub/scm/devel/sparse/sparse.git
> /workspace/sparse \
> > +    && \
> > +    make -j4 PREFIX=/usr HAVE_LLVM= HAVE_SQLITE= install
> > +
> > +WORKDIR /workspace
> > +
> > +# Update and install pip dependencies
> > +RUN python3 -m pip install --upgrade pip \
> > +    && \
> > +    python3 -m pip install wheel \
> > +    && \
> > +    python3 -m pip install flake8 'hacking>=3.0' sphinx setuptools
> pyelftools pyOpenSSL
> > +
>
> The list of python packages to install is the same as in
> .ci/linux-prepare.sh . I wonder if we could extract the python packages
> into a text file and use `pip install -r` in both linux-prepare.sh and
> in the Dockerfile . This way, if we change dependencies, we can update
> the text file instead of having to update the list in multiple places.
> What do you think?
>

That sounds like a good idea, I'll do that in v3.


>
> > +CMD ["/usr/sbin/init"]
>
>
Thanks,
Ales

-- 

Ales Musil

Senior Software Engineer - OVN Core

Red Hat EMEA <https://www.redhat.com>

amu...@redhat.com    IM: amusil
<https://red.ht/sig>
_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to