Skip to content

Commit aa9927a

Browse files
committed
build_dev_binpkgs: Ensure adevcontainer binpkgs are built
This change introduces build_dev_binpkgs, a script to build binary packages for all dependencies of the devcontainer. This works around an issue with build_packages, which doesn't - leading to build issues with the devcontainer later on. This particularly happens for more complex builds with the devcontainer. Additionally, a call to build_dev_binpkgs has been added to the package publishing step in ci-automation before binary packages are published. Signed-off-by: Thilo Fromm <thilofromm@microsoft.com>
1 parent fe28bd9 commit aa9927a

File tree

2 files changed

+100
-2
lines changed

2 files changed

+100
-2
lines changed

build_dev_binpkgs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
# Copyright (c) 2023 by the Flatcar Maintainers.
3+
# Use of this source code is governed by the Apache 2.0 license.
4+
5+
. "$(dirname "$0")/common.sh" || exit 1
6+
7+
# Script must run inside the chroot
8+
assert_inside_chroot
9+
assert_not_root_user
10+
11+
# Dependencies and packages to include by default.
12+
packages_default=( "coreos-devel/board-packages" )
13+
14+
# Packages that are rdeps of the above but should not be included.
15+
# (mostly large packages, e.g. programming languages etc.)
16+
skip_packages_default="dev-lang/rust,virtual/rust,dev-lang/go,dev-lang/go-bootstrap,dev-go/go-md2man"
17+
18+
19+
# Developer-visible flags.
20+
DEFINE_string board "${DEFAULT_BOARD}" \
21+
"The board to build packages for."
22+
DEFINE_string skip_packages "${skip_packages_default[@]}" \
23+
"Comma-separated list of packages in the dependency tree to skip."
24+
DEFINE_boolean pretend "${FLAGS_FALSE}" \
25+
"List packages that would be built but do not actually build."
26+
27+
FLAGS_HELP="usage: $(basename $0) [flags] [packages]
28+
29+
build_dev_binpkgs builds binary packages for all dependencies of [packages]
30+
that are not present in '/build/<board>/var/lib/portage/pkgs/'.
31+
Useful for publishing a complete set of packages to a binhost.
32+
33+
[packages] defaults to '${packages_default}' if not specified.
34+
"
35+
36+
# Parse command line
37+
FLAGS "$@" || exit 1
38+
eval set -- "${FLAGS_ARGV}"
39+
40+
# Die on any errors.
41+
switch_to_strict_mode
42+
43+
if [[ $# -eq 0 ]]; then
44+
set -- "${packages_default[@]}"
45+
fi
46+
# --
47+
48+
function my_board_emerge() {
49+
export PORTAGE_CONFIGROOT="/build/${FLAGS_board}"
50+
export SYSROOT="${SYSROOT:-/build/${FLAGS_board}}"
51+
export ROOT="/build/${FLAGS_board}"
52+
sudo -E emerge --root-deps=rdeps "${@}"
53+
}
54+
# --
55+
56+
pkg_build_list="$(mktemp)"
57+
pkg_skipped_list="${pkg_build_list}-skip"
58+
trap 'rm -f "${pkg_build_list}" "${pkg_skipped_list}"' EXIT
59+
60+
info "Collecting list of binpkgs to build"
61+
62+
my_board_emerge --pretend --root-deps=rdeps --emptytree ${@} \
63+
| grep '\[ebuild' \
64+
| sed 's/^\[[^]]\+\] \([^ :]\+\)*:.*/\1/' \
65+
| while read pkg; do
66+
if [ -f "/build/${FLAGS_board}/var/lib/portage/pkgs/${pkg}.tbz2" ] ; then
67+
continue
68+
fi
69+
skip=""
70+
for s in ${FLAGS_skip_packages//,/ }; do
71+
if [[ ${pkg} = ${s}-* ]] ; then
72+
echo -n "${pkg} " >> "${pkg_skipped_list}"
73+
skip="true"
74+
break
75+
fi
76+
done
77+
[[ -z ${skip} ]] || continue
78+
echo "=${pkg}" | tee -a "${pkg_build_list}" | sed 's/^/ /'
79+
done
80+
# --
81+
82+
if [ -f "${pkg_skipped_list}" ] ; then
83+
info "Skipping binpkgs '$(cat "${pkg_skipped_list}")' because these are in the skip list."
84+
fi
85+
86+
pretend=""
87+
if [[ "${FLAGS_pretend}" -eq "${FLAGS_TRUE}" ]]; then
88+
pretend="--pretend"
89+
fi
90+
91+
my_board_emerge --buildpkg ${pretend} $(cat "${pkg_build_list}")

ci-automation/push_pkgs.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
# This script will publish the packages from a pre-built packages container to
1313
# the buildcache server, effectively turning the build cache into a
1414
# binary packages server for the SDK.
15+
# Before pushing packages the script will run ./build_dev_binpkgs to ensure all
16+
# binary packages for the development container are actually built.
17+
# Note that this may build packages not previously built by the "build_packages"
18+
# step.
1519
#
1620
# PREREQUISITES:
1721
#
@@ -88,11 +92,14 @@ function _push_packages_impl() {
8892

8993
docker_image_from_buildcache "${packages}" "${docker_vernum}"
9094

95+
local my_name="flatcar-packages-publisher-${arch}-${docker_vernum}"
96+
./run_sdk_container -x ./ci-cleanup.sh -n "${my_name}" -C "${packages_image}" \
97+
./build_dev_binpkgs --board="${arch}-usr"
98+
9199
local cmd="source ci-automation/push_pkgs.sh"
92100
cmd="$cmd; image_build__copy_to_bincache '$arch' '$vernum'"
93101

94-
local my_name="flatcar-packages-publisher-${arch}-${docker_vernum}"
95-
./run_sdk_container -x ./ci-cleanup.sh -n "${my_name}" -C "${packages_image}" \
102+
./run_sdk_container -x ./ci-cleanup.sh -n "${my_name}" \
96103
bash -c "$cmd"
97104
}
98105
# --

0 commit comments

Comments
 (0)