Skip to content

Commit

Permalink
PMM-13487 Get rid of jq prerequisite
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Dec 3, 2024
1 parent 69f1fcc commit 9ef7aa3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 50 deletions.
5 changes: 2 additions & 3 deletions build/local/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Below is a list of prerequisites that are required to build PMM locally.
- tar
- git
- curl
- jq: 1.6+

Please note, that building some of the PMM internals, such as Grafana, requires at least 8GB of memory available to docker. The number of CPUs, however, does not matter that much.

Expand Down Expand Up @@ -117,8 +116,8 @@ Currently, Local Builds target the following platforms and distributions:

## TODO

- use the `--debug` parameter to control the verbosity of the logs (1/2 done)
- use the `--debug` parameter to control the verbosity of the logs (1/2 )
- implement the `--release` parameter
- remove `jq` from prerequisites
- remove `jq` from prerequisites
- output the build summary at the end of the build
- implement the `--clean` parameter
99 changes: 52 additions & 47 deletions build/local/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ parse_params() {
SUBMODULES=.modules
CLONE_BRANCH=v3
PATH_TO_SCRIPTS="sources/pmm/src/github.com/percona/pmm/build/scripts"
VAR_PREFIX="__PMM"

# Exported variables
export LOCAL_BUILD=1
Expand Down Expand Up @@ -114,32 +113,6 @@ parse_params() {
done
}

# Function to set a key/value pair
set_value() {
local key="$1"
local value="$2"
validate_key "$key"
eval "${VAR_PREFIX}_${key}=\"${value}\""
}

# Function to retrieve a value by key
get_value() {
local key="$1"
validate_key "$key"
local value=$(eval "echo -n ${VAR_PREFIX}_${key}")
if [ -z "$value" ]; then
echo "Error: variable '${VAR_PREFIX}_${key}' is undefined" >&2
fi
echo -n "$value"
}

# Function to unset a key
unset_value() {
local key="$1"
validate_key "$key"
eval "unset ${VAR_PREFIX}_${key}"
}

# Function to validate a key (allow only alphanumeric and underscore characters)
validate_key() {
local key="$1"
Expand Down Expand Up @@ -215,6 +188,8 @@ check_files() {
echo
exit 1
fi

mkdir -p "$DIR/build"
}

# Update submodules and PR branches
Expand All @@ -232,45 +207,71 @@ update() {
git config --global --add safe.directory /app
# Join the dependencies from ci-default.yml and ci.yml
rm -f gitmodules.yml
python ci.py --convert
DEPS=$(yq -o=json eval-all '. as $item ireduce ({}; . *d $item )' gitmodules.yml ci.yml | jq '.deps')
DEPS=$(echo "$DEPS" | jq -r '[.[] | {name: .name, branch: .branch, path: .path, url: .url}]')
echo "$DEPS"
rm -f gitmodules.yml
echo "$DEPS" > /app/build/build.json
echo -n > /tmp/deps.txt
echo "$DEPS" | jq -c '.[]' | while read -r item; do
branch=$(echo "$item" | jq -r '.branch')
path=$(echo "$item" | jq -r '.path')
name=$(echo "$item" | jq -r '.name')
echo "name=${name}:path=${path}:branch=${branch}" >> /tmp/deps.txt
done
mv -f /tmp/deps.txt /app/build/deps.txt
EOF

chmod +x "$CURDIR/entrypoint.sh"
# Join the dependencies from ci-default.yml and ci.yml
DEPS=$(
docker run --rm --platform="$PLATFORM" \
-v $ROOT_DIR:/app \
-v $CURDIR/ci.yml:/app/ci.yml \
-v $CURDIR/entrypoint.sh:/entrypoint.sh \
-w /app \
--entrypoint=/entrypoint.sh \
"$RPMBUILD_DOCKER_IMAGE"
)

echo "$DEPS" > sbom.json
docker run --rm --platform="$PLATFORM" \
-v $ROOT_DIR:/app \
-v $CURDIR/ci.yml:/app/ci.yml \
-v $CURDIR/entrypoint.sh:/entrypoint.sh \
-w /app \
--entrypoint=/entrypoint.sh \
"$RPMBUILD_DOCKER_IMAGE"

rm -f "$CURDIR/entrypoint.sh"

if [ ! -f "$SUBMODULES/build/deps.txt" ]; then
echo "Error: could not locate the 'build/deps.txt' file, exiting..."
exit 1
fi

echo
echo "This script rewinds submodule branches as per the joint config of '.gitmodules' and 'ci.yml'"

cd "$SUBMODULES"

echo "$DEPS" | jq -c '.[]' | while read -r item; do
branch=$(echo "$item" | jq -r '.branch')
path=$(echo "$item" | jq -r '.path')
name=$(echo "$item" | jq -r '.name')
# Read deps line by line and rewind submodules
while IFS= read -r line; do
local key="" val="" pair="" name="" path="" branch=""

# Parse the colon-separated subkeys and subvalues
IFS=':' read -r -a pairs <<< "$line"
for pair in "${pairs[@]}"; do
key="${pair%%=*}"
val="${pair#*=}"
if [ "$key" = "name" ]; then
name="$val"
elif [ "$key" = "path" ]; then
path="$val"
elif [ "$key" = "branch" ]; then
branch="$val"
fi
done

echo
echo "Rewinding submodule '$name' ..."
echo "path: ${path}, branch: ${branch}"
echo "Rewinding submodule $name ..."
echo "path: $path, branch: $branch"

rewind "$path" "$branch"
done
done < "build/deps.txt"

echo
echo "Printing git status..."
Expand All @@ -280,6 +281,10 @@ update() {
git submodule status

cd "$CURDIR" > /dev/null

if [ "$UPDATE_ONLY" -eq 1 ]; then
exit 0
fi
}

get_branch_name() {
Expand Down

0 comments on commit 9ef7aa3

Please sign in to comment.