This repository has been archived on 2025-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
BreCal/misc/Deployment.md

127 lines
4.3 KiB
Markdown

# System deployment
___
## Prerequisites
## Client
Deployment of the productive client:
- create a branch release/pub_<version> from test release branch
- remove all text references to 'test' (changing target url in the process)
- rename application in settings
- change BG_COLOR in settings to #203864
- user deployment publish xml
## Database
## Backend / Flask app
In order to not have complicated and error-prone copying manoevers a direct deployment from the repo is used using git.
### File structure
### Installation steps
1) Created a ssh-key for the user that does the installation on the server following the Github [instructions](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent).
2) Deploy generated key to the Github user account.
3) In the shell, activate ssh-agent and add the key. For example:
```bash
eval ($ssh-agent)
ssh-add ~/.ssh/od_ed25519
```
4) Change to deployment folder
e.g.
```bash
cd /var/www/brecal_test
```
5) Perform sparse checkout on the Flask server subtree
```bash
git clone -n git@github.com:puls200/brecal.git <target_folder>
cd <target_folder>
git sparse-checkout set --no-cone src/server
git checkout
```
6) Database credentials are stored outside the web root, we are using /var/www/secure. Here the file ```connection_data.json``` is placed, a different named copy for each instance.
### Changing Devel / Test / Prod Environment
Please note that in the "develop" branch the environment and paths are set to the "devel" setting. If a deployment is made (to testing or to the production) the scripts ```copytest.sh``` and ```copyprod.sh``` have to be run. These scripts will change the environment and paths to the respective settings.
There is also a script called ```bump-version.sh``` which can be used to upgrade all version entries in the repository.
### Installing Requirements
Python 3.11 & Pip3.11 installation (linux), virtualenv package
Optional, Step 0: Python source installation
Windows (untested):
Python 3.11: https://www.geeksforgeeks.org/download-and-install-python-3-latest-version/
PIP package manager (in command window): py -m ensurepip --upgrade
Virtual Environment 'virtualenv': https://mothergeo-py.readthedocs.io/en/latest/development/how-to/venv-win.html
Linux:
Python 3.11 & the PIP package manager: https://tecadmin.net/how-to-install-python-3-11-on-ubuntu-22-04/
Virtual Environment 'virtualenv'
### Building the Virtual Environment
Create a virtualenv called '.venv' with a specified python version, such as python3.11
All python packages will be installed in the virtual environment. Upon running the application,
make sure to activate the virtual environment before starting it.
Windows: # on windows, provide the full path, as obtained by "where python"
1.) Relocate to the 'brecal' directory
cd brecal
2.) create a virtual environment with the name '.venv'
where python
virtualenv --python {python_path} .venv
3.) activate the virtual environment and install
.venv\Scripts\activate
cd ./src/server
pip install -r requirements.txt
Linux:
1.) Relocate to the 'brecal' directory
cd brecal
2.) create a virtual environment with the name '.venv'
virtualenv --python python311 .venv
3.) activate the virtual environment and install
source .venv/bin/activate
cd ./src/server
pip install -r requirements.txt
### Testing (using 'pytest')
All tests in the directory brecal/src/server/tests can be run automatically with the 'pytest' module It recognizes any function within these
scripts, as these use 'test_'-prefixes. The module can be used to run the tests or even to create coverage reports, which show, what portions
of the directory are still untested. When the pytest module is installed, one can use a single line of code to run all tests.
1.) Relocate to the application's directory
cd brecal/src/server
2.) activate the virtual environment
Windows:
source .venv\Scripts\activate
Linux:
source .venv\bin\activate
3.) run the tests
option1: run pytest as a standalone
pytest tests/
option2: run pytest & coverage report (inspects coverage for the folder 'BreCal' by running each test in 'tests/'
this creates a folder with the name 'coverage_reports', where .html files are created and can be observed by a developer.
the coverage files are typically ignored by .gitignore
pytest --cov BreCal tests/