Skip to content

Commit

Permalink
chore(build): move common functions to longhorn/dep-versions
Browse files Browse the repository at this point in the history
Longhorn 10208

Signed-off-by: Derek Su <[email protected]>
(cherry picked from commit 742209d)
  • Loading branch information
derekbit authored and mergify[bot] committed Feb 18, 2025
1 parent 7ce4758 commit 21e28cf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 32 deletions.
4 changes: 4 additions & 0 deletions Dockerfile.dapper
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM registry.suse.com/bci/golang:1.23

ARG DAPPER_HOST_ARCH
ARG SRC_BRANCH=main
ARG SRC_TAG
ARG http_proxy
ARG https_proxy

Expand All @@ -11,6 +13,8 @@ ENV DAPPER_ENV TAG REPO DRONE_REPO DRONE_PULL_REQUEST DRONE_COMMIT_REF
ENV DAPPER_OUTPUT bin coverage.out
ENV DAPPER_RUN_ARGS --privileged -v /dev:/host/dev -v /proc:/host/proc
ENV DAPPER_SOURCE /go/src/github.com/longhorn/longhorn-share-manager
ENV SRC_BRANCH ${SRC_BRANCH}
ENV SRC_TAG ${SRC_TAG}

ENV GOLANGCI_LINT_VERSION="v1.60.3"

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
TARGETS := $(shell ls scripts)

export SRC_BRANCH := $(shell bash -c 'wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/main/scripts/common.sh" -O build-common.sh && source build-common.sh && get_branch')
export SRC_TAG := $(shell git tag --points-at HEAD | head -n 1)

.dapper:
@echo Downloading dapper
@curl -sL https://releases.rancher.com/dapper/latest/dapper-`uname -s`-`uname -m` > .dapper.tmp
Expand Down
33 changes: 1 addition & 32 deletions scripts/package
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,11 @@ 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")

# 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
}

SRC_BRANCH=$(get_branch)
SRC_TAG=$(git tag --points-at HEAD | head -n 1)

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

echo "Building image ${IMAGE} based on ${BASE_IMAGE}"
echo "Building image ${IMAGE} based on ${BASE_IMAGE} with ARCH=${ARCH} SRC_BRANCH=${SRC_BRANCH} SRC_TAG=${SRC_TAG}"
buildx build \
--load \
--build-arg ARCH="${ARCH}" \
Expand Down

0 comments on commit 21e28cf

Please sign in to comment.