Skip to content

Commit

Permalink
Merge pull request middlewarehq#602 from sahitya-chandra/pre-req-check
Browse files Browse the repository at this point in the history
Node, Yarn and Docker version check added in dev.sh file
  • Loading branch information
jayantbh authored Oct 17, 2024
2 parents c4e20ae + 0411e33 commit 4bda170
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
58 changes: 58 additions & 0 deletions dev.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,63 @@
#!/bin/bash

#!/bin/bash

MINIMUM_NODE_VERSION=22.0.0
MINIMUM_YARN_VERSION=1.22.22
MINIMUM_DOCKER_VERSION=24.0.0

# Function to compare versions correctly
version_at_least() {
printf '%s\n%s\n' "$1" "$2" | sort -V | head -n 1 | grep -qx "$1"
}

check_versions() {
local node_version yarn_version docker_version
local errors=()

# Check Node.js version
if ! command -v node &> /dev/null; then
errors+=("Node.js is not installed. Please install Node.js v$MINIMUM_NODE_VERSION or higher.")
else
node_version=$(node -v | sed 's/^v//')
if ! version_at_least "$MINIMUM_NODE_VERSION" "$node_version"; then
errors+=("Current Node.js version ($node_version) is incompatible. Please install v$MINIMUM_NODE_VERSION or higher.")
fi
fi

# Check Yarn version
if ! command -v yarn &> /dev/null; then
errors+=("Yarn is not installed. Please install Yarn v$MINIMUM_YARN_VERSION or higher.")
else
yarn_version=$(yarn -v)
if ! version_at_least "$MINIMUM_YARN_VERSION" "$yarn_version"; then
errors+=("Current Yarn version ($yarn_version) is incompatible. Please install v$MINIMUM_YARN_VERSION or higher.")
fi
fi

# Check Docker version
if ! command -v docker &> /dev/null; then
errors+=("Docker is not installed. Please install Docker v$MINIMUM_DOCKER_VERSION or higher.")
else
docker_version=$(docker --version | awk '{print $3}' | sed 's/,//')
if ! version_at_least "$MINIMUM_DOCKER_VERSION" "$docker_version"; then
errors+=("Current Docker version ($docker_version) is incompatible. Please install v$MINIMUM_DOCKER_VERSION or higher.")
fi
fi

# Display errors, if any
if [ ${#errors[@]} -ne 0 ]; then
for error in "${errors[@]}"; do
echo "$error"
done
exit 1
fi

}

check_versions


[ ! -f .env ] && cp env.example .env

check_internet_connection() {
Expand Down
2 changes: 1 addition & 1 deletion web-server/src/assets/dora-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4bda170

Please sign in to comment.