Skip to content

Commit

Permalink
MINOR - Docs prerequisites recipe (#15014)
Browse files Browse the repository at this point in the history
* docs(check-prerequisites): prerequisites recipe

- added scripts/check_prerequisites.sh.
- added usage in docs.
- added prerequisites to Makefile.

* docs(check-prerequisites): fix for docker version

* docs(check-prerequisites): fix for docker version

* docs(check-prerequisites): fix for docker version

* docs(check-prerequisites): revert docker-compose.yml
  • Loading branch information
sushi30 authored Feb 5, 2024
1 parent 8574e9a commit 93c8ce3
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 1 deletion.
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

0 comments on commit 93c8ce3

Please sign in to comment.