From d724082d1c23dcc7b1cb839990d1e2895af95f57 Mon Sep 17 00:00:00 2001 From: "Joel.Johnson" Date: Thu, 29 Aug 2024 15:34:07 +0530 Subject: [PATCH 1/3] updated the makefile --- installation.md | 9 --------- makefile | 32 ++++++++++++++++++-------------- makefile_summary.md | 27 +++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 23 deletions(-) create mode 100644 makefile_summary.md diff --git a/installation.md b/installation.md index 365ce008..5444fef9 100644 --- a/installation.md +++ b/installation.md @@ -63,10 +63,6 @@ During the execution of this command, the Makefile will initiate and prompt for ```make installing-psql```
-#### **To populate your database with data** - -```make into-database``` -
#### **To modify your _.bashrc_ file** @@ -82,11 +78,6 @@ During the execution of this command, the Makefile will initiate and prompt for * Avoid using passwords that closely resemble your username and to run it -#### **To install Usfm-Grammar 2.0** - -```make installing-usfmgrammar``` -
- #### **To install Docker and Docker-Compose** ```make installing-docker``` diff --git a/makefile b/makefile index de06cb76..5ae02d89 100644 --- a/makefile +++ b/makefile @@ -4,7 +4,7 @@ ACTIVATE_VENV := . $(ENVPATH)/bin/activate && SHELL := /bin/bash -.PHONY: pre-requistite venv-configure venv-activate install-dependencies check-package into-database environmental-variables installing-usfmgrammar installing-docker kratosconfig +.PHONY: pre-requistite venv-configure venv-activate install-dependencies check-package environmental-variables installing-docker kratosconfig pre-requisite: #basic python packages to run the makefile @if ! dpkg -s python3-pip &> /dev/null; then \ @@ -62,22 +62,28 @@ installing-psql: fi; \ fi - -into-database: ## Accessing the database folder - sudo -u postgres psql -tc "SELECT 1 FROM pg_database WHERE datname='vachan_db'" | grep -q 1 || sudo -u postgres psql -c "CREATE DATABASE vachan_db" - - cd db && sudo -u postgres psql vachan_db < seed_DB.sql - +installing-psql: + @if psql --version | grep -q "15.3"; then \ + echo "You already have psql 15.3 installed."; \ + else \ + read -p "You currently have a different version of psql installed. Do you want to proceed with installing psql 15.3? (y/N) " response; \ + if [[ $$response =~ ^[Yy]$$ ]]; then \ + echo "Installing psql 15.3..."; \ + sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'; \ + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null; \ + sudo apt update; \ + sudo apt remove postgresql postgresql-contrib; \ + sudo apt install postgresql-15 postgresql-contrib-15; \ + else \ + echo "Aborted installation."; \ + fi; \ + fi environmental-variables: chmod +x setup.sh ./setup.sh -installing-usfmgrammar: - sudo apt install npm - sudo npm install -g usfm-grammar@2.2.0 - installing-docker: @if docker --version | grep -q "Docker version 24.0."; then \ echo "You already have Docker 24.0.1 or above installed."; \ @@ -110,7 +116,7 @@ installing-docker: kratosconfig: - cd docker/Kratos_config && docker compose -f quickstart.yml up + cd docker/Kratos_config && sudo docker compose -f quickstart.yml up setup: @@ -121,9 +127,7 @@ setup: make install-dependencies make check-package make installing-psql - make into-database make environmental-variables - make installing-usfmgrammar make installing-docker make kratosconfig diff --git a/makefile_summary.md b/makefile_summary.md new file mode 100644 index 00000000..5fe07971 --- /dev/null +++ b/makefile_summary.md @@ -0,0 +1,27 @@ +# Makefile Explanation + +## Variable Definitions: + +- ENVPATH := vachan-ENV: Defines a variable named ENVPATH and assigns it the value "vachan-ENV". This variable will likely be used to reference the path to a virtual environment. +- ACTIVATE_VENV := . $(ENVPATH)/bin/activate &&: Defines another variable named ACTIVATE_VENV. The value assigned to it is a command that will activate the virtual environment located in the ENVPATH directory. It uses the . command to source the activate script in the virtual environment's bin directory, and the && operator ensures that the subsequent command (which will likely be used later in the Makefile) is only executed if the activation is successful. +- SHELL := /bin/bash: Sets the default shell to use for executing commands within the Makefile. In this case, it's set to /bin/bash. + +## Phony Targets: + +- PHONY: pre-requistite venv-configure venv-activate install-dependencies check-package into-database environmental-variables installing-usfmgrammar installing-docker kratosconfig: Declares several targets as "phony". Phony targets are not actual files but are used to represent specific actions within the Makefile. This line ensures that Make doesn't treat these targets as files and doesn't try to rebuild them. + +## Make Targets: + +- pre-requisite:: Checks if the python3-pip and python3-venv packages are installed. If not, it installs them using sudo apt install. +- venv-configure:: Creates a virtual environment in the directory specified by ENVPATH using the python3 -m venv command. +- venv-activate:: Activates the virtual environment using the ACTIVATE_VENV variable. +- install-dependencies:: Installs the dependencies listed in the requirements.txt file using pip install within the activated virtual environment. +- check-package:: Checks if all the packages listed in requirements.txt are installed. If any are missing, it installs them using pip install. +- installing-psql:: Checks if PostgreSQL version 15.3 is installed. If not, it prompts the user to install it and then installs it using sudo apt install. +- environmental-variables:: Makes a script named setup.sh executable and then runs it. This script likely sets certain environment variables needed for the project. +- installing-docker:: Checks if Docker version 24.0.1 or above is installed. If not, it prompts the user to install it and then installs it using the official Docker repository. +- kratosconfig:: Navigates to the docker/Kratos_config folder and runs docker compose -f quickstart.yml up to start Docker containers for the project. + +## Default Target: + +- setup:: The default target that is executed when you run make without specifying a specific target. It calls all the other targets in sequence, effectively setting up the entire project environment. \ No newline at end of file From 32ce1aeaad0307a40fd8f389886c764c160f8867 Mon Sep 17 00:00:00 2001 From: "Joel.Johnson" Date: Thu, 29 Aug 2024 16:37:41 +0530 Subject: [PATCH 2/3] updated the code --- README.md | 2 +- makefile | 31 ++++--------------------------- makefile_summary.md | 2 +- 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index ec756aff..bda19097 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) If you need to run the app on another port `--port` can be used. To run in debug mode `--debug` can be used -```uvicorn main:app --port=7000 --debug``` +```uvicorn main:app --port=7000 --debug --reload``` ### Access Documentations diff --git a/makefile b/makefile index 5ae02d89..aeabf0d9 100644 --- a/makefile +++ b/makefile @@ -4,7 +4,7 @@ ACTIVATE_VENV := . $(ENVPATH)/bin/activate && SHELL := /bin/bash -.PHONY: pre-requistite venv-configure venv-activate install-dependencies check-package environmental-variables installing-docker kratosconfig +.PHONY: pre-requistite venv-configure venv-activate install-dependencies check-package environmental-variables installing-docker run-app pre-requisite: #basic python packages to run the makefile @if ! dpkg -s python3-pip &> /dev/null; then \ @@ -45,22 +45,6 @@ check-package: ## Check if packages from requirements.txt are installed echo "Some packages are missing or failed to install."; \ fi -installing-psql: - @if psql --version | grep -q "15.3"; then \ - echo "You already have psql 15.3 installed."; \ - else \ - read -p "You currently have a different version of psql installed. Do you want to proceed with installing psql 15.3? (y/N) " response; \ - if [[ $$response =~ ^[Yy]$$ ]]; then \ - echo "Installing psql 15.3..."; \ - sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $$(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'; \ - wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null; \ - sudo apt update; \ - sudo apt remove postgresql postgresql-contrib; \ - sudo apt install postgresql-15 postgresql-contrib-15; \ - else \ - echo "Aborted installation."; \ - fi; \ - fi installing-psql: @if psql --version | grep -q "15.3"; then \ @@ -113,10 +97,8 @@ installing-docker: fi \ fi - - -kratosconfig: - cd docker/Kratos_config && sudo docker compose -f quickstart.yml up +run-app: + cd app && uvicorn main:app --port=7000 --debug --reload setup: @@ -129,9 +111,4 @@ setup: make installing-psql make environmental-variables make installing-docker - make kratosconfig - - - - - + make run-app diff --git a/makefile_summary.md b/makefile_summary.md index 5fe07971..5906283e 100644 --- a/makefile_summary.md +++ b/makefile_summary.md @@ -20,7 +20,7 @@ - installing-psql:: Checks if PostgreSQL version 15.3 is installed. If not, it prompts the user to install it and then installs it using sudo apt install. - environmental-variables:: Makes a script named setup.sh executable and then runs it. This script likely sets certain environment variables needed for the project. - installing-docker:: Checks if Docker version 24.0.1 or above is installed. If not, it prompts the user to install it and then installs it using the official Docker repository. -- kratosconfig:: Navigates to the docker/Kratos_config folder and runs docker compose -f quickstart.yml up to start Docker containers for the project. +- run-app:: Navigates to the cd app folder and runs uvicorn main:app --port=7000 --debug --reload to start the app ## Default Target: From cca9c32cd1e2f896616b9d631d6e486df50bf5c6 Mon Sep 17 00:00:00 2001 From: "Joel.Johnson" Date: Thu, 29 Aug 2024 16:56:59 +0530 Subject: [PATCH 3/3] updated the code --- makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index aeabf0d9..a137ee3e 100644 --- a/makefile +++ b/makefile @@ -98,7 +98,9 @@ installing-docker: fi run-app: - cd app && uvicorn main:app --port=7000 --debug --reload + source vachan-ENV/bin/activate && \ + cd app && \ + uvicorn main:app --port=7000 --reload setup: