diff --git a/.gitignore b/.gitignore index c8dd7299..f37d9719 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -config.cfg -*.env +/config.cfg +/*.env *.sqlite .vscode custom.css diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..c0d85bc2 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,22 @@ +image: docker/compose +services: + - docker:dind +cache: + key: "$CI_COMMIT_REF_SLUG" + paths: + - /var/lib/docker + +# build: +# stage: build +# script: +# - cp utils/gitlabci/* . +# - docker-compose build + +UI_Test: + stage: test + script: + - cp utils/gitlabci/* . + - docker-compose up -d + - ./utils/run_migrations.sh + - ./utils/tests.sh + - docker-compose down diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 00000000..d629e713 --- /dev/null +++ b/.pylintrc @@ -0,0 +1 @@ +ignored-classes=SQLObject,Registrant,scoped_session diff --git a/app/tests/utils.py b/app/tests/utils.py index 214630ec..782bb1de 100644 --- a/app/tests/utils.py +++ b/app/tests/utils.py @@ -16,6 +16,7 @@ def recreate_db(): populate(db.session) db.session.commit() + @pytest.fixture def client(): app.config["TESTING"] = True diff --git a/requirements.txt b/requirements.txt index f840f58d..9473f9f8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,3 +23,4 @@ redis~=3.3 psycopg2~=2.7 pytest ~= 5.3 +pytest-cov ~= 2.8 diff --git a/utils/bash.sh b/utils/bash.sh index 8a3c6a0e..e39e0627 100755 --- a/utils/bash.sh +++ b/utils/bash.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Open SSH to app instance diff --git a/utils/create_migration.sh b/utils/create_migration.sh index 910344c5..4c739371 100755 --- a/utils/create_migration.sh +++ b/utils/create_migration.sh @@ -1,9 +1,9 @@ -#!/bin/bash +#!/bin/sh # Create a database migration, and copy it back to the host. -docker exec -it contentdb_app_1 sh -c "FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db migrate" -docker exec -u root -it contentdb_app_1 sh -c "cp /home/cdb/migrations/versions/* /source/migrations/versions/" +docker exec contentdb_app_1 sh -c "FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db migrate" +docker exec -u root contentdb_app_1 sh -c "cp /home/cdb/migrations/versions/* /source/migrations/versions/" USER=$(whoami) sudo chown -R $USER:$USER migrations/versions diff --git a/utils/db.sh b/utils/db.sh index f7f6af29..1ad5cc81 100755 --- a/utils/db.sh +++ b/utils/db.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Open SQL console for the database diff --git a/utils/gitlabci/config.cfg b/utils/gitlabci/config.cfg new file mode 100644 index 00000000..b34934f8 --- /dev/null +++ b/utils/gitlabci/config.cfg @@ -0,0 +1,31 @@ +USER_APP_NAME="Content DB" +SERVER_NAME="localhost:5123" +BASE_URL="http://" + SERVER_NAME + +SECRET_KEY="changeme" +WTF_CSRF_SECRET_KEY="changeme" + +SQLALCHEMY_DATABASE_URI = "postgres://contentdb:password@db:5432/contentdb" + +GITHUB_CLIENT_ID = "" +GITHUB_CLIENT_SECRET = "" + +REDIS_URL='redis://redis:6379' +CELERY_BROKER_URL='redis://redis:6379' +CELERY_RESULT_BACKEND='redis://redis:6379' + +USER_ENABLE_USERNAME = True +USER_ENABLE_REGISTER = False +USER_ENABLE_CHANGE_USERNAME = False +USER_ENABLE_EMAIL = False + +MAIL_UTILS_ERROR_SEND_TO = [""] + +UPLOAD_DIR="/var/cdb/uploads/" +THUMBNAIL_DIR="/var/cdb/thumbnails/" + +TEMPLATES_AUTO_RELOAD = True + +LANGUAGES = { + 'en': 'English', +} diff --git a/utils/gitlabci/config.env b/utils/gitlabci/config.env new file mode 100644 index 00000000..925271c8 --- /dev/null +++ b/utils/gitlabci/config.env @@ -0,0 +1,4 @@ +POSTGRES_USER=contentdb +POSTGRES_PASSWORD=password +POSTGRES_DB=contentdb +FLASK_DEBUG=1 diff --git a/utils/reload.sh b/utils/reload.sh index 2b21e799..5d2f2d11 100755 --- a/utils/reload.sh +++ b/utils/reload.sh @@ -1,5 +1,5 @@ -#!/bin/bash +#!/bin/sh # Hot/live reload - only works in debug mode -docker exec -it contentdb_app_1 sh -c "cp -r /source/* ." +docker exec contentdb_app_1 sh -c "cp -r /source/* ." diff --git a/utils/run_migrations.sh b/utils/run_migrations.sh index d2f0e7b4..64774af9 100755 --- a/utils/run_migrations.sh +++ b/utils/run_migrations.sh @@ -1,5 +1,5 @@ -#!/bin/bash +#!/bin/sh # Run all pending migrations -docker exec -it contentdb_app_1 sh -c "FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db upgrade" +docker exec contentdb_app_1 sh -c "FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db upgrade" diff --git a/utils/tests.sh b/utils/tests.sh index adedcf4a..82df3d15 100755 --- a/utils/tests.sh +++ b/utils/tests.sh @@ -1,3 +1,3 @@ -#!/bin/bash +#!/bin/sh -docker exec -it contentdb_app_1 sh -c "FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py python -m pytest app/tests/ --disable-warnings" +docker exec contentdb_app_1 sh -c "FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py python -m pytest app/tests/ --cov=app --disable-warnings"