Dockerfile: fix for seccomp

Commit f30244ee1b broke the scenario of using Dockefile for
anything but making a release. This happened because it installed
native libseccomp build to a temporary directory, and so linking against
libseccomp required setting a few environment variables.

Let's fix this, and simplify libseccomp installation. Instead of using
temporary directories, let's install native libseccomp to a specified
directory, all the cross-builds to its subdirectories, and set
PKG_CONFIG_PATH and LD_LIBRARY_PATH in Dockerfile so that the built
library will found by pkg-config and the dynamic linker (without setting
LD_LIBRARY_PATH, ld picks up distro-provided libseccomp.so).

While at it, fix some bugs introduced by the abovementioned commit.

This fixes building runc in  make targets like shell, dbuild,
integration, unittest -- i.e. those that depend on runcimage.

Fixes: f30244ee1b
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2021-09-29 12:47:57 -07:00
parent d1c9b43e94
commit f95063ede4
3 changed files with 46 additions and 43 deletions
+5 -2
View File
@@ -53,7 +53,10 @@ RUN cd /tmp \
# install libseccomp # install libseccomp
ARG LIBSECCOMP_VERSION ARG LIBSECCOMP_VERSION
COPY script/* /tmp/script/ COPY script/* /tmp/script/
RUN mkdir -p /usr/local/src/libseccomp \ RUN mkdir -p /opt/libseccomp \
&& /tmp/script/seccomp.sh "$LIBSECCOMP_VERSION" /usr/local/src/libseccomp /usr/local/src/libseccomp/.env-file arm64 armel armhf ppc64le && /tmp/script/seccomp.sh "$LIBSECCOMP_VERSION" /opt/libseccomp arm64 armel armhf ppc64le
ENV LIBSECCOMP_VERSION=$LIBSECCOMP_VERSION
ENV LD_LIBRARY_PATH=/opt/libseccomp/lib
ENV PKG_CONFIG_PATH=/opt/libseccomp/lib/pkgconfig
WORKDIR /go/src/github.com/opencontainers/runc WORKDIR /go/src/github.com/opencontainers/runc
+29 -23
View File
@@ -18,6 +18,7 @@ set -e
## ---> ## --->
# Project-specific options and functions. In *theory* you shouldn't need to # Project-specific options and functions. In *theory* you shouldn't need to
# touch anything else in this script in order to use this elsewhere. # touch anything else in this script in order to use this elsewhere.
: "${LIBSECCOMP_VERSION:=2.5.2}"
project="runc" project="runc"
root="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")" root="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")"
@@ -31,7 +32,6 @@ source "$root/script/lib.sh"
# $2 -- native architecture (a .suffix for a native binary file name). # $2 -- native architecture (a .suffix for a native binary file name).
# $@ -- additional architectures to cross-build for. # $@ -- additional architectures to cross-build for.
function build_project() { function build_project() {
local libseccomp_version=2.5.2
local builddir local builddir
builddir="$(dirname "$1")" builddir="$(dirname "$1")"
shift shift
@@ -39,17 +39,14 @@ function build_project() {
shift shift
local arches=("$@") local arches=("$@")
# Assume that if /usr/local/src/libseccomp/.env-file exists, then # Assume that if /opt/libseccomp exists, then we are run
# we are run via Dockerfile, and seccomp is already built. # via Dockerfile, and seccomp is already built.
if [ -r /usr/local/src/libseccomp/.env-file ]; then local seccompdir=/opt/libseccomp temp_dir
# shellcheck disable=SC1091 if [ ! -d "$seccompdir" ]; then
source /usr/local/src/libseccomp/.env-file temp_dir="$(mktemp -d)"
# Copy the source tarball. seccompdir="$temp_dir"
cp /usr/local/src/libseccomp/* "$builddir" # Download and build libseccomp.
else "$root/script/seccomp.sh" "$LIBSECCOMP_VERSION" "$seccompdir" "${arches[@]}"
"$root/script/seccomp.sh" "$libseccomp_version" "$builddir" "./env-file" "${arches[@]}"
# shellcheck disable=SC1091
source ./env-file
fi fi
# For reproducible builds, add these to EXTRA_LDFLAGS: # For reproducible builds, add these to EXTRA_LDFLAGS:
@@ -64,28 +61,37 @@ function build_project() {
# Build natively. # Build natively.
make -C "$root" \ make -C "$root" \
PKG_CONFIG_PATH="${LIBSECCOMP_PREFIX}/lib/pkgconfig" \ PKG_CONFIG_PATH="$seccompdir/lib/pkgconfig" \
LD_LIBRARY_PATH="${LIBSECCOMP_PREFIX}/lib" \
"${make_args[@]}" "${make_args[@]}"
strip "$root/$project" strip "$root/$project"
# Sanity check: make sure libseccomp version is as expected.
local ver
ver=$("$root/$project" --version | awk '$1 == "libseccomp:" {print $2}')
if [ "$ver" != "$LIBSECCOMP_VERSION" ]; then
echo >&2 "libseccomp version mismatch: want $LIBSECCOMP_VERSION, got $ver"
exit 1
fi
mv "$root/$project" "$builddir/$project.$native_arch" mv "$root/$project" "$builddir/$project.$native_arch"
rm -rf "${LIBSECCOMP_PREFIX}"
# Cross-build for for other architectures. # Cross-build for for other architectures.
local prefix arch local arch
for arch in "${arches[@]}"; do for arch in "${arches[@]}"; do
eval prefix=\$"LIBSECCOMP_PREFIX_$arch"
if [ -z "$prefix" ]; then
echo "LIBSECCOMP_PREFIX_$arch is empty (unsupported arch?)" >&2
exit 1
fi
set_cross_vars "$arch" set_cross_vars "$arch"
make -C "$root" \ make -C "$root" \
PKG_CONFIG_PATH="${prefix}/lib/pkgconfig" "${make_args[@]}" PKG_CONFIG_PATH="$seccompdir/$arch/lib/pkgconfig" \
"${make_args[@]}"
"$STRIP" "$root/$project" "$STRIP" "$root/$project"
mv "$root/$project" "$builddir/$project.$arch" mv "$root/$project" "$builddir/$project.$arch"
rm -rf "$prefix"
done done
# Copy libseccomp source tarball.
cp "$seccompdir"/src/* "$builddir"
# Clean up.
if [ -n "$tempdir" ]; then
rm -rf "$tempdir"
fi
} }
# End of the easy-to-configure portion. # End of the easy-to-configure portion.
+12 -18
View File
@@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
set -e -u -o pipefail
# shellcheck source=./script/lib.sh # shellcheck source=./script/lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
@@ -7,17 +9,13 @@ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
# so download, install and build against it. # so download, install and build against it.
# Parameters: # Parameters:
# $1 -- libseccomp version to download and build. # $1 -- libseccomp version to download and build.
# $2 -- destination directory to put the source tarball in. # $2 -- destination directory.
# $3 -- file to append LIBSECCOMP_PREFIX*= environment variables to
# (can be sourced to get install paths).
# $@ -- additional architectures to cross-compile for. # $@ -- additional architectures to cross-compile for.
function build_libseccomp() { function build_libseccomp() {
local ver="$1" local ver="$1"
shift shift
local dest="$1" local dest="$1"
shift shift
local varfile="$1"
shift
local arches=("$@") local arches=("$@")
local tar="libseccomp-${ver}.tar.gz" local tar="libseccomp-${ver}.tar.gz"
@@ -28,36 +26,32 @@ function build_libseccomp() {
tar xf "$tar" -C "$srcdir" tar xf "$tar" -C "$srcdir"
pushd "$srcdir/libseccomp-$ver" || return pushd "$srcdir/libseccomp-$ver" || return
# Build and install natively. # Build natively and install to /usr/local.
local prefix
prefix="$(mktemp -d)"
./configure \ ./configure \
--prefix="$prefix" --libdir="$prefix/lib" \ --prefix="$dest" --libdir="$dest/lib" \
--enable-static --disable-shared --enable-static --enable-shared
echo LIBSECCOMP_PREFIX="$prefix" >>"$varfile"
make install make install
make clean make clean
# Build and install for additional architectures. # Build and install for additional architectures.
local arch local arch
for arch in "${arches[@]}"; do for arch in "${arches[@]}"; do
prefix="$(mktemp -d)"
set_cross_vars "$arch" set_cross_vars "$arch"
./configure --host "$HOST" \ ./configure --host "$HOST" \
--prefix="$prefix" --libdir="$prefix/lib" \ --prefix="$dest/$arch" --libdir="$dest/$arch/lib" \
--enable-static --enable-shared --enable-static --enable-shared
make install make install
make clean make clean
echo "LIBSECCOMP_PREFIX_${arch}=$prefix" >>"$varfile"
done done
# Place the source tarball to $dest. # Place the source tarball to $dest/src.
popd || return popd || return
mv "$tar"{,.asc} "$dest" mkdir "$dest"/src
mv "$tar"{,.asc} "$dest"/src
} }
if $# -lt 4; then if [ $# -lt 4 ]; then
echo "Usage: seccomp.sh <version> <dest-dir> <var-file> [<extra-arch> ...]" >&2 echo "Usage: seccomp.sh <version> <dest-dir> [<extra-arch> ...]" >&2
exit 1 exit 1
fi fi