diff --git a/.dockerignore b/.dockerignore index f758f84..eff55c6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,7 @@ * # except a few +!alembic !src !tests !setup.py diff --git a/Jenkinsfile b/Jenkinsfile index db315e5..5e5c1de 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -25,7 +25,7 @@ node { stage("Test") { tryStep "test", { sh "docker-compose -p dcatd -f ./docker-compose.yml build --no-cache --pull test && " + - "docker-compose -p dcatd -f ./docker-compose.yml run --rm test bash -c 'make test'" + "docker-compose -p dcatd -f ./docker-compose.yml run --rm test make test" }, { sh "docker-compose -p dcatd -f ./docker-compose.yml down" } diff --git a/Makefile b/Makefile index f9963aa..625adef 100644 --- a/Makefile +++ b/Makefile @@ -20,11 +20,11 @@ PYTEST = $(PYTHON) setup.py test PYTEST_COV_OPTS ?= --cov=src --cov-report=term --no-cov-on-fail -test: schema +test: cleanpy schema $(PYTEST) -cov: schema +cov: cleanpy schema $(PYTEST) $(PYTEST_COV_OPTS) @@ -32,7 +32,7 @@ testdep: pip3 install --quiet --upgrade --upgrade-strategy eager -e .[test] && echo 'OK' || echo 'FAILED' -testclean: +testclean: cleanpy @$(RM) .cache .coverage @@ -40,17 +40,17 @@ testclean: # ┃ Installing, building, running ┃ # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -install: +install: cleanpy @echo -n 'Installing... ' @pip3 install --quiet --upgrade --upgrade-strategy eager -e . && echo 'OK' || echo 'FAILED' -dist: +dist: cleanpy $(PYTHON) setup.py sdist -upload: +upload: cleanpy $(PYTHON) setup.py sdist upload -example: +example: cleanpy @echo Starting example server: @docker-compose up api @@ -59,6 +59,10 @@ example: # ┃ Cleaning up ┃ # ┗━━━━━━━━━━━━━┛ +cleanpy: + @echo Removing pyc and pyo files + @find . -type f -name '*.py[co]' -exec rm {} \; + clean: @# From running pytest: $(RM) .coverage .cache diff --git a/alembic/datacatalog/env.py b/alembic/datacatalog/env.py index 058378b..c92fa1d 100644 --- a/alembic/datacatalog/env.py +++ b/alembic/datacatalog/env.py @@ -1,6 +1,7 @@ from __future__ import with_statement +import os from alembic import context -from sqlalchemy import engine_from_config, pool +from sqlalchemy import engine_from_config, pool, create_engine from logging.config import fileConfig # this is the Alembic Config object, which provides @@ -23,6 +24,15 @@ # ... etc. +def get_url(): + """This allows users to override alembic stuff with env vars.""" + envvars = 'DB_USER', 'DB_PASSWORD', 'DB_HOST', 'DB_PORT', 'DB_DATABASE' + confvals = [os.getenv(key, False) for key in envvars] + if all(confvals): + return "postgresql+psycopg2://{}:{}@{}:{}/{}".format(*confvals) + return config.get_main_option("sqlalchemy.url") + + def run_migrations_offline(): """Run migrations in 'offline' mode. @@ -35,7 +45,7 @@ def run_migrations_offline(): script output. """ - url = config.get_main_option("sqlalchemy.url") + url = get_url() context.configure( url=url, target_metadata=target_metadata, literal_binds=True) @@ -50,10 +60,7 @@ def run_migrations_online(): and associate a connection with the context. """ - connectable = engine_from_config( - config.get_section(config.config_ini_section), - prefix='sqlalchemy.', - poolclass=pool.NullPool) + connectable = create_engine(get_url()) with connectable.connect() as connection: context.configure( diff --git a/docker-compose.yml b/docker-compose.yml index d73b5ba..55d3c03 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: POSTGRES_USER: datacatalog POSTGRES_PASSWORD: datacatalog - api: + example: build: context: . depends_on: diff --git a/tests/datacatalog/plugins/test_postgres_config.yml b/tests/datacatalog/plugins/test_postgres_config.yml index 7280642..ef72615 100644 --- a/tests/datacatalog/plugins/test_postgres_config.yml +++ b/tests/datacatalog/plugins/test_postgres_config.yml @@ -13,6 +13,8 @@ storage_postgres: plugins: [] +primarySchema: "" + logging: formatters: default: