Merge remote-tracking branch 'origin/master' into preprod_odex25_fleet

# Conflicts:
#	README.md
This commit is contained in:
esraa 2024-10-13 13:45:02 +03:00
commit 972cadbc63
6 changed files with 564 additions and 1 deletions

127
.gitignore vendored Normal file
View File

@ -0,0 +1,127 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
.history
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
parts/
sdist/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# github action
.github/workflows/*yaml

3
CODEOWNERS Normal file
View File

@ -0,0 +1,3 @@
# This is a CODEOWNERS file managed by Terraform
.github/workflows/ @moutazmuhammad
* @moutazmuhammad @ahmadaking @ronozoro @hasan-exp @Abubaker-Altaib @eslamabady

123
README.md
View File

@ -1,2 +1,123 @@
# odex25-standard-modules
This Repo contains general standard modules for all projects.
This repository contains general standard modules for all projects.
## Cloning and Pulling Branches
### Clone the Repository
Clone the master branch, use the following command:
```sh
git clone -b master --depth=1 https://github.com/expsa/odex25-standard-modules.git STANDARD_MODULES
cd STANDARD_MODULES
chmod +x clone.sh pull.sh
```
### Clone or Pull Branches
To clone or pull branches, use the provided scripts:
1. Clone Branches: Replace YOUR_USERNAME and YOUR_TOKEN with your GitHub username and token.
```sh
./clone.sh YOUR_USERNAME YOUR_TOKEN
```
2. Pull Branches:
- For Test Branches:
```sh
./pull.sh test
```
- For Preprod Branches:
```sh
./pull.sh preprod
```
- For Master Branches:
```sh
./pull.sh master
```
## Branches
### Development Branches
- `dev_odex-event`
- `dev_odex25_accounting`
- `dev_odex25_base`
- `dev_odex25_dms`
- `dev_odex25_fleet`
- `dev_odex25_helpdesk`
- `dev_odex25_hr`
- `dev_odex25_inventory`
- `dev_odex25_maintenance`
- `dev_odex25_mobile`
- `dev_odex25_pos`
- `dev_odex25_project`
- `dev_odex25_purchase`
- `dev_odex25_realstate`
- `dev_odex25_sales`
- `dev_odex25_survey`
- `dev_odex25_transactions`
- `dev_odex25_website`
- `dev_openeducat_erp-14.0.1.0`
- `dev_odex25_ensan`
### Preproduction Branches
- `preprod_odex-event`
- `preprod_odex25_accounting`
- `preprod_odex25_base`
- `preprod_odex25_dms`
- `preprod_odex25_fleet`
- `preprod_odex25_helpdesk`
- `preprod_odex25_hr`
- `preprod_odex25_inventory`
- `preprod_odex25_maintenance`
- `preprod_odex25_mobile`
- `preprod_odex25_pos`
- `preprod_odex25_project`
- `preprod_odex25_purchase`
- `preprod_odex25_realstate`
- `preprod_odex25_sales`
- `preprod_odex25_survey`
- `preprod_odex25_transactions`
- `preprod_odex25_website`
- `preprod_openeducat_erp-14.0.1.0`
- `preprod_odex25_ensan`
### Master Branches
- `master_odex-event`
- `master_odex25_accounting`
- `master_odex25_base`
- `master_odex25_dms`
- `master_odex25_fleet`
- `master_odex25_helpdesk`
- `master_odex25_hr`
- `master_odex25_inventory`
- `master_odex25_maintenance`
- `master_odex25_mobile`
- `master_odex25_pos`
- `master_odex25_project`
- `master_odex25_purchase`
- `master_odex25_realstate`
- `master_odex25_sales`
- `master_odex25_survey`
- `master_odex25_transactions`
- `master_odex25_website`
- `master_openeducat_erp-14.0.1.0`
- `master_odex25_ensan`
## Addons Path
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_base/odex25_base,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_dms/odex25_dms,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_fleet/odex25_fleet,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_helpdesk/odex25_helpdesk,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_hr/odex25_hr,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_inventory/odex25_inventory,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_maintenance/odex25_maintenance,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_mobile/odex25_mobile,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_pos/odex25_pos,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_project/odex25_project,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_purchase/odex25_purchase,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_realstate/odex25_realstate,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_sales/odex25_sales,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/openeducat_erp-14.0.1.0/openeducat_erp-14.0.1.0,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_accounting/odex25_accounting,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_website/odex25_website,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex-event/odex-event,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_transactions/odex25_transactions,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_survey/odex25_survey,\
path_to_dir/STANDARD_MODULES/FOLDER(test,preprod or master)/odex25_ensan/odex25_ensan

138
clone.sh Normal file
View File

@ -0,0 +1,138 @@
#!/bin/bash
# Git repository URL
USERNAME=$1
TOKEN=$2
# Retry limit for failed clone attempts
RETRY_LIMIT=3
# Branch types and their corresponding directories
declare -A branch_dirs=(
["dev"]="test"
["preprod"]="preprod"
["master"]="master"
)
# List of branches
branches=(
"dev_odex-event"
"dev_odex25_accounting"
"dev_odex25_base"
"dev_odex25_dms"
"dev_odex25_fleet"
"dev_odex25_helpdesk"
"dev_odex25_hr"
"dev_odex25_inventory"
"dev_odex25_maintenance"
"dev_odex25_mobile"
"dev_odex25_pos"
"dev_odex25_project"
"dev_odex25_purchase"
"dev_odex25_realstate"
"dev_odex25_sales"
"dev_odex25_survey"
"dev_odex25_transactions"
"dev_odex25_website"
"dev_openeducat_erp-14.0.1.0"
"dev_odex25_ensan"
"preprod_odex-event"
"preprod_odex25_accounting"
"preprod_odex25_base"
"preprod_odex25_dms"
"preprod_odex25_fleet"
"preprod_odex25_helpdesk"
"preprod_odex25_hr"
"preprod_odex25_inventory"
"preprod_odex25_maintenance"
"preprod_odex25_mobile"
"preprod_odex25_pos"
"preprod_odex25_project"
"preprod_odex25_purchase"
"preprod_odex25_realstate"
"preprod_odex25_sales"
"preprod_odex25_survey"
"preprod_odex25_transactions"
"preprod_odex25_website"
"preprod_openeducat_erp-14.0.1.0"
"preprod_odex25_ensan"
"master_odex-event"
"master_odex25_accounting"
"master_odex25_base"
"master_odex25_dms"
"master_odex25_fleet"
"master_odex25_helpdesk"
"master_odex25_hr"
"master_odex25_inventory"
"master_odex25_maintenance"
"master_odex25_mobile"
"master_odex25_pos"
"master_odex25_project"
"master_odex25_purchase"
"master_odex25_realstate"
"master_odex25_sales"
"master_odex25_survey"
"master_odex25_transactions"
"master_odex25_website"
"master_openeducat_erp-14.0.1.0"
"master_odex25_ensan"
)
# Error log file
error_log="clone_error_log.txt" > "$error_log" # Clear log file at the start
# Clone branch function with retry mechanism
clone_branch() {
local branch=$1
local full_path=$2
local attempt=1
while [ $attempt -le $RETRY_LIMIT ]; do
echo "Cloning $branch into $full_path (Attempt $attempt/$RETRY_LIMIT)..."
git clone --depth=1 -b "$branch" "https://$USERNAME:$TOKEN@github.com/expsa/odex25-standard-modules.git" "$full_path"
if [ $? -eq 0 ]; then
echo "Successfully cloned $branch into $full_path"
return 0
else
echo "Failed to clone $branch (Attempt $attempt)."
attempt=$((attempt + 1))
fi
done
# If the retry limit is reached, log the failure
echo "Failed to clone $branch after $RETRY_LIMIT attempts." >> "$error_log"
return 1
}
# Loop through each branch
for branch in "${branches[@]}"; do
# Extract the prefix (dev, preprod, master) and the branch name
prefix="${branch%%_*}"
folder_name="${branch#*_}"
# Determine the base directory based on the prefix
base_dir="${branch_dirs[$prefix]}"
# Full path for the folder inside the corresponding directory
full_path="$base_dir/$folder_name"
# Skip cloning if the folder already exists
if [ -d "$full_path" ]; then
echo "Skipping $branch: already cloned in $full_path"
continue
fi
# Create the directory if it doesn't exist
mkdir -p "$full_path"
# Clone the specific branch with error handling
clone_branch "$branch" "$full_path"
done
# Check if any errors were logged
if [ -s "$error_log" ]; then
echo "Some branches failed to clone. Check $error_log for details."
else
echo "All branches cloned successfully."
fi

139
pull.sh Normal file
View File

@ -0,0 +1,139 @@
#!/bin/bash
# Branch to process (test, preprod, master)
BRANCH=$1
# Retry limit for failed pull attempts
RETRY_LIMIT=3
# Branch types and their corresponding directories
declare -A branch_dirs=(
["dev"]="test"
["preprod"]="preprod"
["master"]="master"
)
# List of branches
branches=(
"dev_odex-event"
"dev_odex25_accounting"
"dev_odex25_base"
"dev_odex25_dms"
"dev_odex25_fleet"
"dev_odex25_helpdesk"
"dev_odex25_hr"
"dev_odex25_inventory"
"dev_odex25_maintenance"
"dev_odex25_mobile"
"dev_odex25_pos"
"dev_odex25_project"
"dev_odex25_purchase"
"dev_odex25_realstate"
"dev_odex25_sales"
"dev_odex25_survey"
"dev_odex25_transactions"
"dev_odex25_website"
"dev_openeducat_erp-14.0.1.0"
"dev_odex25_ensan"
"preprod_odex-event"
"preprod_odex25_accounting"
"preprod_odex25_base"
"preprod_odex25_dms"
"preprod_odex25_fleet"
"preprod_odex25_helpdesk"
"preprod_odex25_hr"
"preprod_odex25_inventory"
"preprod_odex25_maintenance"
"preprod_odex25_mobile"
"preprod_odex25_pos"
"preprod_odex25_project"
"preprod_odex25_purchase"
"preprod_odex25_realstate"
"preprod_odex25_sales"
"preprod_odex25_survey"
"preprod_odex25_transactions"
"preprod_odex25_website"
"preprod_openeducat_erp-14.0.1.0"
"preprod_odex25_ensan"
"master_odex-event"
"master_odex25_accounting"
"master_odex25_base"
"master_odex25_dms"
"master_odex25_fleet"
"master_odex25_helpdesk"
"master_odex25_hr"
"master_odex25_inventory"
"master_odex25_maintenance"
"master_odex25_mobile"
"master_odex25_pos"
"master_odex25_project"
"master_odex25_purchase"
"master_odex25_realstate"
"master_odex25_sales"
"master_odex25_survey"
"master_odex25_transactions"
"master_odex25_website"
"master_openeducat_erp-14.0.1.0"
"master_odex25_ensan"
)
# Error log file
error_log="pull_error_log.txt" > "$error_log" # Clear log file at the start
# Function to pull code with retries
pull_branch() {
local branch=$1
local full_path=$2
local attempt=1
while [ $attempt -le $RETRY_LIMIT ]; do
echo "Pulling $branch into $full_path (Attempt $attempt/$RETRY_LIMIT)..."
# Navigate to the directory and pull the latest changes
cd "$full_path" || { echo "Failed to access $full_path"; exit 1; }
git pull origin "$branch"
local pull_status=$?
# Return to the previous directory
cd - || exit 1
if [ $pull_status -eq 0 ]; then
echo "Successfully pulled $branch into $full_path"
return 0
else
echo "Failed to pull $branch (Attempt $attempt)."
attempt=$((attempt + 1))
fi
done
# If retry limit is reached, log the failure
echo "Failed to pull $branch after $RETRY_LIMIT attempts." >> "$error_log"
return 1
}
# Loop through each branch
for branch in "${branches[@]}"; do
prefix="${branch%%_*}"
# Check if the branch matches the input and the prefix is valid
if [ "$BRANCH" == "${branch_dirs[$prefix]}" ]; then
folder_name="${branch#*_}"
full_path="$BRANCH/$folder_name"
# Skip the branch if the directory does not exist
if [ ! -d "$full_path" ]; then
echo "Skipping $branch: $full_path does not exist"
continue
fi
# Pull the branch with error handling
pull_branch "$branch" "$full_path"
fi
done
# Check if any errors were logged
if [ -s "$error_log" ]; then
echo "Some branches failed to pull. Check $error_log for details."
else
echo "All branches pulled successfully."
fi

35
scripts/pull_code.sh Normal file
View File

@ -0,0 +1,35 @@
#!/bin/bash
# Author: Moutaz Muhammad <M.MUHAMMAD@exp-sa.com>
set -euo pipefail
# Validate input parameters
if [ "$#" -lt 5 ]; then
echo "** [ERROR] Usage: $0 <project_user> <project_path> <project_service> <stage> <folder> <branch>"
exit 1
fi
PROJECT_USER="$1"
PROJECT_PATH="$2"
PROJECT_SERVICE="$3"
STAGE="$4"
FOLDER="$5"
BRANCH="$6"
# Stash changes before pulling
sudo -u "$PROJECT_USER" bash -c "cd '$PROJECT_PATH/$STAGE/$FOLDER' && git stash && git stash clear && git pull origin '$BRANCH'"
if [ $? -eq 0 ]; then
echo "** [INFO] Git pull origin $BRANCH command executed successfully."
else
echo "** [ERROR] Git pull origin $BRANCH command failed."
exit 1
fi
# Restart the project service
sudo systemctl restart "$PROJECT_SERVICE"
if [ $? -eq 0 ]; then
echo "** [INFO] $BRANCH service has been restarted."
else
echo "** [ERROR] Failed to restart $BRANCH service."
exit 1
fi