mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
Use env variables rather than custom ci scripts
This commit is contained in:
parent
608f47837f
commit
c846e2e65a
5
.github/workflows/coverage.yaml
vendored
5
.github/workflows/coverage.yaml
vendored
@ -1,6 +1,6 @@
|
|||||||
# Perform CI checks, and calculate code coverage
|
# Perform CI checks, and calculate code coverage
|
||||||
|
|
||||||
name: Code Coverage
|
name: SQLite
|
||||||
|
|
||||||
on: ["push", "pull_request"]
|
on: ["push", "pull_request"]
|
||||||
|
|
||||||
@ -10,10 +10,11 @@ jobs:
|
|||||||
# These tests are used for code coverage analysis
|
# These tests are used for code coverage analysis
|
||||||
coverage:
|
coverage:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
INVENTREE_DB_NAME: './test_db.sqlite'
|
INVENTREE_DB_NAME: './test_db.sqlite'
|
||||||
INVENTREE_DB_ENGINE: sqlite3
|
INVENTREE_DB_ENGINE: django.db.backends.sqlite3
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
|
9
.github/workflows/mariadb.yaml
vendored
9
.github/workflows/mariadb.yaml
vendored
@ -7,6 +7,15 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
env:
|
||||||
|
# Database backend configuration
|
||||||
|
INVENTREE_DB_ENGINE: django.db.backends.mysql
|
||||||
|
INVENTREE_DB_USER: root
|
||||||
|
INVENTREE_DB_PASSWORD: password
|
||||||
|
INVENTREE_DB_HOST: '127.0.0.1'
|
||||||
|
INVENTREE_DB_PORT: 3306
|
||||||
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
mariadb:
|
mariadb:
|
||||||
image: mariadb:latest
|
image: mariadb:latest
|
||||||
|
8
.github/workflows/mysql.yaml
vendored
8
.github/workflows/mysql.yaml
vendored
@ -9,6 +9,14 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
env:
|
||||||
|
# Database backend configuration
|
||||||
|
INVENTREE_DB_ENGINE: django.db.backends.mysql
|
||||||
|
INVENTREE_DB_USER: root
|
||||||
|
INVENTREE_DB_PASSWORD: password
|
||||||
|
INVENTREE_DB_HOST: '127.0.0.1'
|
||||||
|
INVENTREE_DB_PORT: 3306
|
||||||
|
|
||||||
services:
|
services:
|
||||||
mysql:
|
mysql:
|
||||||
image: mysql:latest
|
image: mysql:latest
|
||||||
|
9
.github/workflows/postgresql.yaml
vendored
9
.github/workflows/postgresql.yaml
vendored
@ -9,6 +9,15 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
env:
|
||||||
|
# Database backend configuration
|
||||||
|
INVENTREE_DB_ENGINE: django.db.backends.postgresql
|
||||||
|
INVENTREE_DB_USER: inventree
|
||||||
|
INVENTREE_DB_PASSWORD: password
|
||||||
|
INVENTREE_DB_HOST: '127.0.0.1'
|
||||||
|
INVENTREE_DB_PORT: 5432
|
||||||
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres
|
image: postgres
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
"""
|
|
||||||
Configuration file for running tests against a MySQL database.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from InvenTree.settings import *
|
|
||||||
|
|
||||||
# Override the 'test' database
|
|
||||||
if 'test' in sys.argv:
|
|
||||||
print('InvenTree: Running tests - Using MySQL test database')
|
|
||||||
|
|
||||||
DATABASES['default'] = {
|
|
||||||
# Ensure mysql backend is being used
|
|
||||||
'ENGINE': 'django.db.backends.mysql',
|
|
||||||
'NAME': 'inventree',
|
|
||||||
'USER': 'root',
|
|
||||||
'PASSWORD': 'password',
|
|
||||||
'HOST': '127.0.0.1',
|
|
||||||
'PORT': '3306',
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
"""
|
|
||||||
Configuration file for running tests against a MySQL database.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from InvenTree.settings import *
|
|
||||||
|
|
||||||
# Override the 'test' database
|
|
||||||
if 'test' in sys.argv:
|
|
||||||
print('InvenTree: Running tests - Using PostGreSQL test database')
|
|
||||||
|
|
||||||
DATABASES['default'] = {
|
|
||||||
# Ensure postgresql backend is being used
|
|
||||||
'ENGINE': 'django.db.backends.postgresql',
|
|
||||||
'NAME': 'inventree_test_db',
|
|
||||||
'USER': 'inventree',
|
|
||||||
'PASSWORD': 'password',
|
|
||||||
'HOST': '127.0.0.1',
|
|
||||||
'PORT': '5432'
|
|
||||||
}
|
|
@ -319,40 +319,25 @@ MARKDOWNIFY_BLEACH = False
|
|||||||
DATABASES = {}
|
DATABASES = {}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
When running unit tests, enforce usage of sqlite3 database,
|
Configure the database backend based on the user-specified values.
|
||||||
so that the tests can be run in RAM without any setup requirements
|
|
||||||
|
- Primarily this configuration happens in the config.yaml file
|
||||||
|
- However there may be reason to configure the DB via environmental variables
|
||||||
|
- The following code lets the user "mix and match" database configuration
|
||||||
"""
|
"""
|
||||||
if 'test' in sys.argv:
|
|
||||||
logger.info('InvenTree: Running tests - Using sqlite3 memory database')
|
|
||||||
DATABASES['default'] = {
|
|
||||||
# Ensure sqlite3 backend is being used
|
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
|
||||||
# Doesn't matter what the database is called, it is executed in RAM
|
|
||||||
'NAME': 'ram_test_db.sqlite3',
|
|
||||||
}
|
|
||||||
|
|
||||||
# Database backend selection
|
logger.info("Configuring database backend:")
|
||||||
else:
|
|
||||||
"""
|
|
||||||
Configure the database backend based on the user-specified values.
|
|
||||||
|
|
||||||
- Primarily this configuration happens in the config.yaml file
|
# Extract database configuration from the config.yaml file
|
||||||
- However there may be reason to configure the DB via environmental variables
|
db_config = CONFIG.get('database', {})
|
||||||
- The following code lets the user "mix and match" database configuration
|
|
||||||
"""
|
|
||||||
|
|
||||||
logger.info("Configuring database backend:")
|
# If a particular database option is not specified in the config file,
|
||||||
|
# look for it in the environmental variables
|
||||||
|
# e.g. INVENTREE_DB_NAME / INVENTREE_DB_USER / etc
|
||||||
|
|
||||||
# Extract database configuration from the config.yaml file
|
db_keys = ['ENGINE', 'NAME', 'USER', 'PASSWORD', 'HOST', 'PORT']
|
||||||
db_config = CONFIG.get('database', {})
|
|
||||||
|
|
||||||
# If a particular database option is not specified in the config file,
|
for key in db_keys:
|
||||||
# look for it in the environmental variables
|
|
||||||
# e.g. INVENTREE_DB_NAME / INVENTREE_DB_USER / etc
|
|
||||||
|
|
||||||
db_keys = ['ENGINE', 'NAME', 'USER', 'PASSWORD', 'HOST', 'PORT']
|
|
||||||
|
|
||||||
for key in db_keys:
|
|
||||||
if key not in db_config:
|
if key not in db_config:
|
||||||
logger.debug(f" - Missing {key} value: Looking for environment variable INVENTREE_DB_{key}")
|
logger.debug(f" - Missing {key} value: Looking for environment variable INVENTREE_DB_{key}")
|
||||||
env_key = f'INVENTREE_DB_{key}'
|
env_key = f'INVENTREE_DB_{key}'
|
||||||
@ -364,10 +349,10 @@ else:
|
|||||||
else:
|
else:
|
||||||
logger.debug(f' INVENTREE_DB_{key} not found in environment variables')
|
logger.debug(f' INVENTREE_DB_{key} not found in environment variables')
|
||||||
|
|
||||||
# Check that required database configuration options are specified
|
# Check that required database configuration options are specified
|
||||||
reqiured_keys = ['ENGINE', 'NAME']
|
reqiured_keys = ['ENGINE', 'NAME']
|
||||||
|
|
||||||
for key in reqiured_keys:
|
for key in reqiured_keys:
|
||||||
if key not in db_config:
|
if key not in db_config:
|
||||||
error_msg = f'Missing required database configuration value {key} in config.yaml'
|
error_msg = f'Missing required database configuration value {key} in config.yaml'
|
||||||
logger.error(error_msg)
|
logger.error(error_msg)
|
||||||
@ -375,27 +360,27 @@ else:
|
|||||||
print('Error: ' + error_msg)
|
print('Error: ' + error_msg)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Special considerations for the database 'ENGINE' setting.
|
Special considerations for the database 'ENGINE' setting.
|
||||||
It can be specified in config.yaml (or envvar) as either (for example):
|
It can be specified in config.yaml (or envvar) as either (for example):
|
||||||
- sqlite3
|
- sqlite3
|
||||||
- django.db.backends.sqlite3
|
- django.db.backends.sqlite3
|
||||||
- django.db.backends.postgresql
|
- django.db.backends.postgresql
|
||||||
"""
|
"""
|
||||||
|
|
||||||
db_engine = db_config['ENGINE']
|
db_engine = db_config['ENGINE']
|
||||||
|
|
||||||
if db_engine.lower() in ['sqlite3', 'postgresql', 'mysql']:
|
if db_engine.lower() in ['sqlite3', 'postgresql', 'mysql']:
|
||||||
# Prepend the required python module string
|
# Prepend the required python module string
|
||||||
db_engine = f'django.db.backends.{db_engine.lower()}'
|
db_engine = f'django.db.backends.{db_engine.lower()}'
|
||||||
db_config['ENGINE'] = db_engine
|
db_config['ENGINE'] = db_engine
|
||||||
|
|
||||||
db_name = db_config['NAME']
|
db_name = db_config['NAME']
|
||||||
|
|
||||||
logger.info(f"Database ENGINE: '{db_engine}'")
|
logger.info(f"Database ENGINE: '{db_engine}'")
|
||||||
logger.info(f"Database NAME: '{db_name}'")
|
logger.info(f"Database NAME: '{db_name}'")
|
||||||
|
|
||||||
DATABASES['default'] = db_config
|
DATABASES['default'] = db_config
|
||||||
|
|
||||||
CACHES = {
|
CACHES = {
|
||||||
'default': {
|
'default': {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user