FreezeMan is a freezer management system designed to manage the storage and tracking of biological samples in a laboratory environment.
- Dependencies
- Running locally for development
- Running tests
- Creating releases
- Deploying to production
- Database diagram
- Python
virtualenv
- Postgres 9.5 or later (tested on 11 and 12)
- Postgres development headers
- Make & C compiler
Python package dependencies are listed in requirements.txt
.
-
Set up a virtual environment with Python 3.11 or later, and install dependencies into it:
cd backend # move into backend repository directory virtualenv -p python3.11 ./env source env/bin/activate pip3.11 install -r requirements.txt
-
Create a database for the application to use locally in Postgres. The following environment variables (listed here with defaults) can be used to set up the Postgres connection:
export PG_DATABASE=fms export PG_USER=admin export PG_PASSWORD=admin export PG_HOST=127.0.0.1 export PG_PORT=5432
-
By default, experiment run info files are dropped into a folder in the project,
./backend/lims-run-info
. If you want to change that, you can create aFMS_RUN_INFO_PATH
environment variable pointing to a different directory. For linux/Mac, this can be added to your shell configuration.FMS_RUN_INFO_PATH=~/my-lims-run-info export FMS_RUN_INFO_PATH
-
Install the pg_fzy extension for the database:
cd backend/dependencies/pg_fzy && make && sudo make install
-
Run any outstanding migrations:
python ./manage.py migrate
-
Create an application superuser:
python ./manage.py createsuperuser
-
Run the development server:
python ./manage.py runserver
Make sure all database configuration has been done successfully with a user that can create new databases (in order to create the test-specific database.) Then, run the following command:
coverage run ./manage.py test -v 2
-
Update the
VERSION
file in the repository to represent the current version number, according to semantic versioning. -
Squash any migrations between the last version and the new version and name it
vX_Y_Z
where the version reflects the new semantic version number stored in theVERSION
file. There should be at most one migration per version. Do not use.
to separate version components, it breaks Django for some reason. -
Tag a new release on GitHub, following the format
vX.Y.Z
whereX
is the major version,Y
is the minor version, andZ
is the patch version.
-
Use NGINX or Apache HTTPD as a reverse proxy
- Remember to serve static and media files using the proxy instead of Django for security and performance reasons
- Static files are collected to the application
staticfiles/
directory - Media files are kept in the
media/
directory - For example uWSGI and NGINX configurations, see
example.uwsgi.ini
andexample.nginx.conf
respectively
-
Use a WSGI server such as uWSGI or Gunicorn
-
Set a secret key in
settings.py
different from the default repository value for security reasons -
Make sure to set
FMS_DEBUG=False
andFMS_HOST=your.domain.org
in the production environment for security reasons and for the site to function correctly -
Set the
FMS_RUN_INFO_PATH
variable to point to a directory where Freezeman will output run info files to trigger run processing. -
Configure the Postgres connection using any of the following environment variables, where the default value is not sufficient:
PG_DATABASE
: Postgres database name. Default:fms
PG_USER
: Postgres username. Default:admin
PG_PASSWORD
: Postgres user password. Default:admin
PG_HOST
: Postgres database host. Default:localhost
PG_PORT
: Postgres database port. Default:5432
-
Any time a new version is deployed, remember to run the following management commands:
./manage.py collectstatic
- Moves all static files into thestaticfiles/
directory./manage.py migrate
- Migrates the database to the latest version
The pg_fzy
extension is a PostgreSQL C extension that implements the fzy
algorithm. To manage it, here are the useful commands, to be run in the
./dependencies/pg_fzy
directory:
make
: build the shared library (linux-x86_64 included by default)sudo make install
: install it in the postgres extension listsudo make uninstall
: remove it from the postgres extension list
When updating the extension, you might need to run drop extension fzy;
before uninstalling it and
create extension fzy;
after installing it.
After each release, we update our local fms database with the latest data from prod. To update, you need to drop your current fms database and import a new one from a .pgsql file, which someone will generate post-release.
The following shell script shows an example of the steps required on a Linux system:
echo '<<< Drop DB fms >>>'
sudo -u postgres dropdb fms
echo '<<< Create DB fms >>>'
sudo -u postgres createdb fms
sudo -u postgres psql < /home/ufgauthi/Work/freezeman/instance/RollbackDB.pgsql
echo '<<< Set user permission >>>'
sudo -u postgres psql -d fms -c 'ALTER ROLE admin CREATEDB;'
On OS X, you can run these commands in the terminal (replacing the path to the .pgsql file with your own path):
dropdb fms
createdb fms
psql -d fms < /Users/ckostiw/Downloads/2022-05-04.pgsql
psql -d fms -c 'ALTER ROLE admin CREATEDB;'
Note: You may need to use
sudo -u <USER>
where<USER>
is the user created for postgres (usually named "postgres") by the postgres installer. The downloadable installer from postgressql.org creates a 'postgres' user. If you install with homebrew then no user is created and you can use your MacOS user without sudo.
After importing the new db data you will need to run migrations to bring the db up to date:
cd backend
python ./manage.py migrate
To run a specific migration, this command can be used where, as an example, 0039
refers to
a specific migration file, 0039_v3_9_0.py
:
python ./manage.py migrate fms_core 0039