Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(check-prerequisites): prerequisites recipe #15014

Merged
merged 5 commits into from
Feb 5, 2024
Merged
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ include ingestion/Makefile
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":"}; {printf "\033[35m%-35s\033[0m %s\n", $$2, $$3}'

.PHONY: prerequisites
prerequisites:
./scripts/check_prerequisites.sh

.PHONY: install_e2e_tests
install_e2e_tests: ## Install the ingestion module with e2e test dependencies (playwright)
python -m pip install "ingestion[e2e_test]/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ OpenMetadata being a full stack project, we use the following for development:
- [Yarn ^1.22.0](https://classic.yarnpkg.com/lang/en/docs/install/)
- [Rpm (Optional, only to run RPM profile with maven)](https://macappstore.org/rpm/)

- Here is a snapshot of a working environment on a Macbook.
To validate the installation of the above tools, you can run:

```shell
make prerequisites
```

### Example Snapshot on a Macbook

```shell
> docker --version
Expand Down
107 changes: 107 additions & 0 deletions scripts/check_prerequisites.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env bash
# Copyright 2021 Collate
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu

declare -A python
python["name"]="Python"
python["version_command"]="python --version 2>&1 | awk '{print \$2}'"
python["required_version"]="3.9 3.10 3.11"

declare -A docker
docker["name"]="Docker"
docker["version_command"]="docker --version | awk '{print \$3}' | sed 's/,//'"
docker["required_version"]="20 21 22 23 24"

declare -A maven
maven["name"]="Maven"
maven["version_command"]="mvn --version | head -n1 | awk '{print \$3}'"
maven["required_version"]="3.6 3.7 3.8 3.9"

declare -A java
java["name"]="Java"
java["version_command"]="java -version 2>&1 | awk -F'\"' '/version/ {print \$2}'"
java["required_version"]="11 16 17"

declare -A jq
jq["name"]="jq"
jq["version_command"]="jq --version | awk -F- '{print \$2}'"
jq["required_version"]="any"

declare -A node
node["name"]="Node"
node["version_command"]="node --version"
node["required_version"]="16 17 18"

declare -A yarn
yarn["name"]="Yarn"
yarn["version_command"]="yarn --version"
yarn["required_version"]="1.22 1.23 1.24"

declare -A antlr
antlr["name"]="ANTLR"
antlr["version_command"]="antlr4 | head -n1 | awk 'NF>1{print \$NF}'"
antlr["required_version"]="4.9"


code=0

function print_error() {
>&2 echo "✗ ERROR: $1"
}

check_command_existence() {
which "$1" >/dev/null 2>&1
res=$?
if [[ $res -ne 0 ]]; then
print_error "$command is not installed."
code=2
fi
echo $res
}

check_version() {
local tool_name=$1
local current=$2
local required=$3
IFS=' ' read -r -a required_versions <<< "$required"
if [[ "$required" == "any" ]]; then
echo "✓ $tool_name version $current is supported."
return
fi
for v in "${required_versions[@]}"; do
if [[ "$current" =~ $v.* ]]; then
echo "✓ $tool_name version $version is supported."
return
fi
done
print_error "$tool_name version $version is not supported. Supported versions are: $required"
code=1
}

declare -n dependency
for dependency in python docker java maven jq node yarn antlr; do
command=$(echo "${dependency["version_command"]}" | awk '{print $1}')
if [[ $(check_command_existence "$command") -ne 0 ]]; then
continue
fi
tool_name=${dependency["name"]}
version=$(eval ${dependency["version_command"]})
required_version=${dependency["required_version"]}
check_version $tool_name "$version" "$required_version"
done
if [[ $code -eq 0 ]]; then
echo "✓ All prerequisites are met."
else
print_error "Some prerequisites are not met."
fi
exit $code
Loading