Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions ceph-dev-pipeline/build/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ pipeline {
println("Skipping compilation since chacra already has artifacts. To override, use THROWAWAY=true (to skip this check) or FORCE=true (to re-upload artifacts).")
build_matrix["${DIST}_${ARCH}"] = false
}

// Set up Pulp client
if ( env.PULP_UPLOAD == "true" ) {
withCredentials([
usernamePassword(credentialsId: 'pulp-auth', usernameVariable: 'PULP_USERNAME', passwordVariable: 'PULP_PASSWORD')
Comment thread
vamahaja marked this conversation as resolved.
]) {
sh './scripts/setup_pulp.sh'
}
}
}
}
}
Expand Down Expand Up @@ -587,6 +596,22 @@ pipeline {
export OS_PKG_TYPE="${os.pkg_type}"
if [ "$THROWAWAY" != "true" ]; then ./scripts/chacra_upload.sh; fi
"""

sh """#!/bin/bash
if [ "$THROWAWAY" != "true" ] && [ "$PULP_UPLOAD" == "true" ]; then
export CEPH_VERSION="${env.VERSION}"
export OS_NAME="${os.name}"
export OS_VERSION="${os.version}"
export OS_VERSION_NAME="${os.version_name}"
export OS_PKG_TYPE="${os.pkg_type}"
export SHA1="${env.SHA1}"
export FLAVOR="${env.FLAVOR}"

./scripts/pulp_upload.sh
else
echo "Skipping pulp upload because PULP_UPLOAD=$PULP_UPLOAD"
fi
"""
}
}
post {
Expand Down
5 changes: 5 additions & 0 deletions ceph-dev-pipeline/config/definitions/ceph-dev-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
description: "Whether to push new binaries to Chacra if some are already present"
default: false

- bool:
name: PULP_UPLOAD
description: "Whether to upload packages to Pulp"
default: false

- choice:
name: FLAVOR
choices:
Expand Down
286 changes: 286 additions & 0 deletions scripts/pulp_upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
#!/bin/bash
set -ex

export PATH="$HOME/.local/bin:$PATH"

PULP_PROJECT="ceph"
SHORT_SHA1=${SHA1: -8}

log() {
echo "[pulp_upload] $*" >&2
}

resolve_branch_from_ceph_version() {
local branch=""
if [[ $CEPH_VERSION =~ ^21.* ]]; then
branch="main"
elif [[ $CEPH_VERSION =~ ^20.* ]]; then
branch="tentacle"
elif [[ $CEPH_VERSION =~ ^19.* ]]; then
branch="squid"
elif [[ $CEPH_VERSION =~ ^18.* ]]; then
branch="reef"
elif [[ $CEPH_VERSION =~ ^17.* ]]; then
branch="quincy"
elif [[ $CEPH_VERSION =~ ^16.* ]]; then
branch="pacific"
else
log "ERROR: Unsupported Ceph version '${CEPH_VERSION}'" \
"(expected 16.x–20.x for branch mapping)"
exit 1
fi
printf '%s\n' "$branch"
}
Comment on lines +13 to +33
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to reuse https://github.com/ceph/ceph-build/blob/main/scripts/build_utils.sh#L13-L78? Having another distro map hard coded somewhere is not scalable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we ought to drop a yaml or json file in, say, the repo root for this


resolve_os_version_for_repo() {
local os_label="${OS_VERSION}"
if [ "$OS_NAME" == "ubuntu" ]; then
os_label="${OS_VERSION_NAME}"
fi
printf '%s\n' "$os_label"
}

add_pulp_uploaded_packages_to_repository() {
local content_type="$1"
local repo_name="$2"
local uuid_array_name="$3"
local -n _pulp_uuids="$uuid_array_name"
local add_content_json kind_upper

kind_upper=$(printf '%s' "$content_type" | tr '[:lower:]' '[:upper:]')
log "Adding ${kind_upper} content to repository ${repo_name}"
add_content_json="$(
printf '['
for uuid in "${_pulp_uuids[@]}"; do
printf '{"pulp_href":"/pulp/api/v3/content/%s/packages/%s/"},' \
"$content_type" "$uuid"
done | sed 's/,$//'
printf ']'
)"
pulp "${content_type}" repository content modify --repository "$repo_name" \
--add-content "$add_content_json" --base-version 0
}

upload_rpm_to_pulp() {
local rpmbuild_dir="${1%/}"
local repo_name="$2"
local out_array_name="$3"
local -n pulp_uuid="$out_array_name"

pulp_uuid=()
log "Discovering RPM artifacts under ${rpmbuild_dir}"
while IFS= read -r rpm_file; do
[ -z "$rpm_file" ] && continue
pulp_uuid+=($(pulp rpm content -t package upload \
--repository "$repo_name" --file "$rpm_file" --no-publish | \
jq -r '.prn | split(":") | last'
))
done < <(
find "${rpmbuild_dir}" -regextype egrep -regex ".*(\.rpm)$"
)
log "Finished RPM uploads (repository=${repo_name})"
[[ ${#pulp_uuid[@]} -gt 0 ]]
}

upload_deb_to_pulp() {
local deb_dir="${1%/}"
local repo_name="$2"
local arch="$3"
local out_array_name="$4"
local -n pulp_uuid="$out_array_name"
local _arch="$arch"

if [ "$arch" == "x86_64" ]; then
_arch="amd64"
elif [ "$arch" == "aarch64" ]; then
_arch="arm64"
fi

pulp_uuid=()
log "Discovering binary .deb packages under ${deb_dir}/"
while IFS= read -r deb_file; do
[ -z "$deb_file" ] && continue
pulp_uuid+=($(pulp deb content -t package upload \
--repository "$repo_name" --file "$deb_file" | \
jq -r '.prn | split(":") | last'
))
done < <(
find "${deb_dir}/" -regextype egrep -regex ".*(${_arch}\.deb)$"
)
log "Finished DEB uploads (repository=${repo_name})"
[[ ${#pulp_uuid[@]} -gt 0 ]]
}

publish_pulp_distribution() {
local repo_name="$1"
local repo_endpoint="$2"
local repo_arch="$3"
local package_version="$4"
local final_version pub_href dist_name labels

pub_href=$(
pulp "${OS_PKG_TYPE}" publication create --repository "$repo_name" \
| jq -r '.pulp_href'
)
log "Created ${OS_PKG_TYPE} publication: ${pub_href}"

if [ "$pub_href" == "null" ]; then
log "ERROR: Failed to create ${OS_PKG_TYPE} publication"
return
fi

dist_name="dist-${repo_name}-${SHORT_SHA1}"
log "Creating distribution ${dist_name} " \
"with base_path=${repo_endpoint}"
if ! pulp "${OS_PKG_TYPE}" distribution create \
--name "${dist_name}" \
--base-path "${repo_endpoint}" \
--publication "${pub_href}"; then
log "ERROR: Failed to create ${OS_PKG_TYPE} distribution"
return
fi

local lookup_flag="--name"
if [[ "$OS_PKG_TYPE" == "rpm" ]]; then
lookup_flag="--distribution"
fi

local i
local -a labels=(
project "${PULP_PROJECT}"
version "${package_version}"
ref "${BRANCH}"
arch "${repo_arch}"
sha1 "${SHA1}"
distro "${OS_NAME}"
distro_version "${OS_VERSION_NAME}"
flavor "${FLAVOR}"
)
log "Setting distribution labels: ${labels[@]}"
for ((i = 0; i < ${#labels[@]}; i += 2)); do
pulp "${OS_PKG_TYPE}" distribution label set \
"${lookup_flag}" "${dist_name}" \
--key "${labels[i]}" --value "${labels[i + 1]}"
done

log "Pulp upload and distribution publish completed" \
"(repository=${repo_name})"
}

log "Uploading artifacts to Pulp repository ..."

BRANCH=$(resolve_branch_from_ceph_version)
_OS_VERSION=$(resolve_os_version_for_repo)

REPO_NAME="${PULP_PROJECT}-${BRANCH}-${OS_NAME}-${_OS_VERSION}"
REPO_ENDPOINT="repos/${PULP_PROJECT}/${BRANCH}/${SHA1}/${OS_NAME}"
REPO_ENDPOINT="${REPO_ENDPOINT}/${_OS_VERSION}/flavors/${FLAVOR}"

if [ "$OS_PKG_TYPE" = "rpm" ]; then
log "Starting RPM upload (OS_PKG_TYPE=${OS_PKG_TYPE})"

spec_path="${WORKSPACE}/dist/ceph/ceph.spec"
rpm_release=$(grep Release "$spec_path" | \
sed 's/Release:[ \t]*//g' | cut -d '%' -f 1)
rpm_version=$(grep Version "$spec_path" | \
sed 's/Version:[ \t]*//g')
PACKAGE_MANAGER_VERSION="$rpm_version-$rpm_release"
log "Package version label (RPM): ${PACKAGE_MANAGER_VERSION}"

_rpm_root="${WORKSPACE}/dist/ceph/rpmbuild"
for _kind in SRPMS noarch aarch64 x86_64; do
_rpm_pulp_uuids=()
case "$_kind" in
SRPMS)
log "Uploading SRPMS to ${REPO_NAME}-SRPMS"
if upload_rpm_to_pulp "${_rpm_root}/SRPMS" "${REPO_NAME}-SRPMS" \
_rpm_pulp_uuids; then
add_pulp_uploaded_packages_to_repository rpm \
"${REPO_NAME}-SRPMS" _rpm_pulp_uuids
publish_pulp_distribution \
"${REPO_NAME}-SRPMS" \
"${REPO_ENDPOINT}/SRPMS" \
"source" \
"${PACKAGE_MANAGER_VERSION}"
else
log "WARNING: SRPMS upload failed;" \
"skipping content modification and publication for ${REPO_NAME}-SRPMS"
fi
;;
x86_64)
log "Uploading x86_64 RPMs to ${REPO_NAME}-x86_64"
if upload_rpm_to_pulp "${_rpm_root}/RPMS/x86_64" \
"${REPO_NAME}-x86_64" _rpm_pulp_uuids; then
add_pulp_uploaded_packages_to_repository rpm \
"${REPO_NAME}-x86_64" _rpm_pulp_uuids
publish_pulp_distribution \
"${REPO_NAME}-x86_64" \
"${REPO_ENDPOINT}/x86_64" \
"x86_64" \
"${PACKAGE_MANAGER_VERSION}"
else
log "WARNING: x86_64 RPM upload failed;" \
"skipping content modification and publication for ${REPO_NAME}-x86_64"
fi
;;
noarch)
log "Uploading noarch RPMs to ${REPO_NAME}-noarch"
if upload_rpm_to_pulp "${_rpm_root}/RPMS/noarch" \
"${REPO_NAME}-noarch" _rpm_pulp_uuids; then
add_pulp_uploaded_packages_to_repository rpm \
"${REPO_NAME}-noarch" _rpm_pulp_uuids
publish_pulp_distribution \
"${REPO_NAME}-noarch" \
"${REPO_ENDPOINT}/noarch" \
"noarch" \
"${PACKAGE_MANAGER_VERSION}"
else
log "WARNING: noarch RPM upload failed;" \
"skipping content modification and publication for ${REPO_NAME}-noarch"
fi
;;
aarch64)
log "Uploading aarch64 RPMs to ${REPO_NAME}-aarch64"
if upload_rpm_to_pulp "${_rpm_root}/RPMS/aarch64" \
"${REPO_NAME}-aarch64" _rpm_pulp_uuids; then
add_pulp_uploaded_packages_to_repository rpm \
"${REPO_NAME}-aarch64" _rpm_pulp_uuids
publish_pulp_distribution \
"${REPO_NAME}-aarch64" \
"${REPO_ENDPOINT}/aarch64" \
"aarch64" \
"${PACKAGE_MANAGER_VERSION}"
else
log "WARNING: aarch64 RPM upload failed;" \
"skipping content modification and publication for ${REPO_NAME}-aarch64"
fi
;;
esac
done
unset _kind _rpm_root _rpm_pulp_uuids

elif [ "$OS_PKG_TYPE" = "deb" ]; then
PACKAGE_MANAGER_VERSION="${VERSION}-1${OS_VERSION_NAME}"
log "Starting DEB upload (OS_PKG_TYPE=${OS_PKG_TYPE})"

log "Uploading DEB artifacts to ${REPO_NAME}-${ARCH}"
_deb_pulp_uuids=()
if upload_deb_to_pulp "${WORKSPACE}/dist/ceph" "${REPO_NAME}-${ARCH}" \
"${ARCH}" _deb_pulp_uuids; then
add_pulp_uploaded_packages_to_repository deb "${REPO_NAME}-${ARCH}" \
_deb_pulp_uuids
publish_pulp_distribution \
"${REPO_NAME}-${ARCH}" \
"${REPO_ENDPOINT}/${ARCH}" \
"${ARCH}" \
"${PACKAGE_MANAGER_VERSION}"
else
log "WARNING: DEB upload failed;" \
"skipping content modification and publication for ${REPO_NAME}-${ARCH}"
fi
unset _deb_pulp_uuids

else
log "ERROR: Unsupported OS_PKG_TYPE='${OS_PKG_TYPE}' (expected rpm or deb)"
exit 1
fi
23 changes: 23 additions & 0 deletions scripts/setup_pulp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash -ex

echo "Setting up Pulp client"
source "$WORKSPACE/scripts/setup_uv.sh"

export PATH="$HOME/.local/bin:$PATH"

PULP_SERVER_URL="https://pulp.apps.pok.os.sepia.ceph.com"

uv tool install pulp-cli --with pulp-cli-deb

echo "Configuring Pulp client"
uv run pulp config create --base-url "${PULP_SERVER_URL}" \
--username "${PULP_USERNAME}" --password "${PULP_PASSWORD}" \
--no-verify-ssl --overwrite

echo "Checking Pulp client status"
if ! uv run pulp status; then
echo "Error: Pulp client is not configured correctly."
exit 1
fi

echo "Pulp client setup complete"