Skip to content

Commit

Permalink
Update BuildKit Configurations to Enhance Compatibility
Browse files Browse the repository at this point in the history
* Add BuildKit cache cleanup in CI
* Declare DOCKER_BUILDKIT when building image for docker compatibility.

fixes #5941

Signed-off-by: Shuyang Xin <[email protected]>
  • Loading branch information
XinShuYang committed Feb 1, 2024
1 parent 5135e06 commit 44ead5e
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions ci/jenkins/test-mc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function clean_images() {
docker images | grep -E 'mc-controller|antrea-ubuntu' | awk '{print $3}' | xargs -r docker rmi -f || true
# Clean up dangling images generated in previous builds.
docker image prune -f --filter "until=24h" || true > /dev/null
check_and_cleanup_docker_build_cache
}

function cleanup_multicluster_ns {
Expand Down
1 change: 1 addition & 0 deletions ci/jenkins/test-rancher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function deliver_antrea {
git show --numstat
make clean
${CLEAN_STALE_IMAGES}
check_and_upgrade_golang
chmod -R g-w build/images/ovs
chmod -R g-w build/images/base
DOCKER_REGISTRY="${DOCKER_REGISTRY}" ./hack/build-antrea-linux-all.sh --pull
Expand Down
1 change: 1 addition & 0 deletions ci/jenkins/test-vmc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ function deliver_antrea {
# because they might be being used in other builds running simultaneously.
docker image prune -af --filter "until=1h" > /dev/null
docker system df -v
check_and_cleanup_docker_build_cache
set -e

cd $GIT_CHECKOUT_DIR
Expand Down
1 change: 1 addition & 0 deletions ci/jenkins/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ function clean_antrea {
done
docker images | grep 'antrea' | awk '{print $3}' | xargs -r docker rmi || true
docker images | grep '<none>' | awk '{print $3}' | xargs -r docker rmi || true
check_and_cleanup_docker_build_cache
}

function clean_for_windows_install_cni {
Expand Down
17 changes: 17 additions & 0 deletions ci/jenkins/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.

function check_and_cleanup_docker_build_cache() {
free_space=$(df -h -B 1G / | awk 'NR==2 {print $4}')
free_space_threshold=40
if [[ $free_space -lt $free_space_threshold ]]; then
# If cleaning up unused dangling images doesn't free up sufficient disk space,
# we will have to reduce the builder cache to 10GB to release enough disk space.
docker builder prune -af --keep-storage=10gb > /dev/null
free_space=$(df -h -B 1G / | awk 'NR==2 {print $4}')
if [[ $free_space -lt $free_space_threshold ]]; then
# If the first round cleanup doesn't free up sufficient disk space,
# we will have to clean up all builder cache to release enough disk space.
docker builder prune -af > /dev/null
fi
fi
docker system df -v
}

function check_and_upgrade_golang() {
if [ -z "${GOLANG_RELEASE_DIR}" ]; then
GOLANG_RELEASE_DIR="/var/lib/jenkins/golang-releases"
Expand Down
4 changes: 3 additions & 1 deletion ci/test-conformance-aks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,12 @@ function deliver_antrea_to_aks() {
# because they might be being used in other builds running simultaneously.
docker image prune -f --filter "until=2h" > /dev/null
docker system df -v
check_and_cleanup_docker_build_cache

set -e

cd ${GIT_CHECKOUT_DIR}
VERSION="$CLUSTER" make
VERSION="$CLUSTER" ./hack/build-antrea-linux-all.sh --pull
if [[ "$?" -ne "0" ]]; then
echo "=== Antrea Image build failed ==="
exit 1
Expand Down
3 changes: 2 additions & 1 deletion ci/test-conformance-eks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,11 @@ function deliver_antrea_to_eks() {
# because they might be being used in other builds running simultaneously.
docker image prune -f --filter "until=2h" > /dev/null
docker system df -v
check_and_cleanup_docker_build_cache
set -e

cd ${GIT_CHECKOUT_DIR}
VERSION="$CLUSTER" make
VERSION="$CLUSTER" ./hack/build-antrea-linux-all.sh --pull
if [[ "$?" -ne "0" ]]; then
echo "=== Antrea Image build failed ==="
exit 1
Expand Down
3 changes: 2 additions & 1 deletion ci/test-conformance-gke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ function deliver_antrea_to_gke() {
# because they might be being used in other builds running simultaneously.
docker image prune -f --filter "until=2h" > /dev/null
docker system df -v
check_and_cleanup_docker_build_cache
set -e

cd ${GIT_CHECKOUT_DIR}
VERSION="$CLUSTER" make -C ${GIT_CHECKOUT_DIR}
VERSION="$CLUSTER" ./hack/build-antrea-linux-all.sh --pull
if [[ "$?" -ne "0" ]]; then
echo "=== Antrea Image build failed ==="
exit 1
Expand Down
2 changes: 1 addition & 1 deletion docs/minikube.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ minikube start --cni=antrea.yml --network-plugin=cni

These instructions assume that you have built the Antrea Docker image locally
(e.g. by running `make` from the root of the repository, or in case of arm64 architecture by running
`DOCKER_BUILDKIT=1 ./hack/build-antrea-ubuntu-all.sh --platform linux/arm64`).
`./hack/build-antrea-linux-all.sh --platform linux/arm64`).

```bash
# load the Antrea Docker image in the minikube nodes
Expand Down
1 change: 1 addition & 0 deletions hack/build-antrea-linux-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ cd build/images/base
cd -

export NO_PULL=1
export DOCKER_BUILDKIT=1
if [ "$DISTRO" == "ubuntu" ]; then
if $COVERAGE; then
make build-controller-ubuntu-coverage
Expand Down

0 comments on commit 44ead5e

Please sign in to comment.