1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
#!/bin/bash
# Copyright (C) 2017 SUSE LLC.
# Copyright (C) 2017-2021 Open Containers Authors
#
# 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.
set -e
## --->
# Project-specific options and functions. In *theory* you shouldn't need to
# touch anything else in this script in order to use this elsewhere.
: "${LIBSECCOMP_VERSION:=2.5.5}"
project="runc"
root="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")"
# shellcheck source=./script/lib.sh
source "$root/script/lib.sh"
# This function takes an output path as an argument, where the built
# (preferably static) binary should be placed.
# Parameters:
# $1 -- destination directory to place build artefacts to.
# $2 -- native architecture (a .suffix for a native binary file name).
# $@ -- additional architectures to cross-build for.
function build_project() {
local builddir
builddir="$(dirname "$1")"
shift
local native_arch="$1"
shift
local arches=("$@")
# Assume that if /opt/libseccomp exists, then we are run
# via Dockerfile, and seccomp is already built.
local seccompdir=/opt/libseccomp temp_dir
if [ ! -d "$seccompdir" ]; then
temp_dir="$(mktemp -d)"
seccompdir="$temp_dir"
# Download and build libseccomp.
"$root/script/seccomp.sh" "$LIBSECCOMP_VERSION" "$seccompdir" "${arches[@]}"
fi
# For reproducible builds, add these to EXTRA_LDFLAGS:
# -w to disable DWARF generation;
# -s to disable symbol table;
# -buildid= to remove variable build id.
local ldflags="-w -s -buildid="
# Add -a to go build flags to make sure it links against
# the provided libseccomp, not the system one (otherwise
# it can reuse cached pkg-config results).
local make_args=(COMMIT_NO= EXTRA_FLAGS="-a" EXTRA_LDFLAGS="${ldflags}" static)
# Build natively.
make -C "$root" \
PKG_CONFIG_PATH="$seccompdir/lib/pkgconfig" \
"${make_args[@]}"
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"
# Cross-build for for other architectures.
local arch
for arch in "${arches[@]}"; do
set_cross_vars "$arch"
make -C "$root" \
PKG_CONFIG_PATH="$seccompdir/$arch/lib/pkgconfig" \
"${make_args[@]}"
"$STRIP" "$root/$project"
mv "$root/$project" "$builddir/$project.$arch"
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.
## <---
# Print usage information.
function usage() {
echo "usage: release_build.sh [-a <cross-arch>]... [-c <commit-ish>] [-H <hashcmd>]" >&2
echo " [-r <release-dir>] [-v <version>]" >&2
exit 1
}
# Log something to stderr.
function log() {
echo "[*] $*" >&2
}
# Log something to stderr and then exit with 0.
function bail() {
log "$@"
exit 0
}
# When creating releases we need to build static binaries, an archive of the
# current commit, and generate detached signatures for both.
commit="HEAD"
version=""
releasedir=""
hashcmd=""
declare -a add_arches
while getopts "a:c:H:hr:v:" opt; do
case "$opt" in
a)
add_arches+=("$OPTARG")
;;
c)
commit="$OPTARG"
;;
H)
hashcmd="$OPTARG"
;;
h)
usage
;;
r)
releasedir="$OPTARG"
;;
v)
version="$OPTARG"
;;
:)
echo "Missing argument: -$OPTARG" >&2
usage
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
esac
done
version="${version:-$(<"$root/VERSION")}"
releasedir="${releasedir:-release/$version}"
hashcmd="${hashcmd:-sha256sum}"
native_arch="$(go env GOARCH || echo "amd64")"
# Suffixes of files to checksum/sign.
suffixes=("$native_arch" "${add_arches[@]}" tar.xz)
log "creating $project release in '$releasedir'"
log " version: $version"
log " commit: $commit"
log " hash: $hashcmd"
# Make explicit what we're doing.
set -x
# Make the release directory.
rm -rf "$releasedir" && mkdir -p "$releasedir"
# Build project.
build_project "$releasedir/$project" "$native_arch" "${add_arches[@]}"
# Generate new archive.
git archive --format=tar --prefix="$project-$version/" "$commit" | xz >"$releasedir/$project.tar.xz"
# Generate sha256 checksums for binaries and libseccomp tarball.
(
cd "$releasedir"
# Add $project. prefix to all suffixes.
"$hashcmd" "${suffixes[@]/#/$project.}" >"$project.$hashcmd"
)
|