@@ -9,9 +9,9 @@ RECIPES_REPO=""
99RECIPES_TAG=" "
1010FOREST_NJOBS=" 1"
1111NETRC_FILE=" "
12- TAG=" latest"
13- KERNEL_VER=" "
12+ TAG=" ${TAG:- ${GITHUB_REF_NAME:- latest} } "
1413NO_CACHE=" "
14+ PUSH=" "
1515SNAPSHOT=" "
1616SNAPSHOT_NAME=" $( date +%Y%m%d%H%M) "
1717
@@ -20,17 +20,17 @@ usage() {
2020 cat << EOF
2121Usage: $( basename " $0 " ) [OPTIONS]
2222
23- Build the xbot2 noble Docker images (base -> robot -> rt) using docker buildx bake.
23+ Build the xbot2 noble Docker images (base -> robot -> rt-v5/rt-v6 ) using docker buildx bake.
2424
2525Options:
2626 --user-id ID UID for the 'user' account inside the container (default: current user)
2727 --recipes-repo URL Forest recipes repository URL [required for robot/rt]
2828 --recipes-tag TAG Forest recipes git tag/branch [required for robot/rt]
2929 --forest-njobs N Parallel jobs for forest grow (default: 1)
3030 --netrc PATH Path to a .netrc file for private git clones (build secret)
31- --tag TAG Docker image tag applied to all three images (default: latest)
32- --kernel-ver VER Kernel version passed to Dockerfile-rt as KERNEL_VER
31+ --tag TAG Docker image tag applied to all images (default: TAG, GITHUB_REF_NAME, or latest)
3332 --no-cache Pass --no-cache to docker buildx bake
33+ --push Push images to the registry instead of only loading them locally
3434 --snapshot Run snapshot.bash after a successful build
3535 --snapshot-name NAME Build name subfolder for the snapshot (default: YYYYMMDDHHmm)
3636 -h, --help Show this help message
@@ -46,8 +46,8 @@ while [[ $# -gt 0 ]]; do
4646 --forest-njobs) FOREST_NJOBS=" $2 " ; shift 2 ;;
4747 --netrc) NETRC_FILE=" $2 " ; shift 2 ;;
4848 --tag) TAG=" $2 " ; shift 2 ;;
49- --kernel-ver) KERNEL_VER=" $2 " ; shift 2 ;;
5049 --no-cache) NO_CACHE=" --no-cache" ; shift ;;
50+ --push) PUSH=" 1" ; shift ;;
5151 --snapshot) SNAPSHOT=" 1" ; shift ;;
5252 --snapshot-name) SNAPSHOT_NAME=" $2 " ; shift 2 ;;
5353 -h|--help) usage; exit 0 ;;
@@ -62,7 +62,6 @@ export RECIPES_TAG
6262export FOREST_NJOBS
6363export NETRC_FILE
6464export TAG
65- export KERNEL_VER
6665
6766cd " $DIR "
6867
@@ -71,8 +70,30 @@ if [[ -n "$SNAPSHOT" && "$TAG" == "latest" ]]; then
7170 TAG=" $SNAPSHOT_NAME "
7271fi
7372
74- docker buildx bake --allow=fs.read=$( realpath " $NETRC_FILE " ) -f docker-bake.hcl --load $NO_CACHE
73+ BAKE_ARGS=(-f docker-bake.hcl)
74+ if [[ -n " $NETRC_FILE " ]]; then
75+ BAKE_ARGS=(--allow=fs.read=" $( realpath " $NETRC_FILE " ) " " ${BAKE_ARGS[@]} " )
76+ fi
77+ NO_CACHE_ARGS=()
78+ if [[ -n " $NO_CACHE " ]]; then
79+ NO_CACHE_ARGS+=(" $NO_CACHE " )
80+ fi
7581
7682if [[ -n " $SNAPSHOT " ]]; then
83+ echo " Building images locally with tag: $TAG "
84+ docker buildx bake " ${BAKE_ARGS[@]} " " ${NO_CACHE_ARGS[@]} " --load rt
85+
7786 " $DIR /snapshot.bash" --tag " $TAG " --name " $SNAPSHOT_NAME "
7887fi
88+
89+ if [[ -n " $PUSH " ]]; then
90+ echo " Building and pushing images with tag: $TAG "
91+ PUSH_NO_CACHE_ARGS=()
92+ if [[ -z " $SNAPSHOT " ]]; then
93+ PUSH_NO_CACHE_ARGS=(" ${NO_CACHE_ARGS[@]} " )
94+ fi
95+ docker buildx bake " ${BAKE_ARGS[@]} " " ${PUSH_NO_CACHE_ARGS[@]} " --push rt
96+ elif [[ -z " $SNAPSHOT " ]]; then
97+ echo " Building images locally with tag: $TAG "
98+ docker buildx bake " ${BAKE_ARGS[@]} " " ${NO_CACHE_ARGS[@]} " --load rt
99+ fi
0 commit comments