Skip to content

Commit

Permalink
build: support snapshosts
Browse files Browse the repository at this point in the history
Use special parameters to build an image based on OpenWrt snapshot.
Snapshots can be used to test upcoming changes.
  • Loading branch information
gsanchietti committed Oct 11, 2024
1 parent 9e404ef commit b1cb869
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
15 changes: 13 additions & 2 deletions builder/build-builder
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@

set -e

OWRT_VERSION=$(git describe | cut -d'-' -f1)
# check env variable OWRT_VERSION is set
if [ -z "$OWRT_VERSION" ]; then
OWRT_VERSION=$(git describe | cut -d'-' -f1)
fi

if [ -z "$OWRT_VERSION" ]; then
echo "Missing OWRT_VERSION"
exit 1
fi

repobase="ghcr.io/nethserver"
reponame="nethsecurity-builder"

Expand All @@ -35,7 +39,13 @@ echo "Creating 'build' user"
buildah run ${container} -- useradd -s /bin/bash -m build

echo "Downloading OpenWrt $OWRT_VERSION"
buildah run --user build ${container} -- bash -c "ls /home; cd /home/build && wget https://github.com/openwrt/openwrt/archive/refs/tags/v${OWRT_VERSION}.tar.gz -O openwrt.tgz"
if [ "$OWRT_VERSION" == "snapshot" ]; then
# special value for OWR_VERSION is 'snapshot'
echo "Building SNAPSHOT from main branch"
buildah run --user build ${container} -- bash -c "ls /home; cd /home/build && wget https://github.com/openwrt/openwrt/archive/refs/heads/main.tar.gz -O openwrt.tgz"
else
buildah run --user build ${container} -- bash -c "ls /home; cd /home/build && wget https://github.com/openwrt/openwrt/archive/refs/tags/v${OWRT_VERSION}.tar.gz -O openwrt.tgz"
fi

echo "Extracting OpenWrt image"
buildah run --user build ${container} -- bash -c "cd /home/build && mkdir openwrt && tar xvf openwrt.tgz --strip-components=1 -C openwrt && rm -f openwrt.tgz"
Expand Down Expand Up @@ -69,3 +79,4 @@ buildah add "${container}" ../packages /nspackages
buildah add "${container}" ../patches /patches
buildah config --user build --workingdir /home/build/openwrt --entrypoint='["/entrypoint.sh"]' --cmd='["/make.sh"]' ${container}
buildah commit "${container}" "${repobase}/${reponame}"
build tag "${repobase}/${reponame}" "${repobase}/${reponame}:${OWRT_VERSION}"
15 changes: 14 additions & 1 deletion run
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ fi

# Setup cache volumes
if [ $cache -ge 1 ]; then
opts=" -v nethsecurity-build_dir:/home/build/openwrt/build_dir:z -v nethsecurity-staging_dir:/home/build/openwrt/staging_dir:z -v nethsecurity-ccache:/home/build/openwrt/.ccache -v nethsecurity-download:/home/build/openwrt/download"
vsuffix=""
if [ "$image_tag" == "snapshot" ]; then
vsuffix="_snapshot"
fi
opts=" -v nethsecurity-build_dir$vsuffix:/home/build/openwrt/build_dir:z -v nethsecurity-staging_dir$vsuffix:/home/build/openwrt/staging_dir:z -v nethsecurity-ccache$vsuffix:/home/build/openwrt/.ccache -v nethsecurity-download$vsuffix:/home/build/openwrt/download"
fi

# Download latest image
Expand All @@ -68,6 +72,11 @@ if [ -z "${VERSION}" ]; then
git fetch --prune --unshallow &> /dev/null
VERSION=$(git describe)
fi
# Force snapshot version for snapshot builds
if [ "$image_tag" == "snapshot" ]; then
VERSION="snapshot"
fi

# OWRT_VERSION is like 23.05.2
OWRT_VERSION=$(echo $VERSION | cut -d'-' -f1)
# NS_VERSION is a semver release like '1.0.0' for stable and '1.0.0-alpha1' or '1.0.0-234-g1bc543c' for dev
Expand All @@ -85,6 +94,10 @@ if [ -z "$PRE_RELEASE" ]; then
else
REPO_CHANNEL="dev"
fi
# Force snapshot channel for snapshot builds
if [ "$image_tag" == "snapshot" ]; then
REPO_CHANNEL="snapshot"
fi

export REPO_CHANNEL
export OWRT_VERSION
Expand Down

0 comments on commit b1cb869

Please sign in to comment.