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 <derek.su@suse.com>
  • Loading branch information
derekbit committed Feb 11, 2025
1 parent 3cdf8b6 commit 813b513
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 15 deletions.
29 changes: 15 additions & 14 deletions package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM registry.suse.com/bci/bci-base:15.6 AS builder

ARG ARCH=amd64
ARG SRC_BRANCH=main
ARG SRC_TAG

RUN zypper -n ref && \
zypper update -y
Expand All @@ -12,23 +14,22 @@ RUN zypper -n addrepo --refresh https://download.opensuse.org/repositories/syste
RUN zypper -n install cmake curl git gcc wget xsltproc docbook-xsl-stylesheets jq && \
rm -rf /var/cache/zypp/*

RUN git clone https://github.com/longhorn/dep-versions.git -b ${SRC_BRANCH} /usr/src/dep-versions && \
cd /usr/src/dep-versions && \
if [ -n "${SRC_TAG}" ] && git show-ref --tags ${SRC_TAG} > /dev/null 2>&1; then \
echo "Checking out tag ${SRC_TAG}"; \
cd /usr/src/dep-versions && git checkout tags/${SRC_TAG}; \
fi

# Build liblonghorn
ENV LIBLONGHORN_COMMIT_ID 53d1c063b95efc8d949b095bd4bf04637230265f
RUN cd /usr/src && \
git clone https://github.com/rancher/liblonghorn.git && \
cd liblonghorn && \
git checkout ${LIBLONGHORN_COMMIT_ID} && \
make; \
make install
RUN export REPO_OVERRIDE="" && \
export COMMIT_ID_OVERRIDE="" && \
bash /usr/src/dep-versions/scripts/build-liblonghorn.sh "${REPO_OVERRIDE}" "${COMMIT_ID_OVERRIDE}"

# Build TGT
ENV TGT_COMMIT_ID 3a8bc4823b5390e046f7aa8231ed262c0365c42c
RUN cd /usr/src && \
git clone https://github.com/rancher/tgt.git && \
cd tgt && \
git checkout ${TGT_COMMIT_ID} && \
make; \
make install
RUN export REPO_OVERRIDE="" && \
export COMMIT_ID_OVERRIDE="" && \
bash /usr/src/dep-versions/scripts/build-tgt.sh "${REPO_OVERRIDE}" "${COMMIT_ID_OVERRIDE}"

# Install grpc_health_probe
RUN GRPC_HEALTH_PROBE_DOWNLOAD_URL=$(wget -qO- https://api.github.com/repos/grpc-ecosystem/grpc-health-probe/releases/latest | jq -r '.assets[] | select(.name | test("linux.*'"${ARCH}"'"; "i")) | .browser_download_url') && \
Expand Down
38 changes: 37 additions & 1 deletion scripts/package
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
#!/bin/bash
set -e

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")

# Fetch versions.json from the appropriate branch, fallback to main
wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/${branch}/versions.json" -O /versions.json
if [ $? -eq 0 ]; then
echo "${branch}"
else
echo "main"
fi
}

source $(dirname $0)/version

cd $(dirname $0)/..
Expand Down Expand Up @@ -39,7 +67,15 @@ do
docker pull "$BASE_IMAGE"
done

docker build --build-arg ARCH=${ARCH} -t ${IMAGE} -f package/Dockerfile .
SRC_BRANCH=$(get_branch)
SRC_TAG=$(git tag --points-at HEAD | head -n 1)

docker build \
--build-arg ARCH=${ARCH} \
--build-arg SRC_BRANCH="${SRC_BRANCH}" \
--build-arg SRC_TAG="${SRC_TAG}" \
-t ${IMAGE} \
-f package/Dockerfile .

echo Built ${IMAGE}

Expand Down

0 comments on commit 813b513

Please # to comment.