Skip to content

Commit

Permalink
chore: versions of dependent packages are centrally managed in longho…
Browse files Browse the repository at this point in the history
…rn/dep-versions

Longhorn 10208

Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit committed Feb 4, 2025
1 parent 7e40dd0 commit 214e7f3
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 9 deletions.
25 changes: 18 additions & 7 deletions package/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

FROM registry.suse.com/bci/bci-base:15.6 AS build

ARG DEP_VERSION_FILE=versions.json

RUN zypper -n ref && \
zypper update -y

Expand All @@ -14,14 +16,21 @@ RUN zypper -n addrepo --refresh https://download.opensuse.org/repositories/syste

RUN zypper -n install autoconf bison curl cmake doxygen make git gcc14 gcc14-c++ flex Mesa-libGL-devel libdbus-1-3 \
nfsidmap-devel liburcu-devel libblkid-devel e2fsprogs e2fsprogs-devel xfsprogs xfsprogs-devel \
tar gzip dbus-1-devel lsb-release graphviz-devel libnsl-devel libcurl-devel libjson-c-devel libacl-devel && \
tar gzip dbus-1-devel lsb-release graphviz-devel libnsl-devel libcurl-devel libjson-c-devel libacl-devel jq && \
rm -rf /var/cache/zypp/*

RUN curl -L https://github.com/rancher/nfs-ganesha/archive/refs/tags/v6_20250113.tar.gz | tar zx \
&& curl -L https://github.com/nfs-ganesha/ntirpc/archive/refs/tags/v6.3.tar.gz | tar zx \
&& mv nfs-ganesha-6_20250113 nfs-ganesha \
&& rm -r nfs-ganesha/src/libntirpc \
&& mv ntirpc-6.3 nfs-ganesha/src/libntirpc
COPY ${DEP_VERSION_FILE} /versions.json

RUN export NFS_GANESHA_REPO=$(jq -r '.["nfs-ganesha"].repo' /versions.json) && \
export NFS_GANESHA_COMMIT_ID=$(jq -r '.["nfs-ganesha"].commit' /versions.json) && \
export NTIRPC_REPO=$(jq -r '.["ntirpc"].repo' /versions.json) && \
export NTIRPC_COMMIT_ID=$(jq -r '.["ntirpc"].commit' /versions.json) && \
git clone ${NFS_GANESHA_REPO} /nfs-ganesha && \
git -C /nfs-ganesha checkout ${NFS_GANESHA_COMMIT_ID} && \
rm -r /nfs-ganesha/src/libntirpc && \
git clone ${NTIRPC_REPO} /nfs-ganesha/src/libntirpc && \
git -C /nfs-ganesha/src/libntirpc checkout ${NTIRPC_COMMIT_ID}

WORKDIR /nfs-ganesha

# build ganesha only supporting nfsv4 and vfs
Expand All @@ -43,6 +52,7 @@ RUN mkdir -p /ganesha-extra \
&& mkdir -p /ganesha-extra/etc/dbus-1/system.d \
&& cp src/scripts/ganeshactl/org.ganesha.nfsd.conf /ganesha-extra/etc/dbus-1/system.d/


FROM registry.suse.com/bci/bci-base:15.6

ARG TARGETPLATFORM
Expand All @@ -59,7 +69,8 @@ RUN zypper addrepo --refresh https://download.opensuse.org/repositories/system:/
zypper --gpg-auto-import-keys ref

# RUN microdnf install -y nano tar lsof e2fsprogs fuse-libs libss libblkid userspace-rcu dbus-x11 rpcbind hostname nfs-utils xfsprogs jemalloc libnfsidmap && microdnf clean all
RUN zypper -n install rpcbind hostname libblkid1 liburcu6 libjson-c* dbus-1-x11 dbus-1 nfsidmap-devel nfs-kernel-server nfs-client nfs4-acl-tools xfsprogs e2fsprogs awk && \
RUN zypper -n install rpcbind hostname libblkid1 liburcu6 libjson-c* dbus-1-x11 dbus-1 nfsidmap-devel \

Check warning on line 72 in package/Dockerfile

View check run for this annotation

codefactor.io / CodeFactor

package/Dockerfile#L72

Specify version with `zypper install -y <package>=<version>`. (DL3037)

Check warning on line 72 in package/Dockerfile

View check run for this annotation

codefactor.io / CodeFactor

package/Dockerfile#L72

`zypper clean` missing after zypper use. (DL3036)
nfs-kernel-server nfs-client nfs4-acl-tools xfsprogs e2fsprogs awk && \
rm -rf /var/cache/zypp/*

RUN mkdir -p /var/run/dbus && mkdir -p /export
Expand Down
57 changes: 55 additions & 2 deletions scripts/package
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,69 @@ fi

cp -r bin package/

APIVERSION=`./bin/longhorn-share-manager version --client-only|jq ".clientVersion.apiVersion"`
#APIVERSION=`./bin/longhorn-share-manager version --client-only|jq ".clientVersion.apiVersion"`

# Try bin/longhorn-share-manager-amd64 and bin/longhorn-share-manager-arm64 doesn't have "Exec format error"
# if it is not "Exec format error", use it to get the version
#APIVERSION=`./bin/longhorn-share-manager version --client-only|jq ".clientVersion.apiVersion"`

APIVERSION=""
arch=$(uname -m)
if [ "$arch" == "aarch64" ]; then
ARCH="arm64"
else
ARCH="amd64"
fi
APIVERSION=`./bin/longhorn-share-manager-"$ARCH" version --client-only|jq ".clientVersion.apiVersion"`

Check notice on line 29 in scripts/package

View check run for this annotation

codefactor.io / CodeFactor

scripts/package#L29

Use $(...) notation instead of legacy backticks `...`. (SC2006)


TAG=${TAG:-"v${APIVERSION}_`date -u +%Y%m%d`"}
REPO=${REPO:-longhornio}
IMAGE=${REPO}/${PROJECT}:${TAG}

function convert_version_to_major_minor_x() {
local version="$1"
if [[ "$version" =~ ^v([0-9]+)\.([0-9]+)\. ]]; then
echo "v${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.x"
else
echo "Invalid version format: $version"
fi
}

function get_branch() {
local version_file="version"
if [[ ! -f $version_file ]]; then
echo "Error: Version file '$version_file' not found."
exit 1
fi

local version=$(cat "$version_file")
local branch=$(convert_version_to_major_minor_x "$version")

echo "${branch}"
}

BRANCH=$(get_branch)

wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/refs/heads/${BRANCH}/versions.json" -O package/versions.json || {
echo "Failed to fetch from branch $BRANCH, trying main branch..."
wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/refs/heads/main/versions.json" -O package/versions.json || {
echo "Failed to fetch from main branch. Exiting."
exit 1
}
}

# update base image to get latest changes
BASE_IMAGE=`grep FROM package/Dockerfile | grep -v AS | awk '{print $2}'`
docker pull ${BASE_IMAGE}

buildx build --load -t ${IMAGE} -f package/Dockerfile .
echo "Building image ${IMAGE} based on ${BASE_IMAGE}"
buildx build \
--load \
--build-arg ARCH="${ARCH}" \
--build-arg DEP_VERSION_FILE=package/versions.json \
-t "${IMAGE}" \
-f package/Dockerfile .

echo Built ${IMAGE}

Expand Down

0 comments on commit 214e7f3

Please sign in to comment.