Skip to content

Commit

Permalink
updating Makefile as in #73
Browse files Browse the repository at this point in the history
Signed-off-by: Boekhorst <[email protected]>
  • Loading branch information
boekhorstb1 committed Sep 10, 2024
1 parent a30c9ca commit d27d5ad
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 30 deletions.
78 changes: 48 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ COLOUR_BLUE=\033[0;34m
COLOUR_END=\033[0m

.DEFAULT_GOAL:=help
SHELL := /bin/bash
SHELL:=/bin/bash

# Get needed paths and information from locally installed librados
export RADOSLIB_VERSION := 2.0.0
export GENERAL_LIB_LOCATION := ${shell pip show rados | grep -oP "(?<=Location: ).*"}
export RADOSLIB_INSTALLED_VERSION := ${shell pip show rados | grep Version | awk '{print $$2}'}

## checking if docker, or podman should be used. Podman is preferred.
ifeq ($(shell command -v podman 2> /dev/null),)
Expand All @@ -18,27 +14,41 @@ else
CONTAINERCMD=podman
endif

# Checking if python exists
ifneq (, $(shell command -v python))
$(info Python is installed as 'python')
PYTHON := $(shell command -v python)
else ifneq (, $(shell command -v python3))
$(info Python3 is installed as 'python3')
PYTHON := $(shell command -v python3)
else
$(error Neither python nor python3 is installed)
endif

## Export default rookify version
export ROOKIFY_VERSION ?= "0.0.0.dev1"
export ROOKIFY_VERSION?=0.0.0.dev1

.PHONY: help
help: ## Display this help message
@echo -e '${COLOUR_RED}Usage: make <command>${COLOUR_END}'
@echo -e '\n${COLOUR_BLUE}ROOKIFY MAKEFILE${COLOUR_BLUE}'
@echo -e '\n${COLOUR_RED}Usage: make <command>${COLOUR_END}'
@cat $(MAKEFILE_LIST) | grep '^[a-zA-Z]' | \
awk -F ':.*?## ' 'NF==2 {printf " %-26s%s\n\n", $$1, "${COLOUR_GREEN}"$$2"${COLOUR_END}"}'
@echo -e '${COLOUR_RED}OSISM helperscript usage: make <command>${COLOUR_END}'
@cat $(MAKEFILE_LIST) | grep '^[a-zA-Z]' | \
awk -F ':.*?#osism# ' 'NF==2 {printf " %-26s%s\n\n", $$1, "${COLOUR_GREEN}"$$2"${COLOUR_END}"}'

.PHONY: setup
setup: setup-pre-commit check-radoslib setup-venv ## Setup the pre-commit environment and then the venv environment
setup: check-radoslib setup-venv setup-pre-commit ## Setup the pre-commit environment and then the venv environment

.PHONY: setup-pre-commit
setup-pre-commit:
pip install --user pre-commit && pre-commit install
./.venv/bin/pip install --user pre-commit && ./.venv/bin/python -m pre_commit install

.PHONY: setup-venv
setup-venv:
python -m venv --system-site-packages ./.venv && \
source ./.venv/bin/activate && \
pip install -r requirements.txt
${PYTHON} -m venv --system-site-packages ./.venv && \
./.venv/bin/pip install -r requirements.txt

.PHONY: run-precommit
run-precommit: ## Run pre-commit to check if all files running through
Expand All @@ -50,33 +60,33 @@ update-requirements: ## Update the requirements.txt with newer versions of pip p
pip freeze -l > requirements.txt

.PHONY: check-radoslib
export RADOSLIB_VERSION:=2.0.0
check-radoslib: ## Checks if radoslib is installed and if it contains the right version
@if [ -z "${GENERAL_LIB_LOCATION}" ]; then \
echo -e "${COLOUR_RED}ERROR: 'rados' library not found. Please make sure it's installed.${COLOUR_END}"; \
exit 1; \
else \
echo -e "GENERAL_LIB_LOCATION: $(GENERAL_LIB_LOCATION)"; \
fi
@if [ "${RADOSLIB_INSTALLED_VERSION}" != "${RADOSLIB_VERSION}" ]; then \
echo -e "${COLOUR_RED}ERROR: Incorrect version of 'rados' library found. Expected version $(RADOSLIB_VERSION), found $$RADOSLIB_INSTALLED_VERSION.${COLOUR_END}"; \
exit 1; \
else \
echo -e "RADOSLIB_INSTALLED_VERSION: $(RADOSLIB_INSTALLED_VERSION)"; \
fi
# Get needed paths and information from locally installed librados
./scripts/check_local_rados_lib_installation.sh ${RADOSLIB_VERSION}

.PHONY: build-local-rookify
build-local-rookify: ## This builds rookify into .venv/bin/rookify
source .venv/bin/activate && pip install -e .

.PHONY: build-container
build-container: ## Build container from Dockerfile, add e.g. ROOKIFY_VERSION=0.0.1 to specify the version. Default value is 0.0.0.dev1
${CONTAINERCMD} build --build-arg ROOKIFY_VERSION=$(ROOKIFY_VERSION) --target rookify -t rookify:latest -f Dockerfile .

.PHONY: run-local-rookify
run-local-rookify: ## Runs rookify in the local development environment (requires setup-venv)
$(eval PYTHONPATH="${PYTHONPATH}:$(pwd)/src")
source ./.venv/bin/activate && \
cd src && python -m rookify
if [ ! -f ./.venv/bin/rookify ]; then \
${MAKE} build-local-rookify; \
fi; \
.venv/bin/rookify

.PHONY: run-rookify
run-rookify: ## Runs rookify in the container
docker exec -it rookify-dev /app/rookify/.venv/bin/rookify

.PHONY: build-container
build-container: ## Build container from Dockerfile, add e.g. ROOKIFY_VERSION=0.0.1 to specify the version. Default value is 0.0.0.dev1
${CONTAINERCMD} build --build-arg ROOKIFY_VERSION=$(ROOKIFY_VERSION) --target rookify -t rookify:latest -f Dockerfile .
.PHONY: get-testbed-configs-for-rookify-testing
get-testbed-configs-for-rookify-testing: ## Gets the needed config (like .kube, /etc/ceph and so on) from the testbed
bash ./scripts/get_configs_from_testbed.sh

.PHONY: run-tests-locally
run-tests-locally: ## Runs the tests in the tests directory. NB: check that your local setup is connected through vpn to the testbed!
Expand All @@ -101,3 +111,11 @@ down: ## Remove the containers as setup by docker-compose.yml
.PHONY: up
up: ## Sets up the container as specified in docker-compose.yml and opens a bash terminal
${CONTAINERCMD} compose up -d

##
# Add osism specific scripts below here (so they appear below helper header)
##

.PHONY: get-config
get-config: #osism# Gets configuration files from the OSISM testbed
./scripts/osism/get_osism_configs_from_testbed.sh
29 changes: 29 additions & 0 deletions scripts/check_local_rados_lib_installation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/env bash

# Check if a version argument is provided
if [ $# -eq 1 ]; then
RADOSLIB_VERSION="$1"
else
# Default version if no argument is provided
RADOSLIB_VERSION="2.0.0"
fi

# Get the location of the installed rados library
GENERAL_LIB_LOCATION=$(pip show rados | grep -oP "(?<=Location: ).*")

# Get the installed version of the rados library
RADOSLIB_INSTALLED_VERSION=$(pip show rados | grep Version | awk '{print $2}')

# Check if the rados library is installed
if [ -z "$GENERAL_LIB_LOCATION" ]; then
echo -e "\033[0;31mERROR: 'rados' library not found. Please make sure it's installed.\033[0m"
exit 1
fi

# Check if the installed version matches the expected version
if [ "$RADOSLIB_INSTALLED_VERSION" != "$RADOSLIB_VERSION" ]; then
echo -e "\033[0;31mERROR: 'rados' library version $RADOSLIB_INSTALLED_VERSION does not match the expected version $RADOSLIB_VERSION.\033[0m"
exit 1
else
echo -e "\033[0;32m'rados' library version $RADOSLIB_INSTALLED_VERSION is correct.\033[0m"
fi

0 comments on commit d27d5ad

Please sign in to comment.