diff --git a/.github/workflows/ensan-project.yml b/.github/workflows/ensan-project.yml new file mode 100644 index 000000000..db2b23a7e --- /dev/null +++ b/.github/workflows/ensan-project.yml @@ -0,0 +1,45 @@ +name: Ensan Project - Pull Code + +on: + push: + branches: + - test + - preprod + workflow_dispatch: + + +jobs: + deploy_master_server: + name: Deploy to Master + runs-on: ensan-client-project-runner + if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master' + steps: + - name: Checkout And Restart Project + run: | + echo "** [INFO] Running on branch --> ${{ github.ref }}" + + sudo chmod +x ${{ secrets.ENSAN_PROJECT_PATH }}/master/standard/scripts/pull_code.sh + sudo ${{ secrets.ENSAN_PROJECT_PATH }}/master/standard/scripts/pull_code.sh ${{ secrets.ENSAN_PROJECT_USER }} ${{ secrets.ENSAN_PROJECT_PATH }} standard ${{ secrets.ENSAN_MASTER_SERVICE }} master + + deploy_preprod_server: + name: Deploy to Preprod + runs-on: app-server-runner + if: github.ref == 'refs/heads/preprod' + steps: + - name: Checkout And Restart Project + run: | + echo "** [INFO] Running on branch --> ${{ github.ref }}" + + sudo chmod +x ${{ secrets.ENSAN_APP_PROJECT_PATH }}/preprod/standard/scripts/pull_code.sh + sudo ${{ secrets.ENSAN_APP_PROJECT_PATH }}/preprod/standard/scripts/pull_code.sh ${{ secrets.ENSAN_APP_PROJECT_USER }} ${{ secrets.ENSAN_APP_PROJECT_PATH }} standard ${{ secrets.ENSAN_PREPROD_SERVICE }} preprod + + deploy_test_server: + name: Deploy to Test + runs-on: app-server-runner + if: github.ref == 'refs/heads/test' + steps: + - name: Checkout And Restart Project + run: | + echo "** [INFO] Running on branch --> ${{ github.ref }}" + sudo chmod +x ${{ secrets.ENSAN_APP_PROJECT_PATH }}/test/standard/scripts/pull_code.sh + sudo ${{ secrets.ENSAN_APP_PROJECT_PATH }}/test/standard/scripts/pull_code.sh ${{ secrets.ENSAN_APP_PROJECT_USER }} ${{ secrets.ENSAN_APP_PROJECT_PATH }} standard ${{ secrets.ENSAN_TEST_SERVICE }} test diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..e3695b424 --- /dev/null +++ b/.gitignore @@ -0,0 +1,128 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# 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 diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 000000000..8bc336739 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,2 @@ +# This is a CODEOWNERS file managed by Terraform +* @moutazmuhammad @ahmadaking @ronozoro @hasan-exp @Abubaker-Altaib @AbuzarExp \ No newline at end of file diff --git a/scripts/pull_code.sh b/scripts/pull_code.sh new file mode 100644 index 000000000..e1972757f --- /dev/null +++ b/scripts/pull_code.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Author: Moutaz Muhammad + +set -euo pipefail + +# Validate input parameters +if [ "$#" -lt 5 ]; then + echo "** [ERROR] Usage: $0 " + exit 1 +fi + +PROJECT_USER="$1" +PROJECT_PATH="$2" +REPO="$3" +PROJECT_SERVICE="$4" +BRANCH="$5" + +# Stash changes before pulling +sudo -u "$PROJECT_USER" bash -c "cd '$PROJECT_PATH/$BRANCH/$REPO' && 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 \ No newline at end of file