Skip to content

Commit

Permalink
Refactor Dockerfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
gab-arrobo committed Mar 9, 2024
1 parent a64a011 commit 42a8f5a
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 61 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,37 @@ jobs:
config_path: .spellcheck.yml
task_name: Markdown

hadolint:
name: hadolint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Dockerfile linter
uses: hadolint/[email protected]
# For now, ignoring:
# DL3008 warning: Pin versions in apt get install (e.g., apt-get install <package>=<version>)
with:
dockerfile: env/Dockerfile
ignore: DL3008

hadolint-cndp:
name: hadolint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Dockerfile linter
uses: hadolint/[email protected]
# For now, ignoring:
# DL3008 warning: Pin versions in apt get install (e.g., apt-get install <package>=<version>); and
# DL3013 warning: Pin versions in pip (e.g., pip install <package>==<version>)
with:
dockerfile: env/Dockerfile-cndp
ignore: DL3008,DL3013

license-check:
runs-on: ubuntu-latest
steps:
Expand Down
55 changes: 28 additions & 27 deletions env/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2020-present Open Networking Foundation
# Copyright 2019 Intel Corporation
# Copyright 2019-present Intel Corporation
# vim: syntax=dockerfile

ARG BASE_IMAGE=ubuntu:focal
# Install CNDP dependencies and build CNDP.
FROM ${BASE_IMAGE} AS cndp-build
FROM ubuntu:20.04 AS cndp-build

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
--no-install-recommends \
ca-certificates \
build-essential \
golang \
libelf-dev \
Expand All @@ -31,16 +32,16 @@ RUN apt-get update && apt-get install -y \
lld \
m4 \
linux-tools-common \
libbpf-dev \
&& rm -rf /var/lib/apt/lists/*
libbpf-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install libxdp
RUN git clone https://github.com/xdp-project/xdp-tools.git
WORKDIR /xdp-tools/
RUN git checkout v1.2.2
RUN ./configure
WORKDIR /xdp-tools/
RUN make -j; PREFIX=/usr make -j install
WORKDIR /xdp-tools
RUN git clone https://github.com/xdp-project/xdp-tools.git . && \
git checkout v1.2.2 && \
./configure && \
make -j; PREFIX=/usr make -j install
ENV PKG_CONFIG_PATH=/usr/lib/pkgconfig

# Get CNDP from GitHub
Expand All @@ -55,14 +56,15 @@ RUN make && make install
RUN make static_build=1 rebuild install

# Build the prometheus-metrics app
WORKDIR /cndp/lang/go/stats/prometheus/
WORKDIR /cndp/lang/go/stats/prometheus
RUN go build prometheus.go

FROM ${BASE_IMAGE}
FROM ubuntu:20.04

# Install CNDP dependencies
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
--no-install-recommends \
build-essential \
ethtool \
libbsd-dev \
Expand All @@ -73,7 +75,9 @@ RUN apt-get update && apt-get install -y \
libnl-cli-3-dev \
libnuma1 \
libpcap0.8 \
pkg-config
pkg-config && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Copy required CNDP libraries, header files, pkg-config and binaries.
COPY --from=cndp-build /cndp/usr/local/bin/cndpfwd /usr/bin/
Expand All @@ -88,24 +92,21 @@ COPY --from=cndp-build /usr/include/xdp/ /usr/include/xdp/
# Set CNDP PKG_CONFIG_PATH
ENV PKG_CONFIG_PATH=/usr/lib64/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig

RUN echo "APT::Install-Recommends false;" >> /etc/apt/apt.conf.d/00recommends && \
echo "APT::Install-Suggests false;" >> /etc/apt/apt.conf.d/00recommends && \
echo "APT::AutoRemove::RecommendsImportant false;" >> /etc/apt/apt.conf.d/00recommends && \
echo "APT::AutoRemove::SuggestsImportant false;" >> /etc/apt/apt.conf.d/00recommends

COPY env/build-dep.yml /tmp/
COPY env/kmod.yml /tmp/
COPY env/ci.yml /tmp/

# Install dependency packages with Ansible
RUN apt-get -q update && \
apt-get install -y ansible curl && \
ansible-playbook /tmp/ci.yml -i "localhost," -c local && \
apt-get purge -y ansible && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists
RUN update-alternatives --install /usr/local/bin/python python /usr/bin/python3 3
RUN mkdir -p /build/bess
RUN apt-get update && \
apt-get install -y \
--no-install-recommends \
ansible \
curl && \
ansible-playbook /tmp/ci.yml -i "localhost," -c local && \
apt-get purge -y ansible && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

WORKDIR /build/bess
COPY . .
Expand Down
77 changes: 43 additions & 34 deletions env/Dockerfile-cndp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2020-2022 Intel Corporation
# Copyright (c) 2020-present Intel Corporation
#
# vim: syntax=dockerfile

Expand All @@ -8,12 +8,13 @@
# --build-arg https_proxy=$http_proxy --build-arg no_proxy="$no_proxy" \
# -t besscndp -f env/Dockerfile-cndp .

ARG BASE_IMAGE=ubuntu:focal
FROM ${BASE_IMAGE} AS cndp-build
FROM ubuntu:20.04 AS cndp-build

# Install CNDP dependencies and build CNDP.
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
--no-install-recommends \
ca-certificates \
build-essential \
golang \
libelf-dev \
Expand All @@ -36,16 +37,16 @@ RUN apt-get update && apt-get install -y \
lld \
m4 \
linux-tools-common \
libbpf-dev \
&& rm -rf /var/lib/apt/lists/*
libbpf-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install libxdp
RUN git clone https://github.com/xdp-project/xdp-tools.git
WORKDIR /xdp-tools/
RUN git checkout v1.2.2
RUN ./configure
WORKDIR /xdp-tools/
RUN make -j; PREFIX=/usr make -j install
WORKDIR /xdp-tools
RUN git clone https://github.com/xdp-project/xdp-tools.git . && \
git checkout v1.2.2 && \
./configure && \
make -j; PREFIX=/usr make -j install
ENV PKG_CONFIG_PATH=/usr/lib/pkgconfig

# Get CNDP from GitHub
Expand All @@ -60,14 +61,15 @@ RUN make && make install
RUN make static_build=1 rebuild install

# Build the prometheus-metrics app
WORKDIR /cndp/lang/go/stats/prometheus/
WORKDIR /cndp/lang/go/stats/prometheus
RUN go build prometheus.go

FROM ${BASE_IMAGE}
FROM ubuntu:20.04

# Install CNDP dependencies
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
--no-install-recommends \
build-essential \
ethtool \
libbsd-dev \
Expand All @@ -78,7 +80,9 @@ RUN apt-get update && apt-get install -y \
libnl-cli-3-dev \
libnuma1 \
libpcap0.8 \
pkg-config
pkg-config && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Copy required CNDP libraries, header files, pkg-config and binaries.
COPY --from=cndp-build /cndp/usr/local/bin/cndpfwd /usr/bin/
Expand All @@ -93,28 +97,35 @@ COPY --from=cndp-build /usr/include/xdp/ /usr/include/xdp/
# Set CNDP PKG_CONFIG_PATH
ENV PKG_CONFIG_PATH=/usr/lib64/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig

# Install BESS
RUN echo "APT::Install-Recommends false;" >> /etc/apt/apt.conf.d/00recommends && \
echo "APT::Install-Suggests false;" >> /etc/apt/apt.conf.d/00recommends && \
echo "APT::AutoRemove::RecommendsImportant false;" >> /etc/apt/apt.conf.d/00recommends && \
echo "APT::AutoRemove::SuggestsImportant false;" >> /etc/apt/apt.conf.d/00recommends

COPY env/build-dep.yml /tmp/
COPY env/kmod.yml /tmp/
COPY env/ci.yml /tmp/

# Install dependency packages with Ansible
RUN apt-get -q update && \
apt-get install -y ansible curl git sudo libgraph-easy-perl python-is-python3 && \
ansible-playbook /tmp/ci.yml -i "localhost," -c local && \
apt-get purge -y ansible && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists
RUN python3 -m pip install --upgrade pip && python3 -m pip install grpcio scapy protobuf==3.20.0 flask pyroute2

RUN mkdir -p /build/bess
RUN mkdir -p /build/bess/log
RUN apt-get update && \
apt-get install -y \
--no-install-recommends \
ansible \
curl \
git \
sudo \
libgraph-easy-perl \
python-is-python3 && \
ansible-playbook /tmp/ci.yml -i "localhost," -c local && \
apt-get purge -y ansible && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN python3 -m pip install --no-cache-dir --upgrade pip && \
python3 -m pip install --no-cache-dir \
grpcio \
scapy \
protobuf==3.20.0 \
flask \
pyroute2

RUN mkdir -p /build/bess/log

# Copy required files and build bess
WORKDIR /build/bess
Expand All @@ -127,10 +138,8 @@ COPY protobuf protobuf
COPY pybess pybess
COPY sample_plugin sample_plugin
COPY build.py container_build.py install_git_hooks.sh ./
RUN ./build.py bess
RUN cp /build/bess/deps/dpdk-22.11.4/build/app/dpdk-testpmd /usr/local/bin/
RUN ./build.py bess && \
cp /build/bess/deps/dpdk-22.11.4/build/app/dpdk-testpmd /usr/local/bin/

ENV CCACHE_DIR=/tmp/ccache
ENV CCACHE_COMPRESS=true

WORKDIR /build/bess

0 comments on commit 42a8f5a

Please sign in to comment.