From 4518228d6936751b310eb4e3c857f065b8da4e58 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Wed, 17 May 2017 14:33:08 +0300 Subject: [PATCH 1/4] Edit GitLab CI --- .gitlab-ci.yml | 18 +++- sikweb/ci-settings.py | 206 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 sikweb/ci-settings.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4c20cd3..6083455 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,15 @@ image: python:3.5 +services: + - postgres:latest + +variables: + POSTGRES_DB: sik + +before_script: + - python -V + - pip install -r requirements.txt + stages: - build - lint @@ -7,15 +17,21 @@ stages: build: stage: build + variables: + DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB" script: - sh ./scripts/autoinstall.sh lint: stage: lint + variables: + DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB" script: - pep8 --count && eslint . test: stage: test + variables: + DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB" script: - - docker-compose run web python manage.py test + - docker-compose run web python manage.py test --settings sikweb.ci-settings diff --git a/sikweb/ci-settings.py b/sikweb/ci-settings.py new file mode 100644 index 0000000..e824f98 --- /dev/null +++ b/sikweb/ci-settings.py @@ -0,0 +1,206 @@ +""" +Django settings for sikweb project. + +Generated by 'django-admin startproject' using Django 1.9. + +For more information on this file, see +https://docs.djangoproject.com/en/1.9/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.9/ref/settings/ +""" + +import os +import logging +from os.path import expanduser +from django.utils.translation import ugettext_lazy as _ + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '7p$85^4ibb^p4-=vs44b7!y0e-zemugze18@a#30&71=a8)dp(' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'corsheaders', + 'webapp', + 'members', + 'infoscreen', + 'rest_framework', + 'django_nose', + 'bootstrap3', + 'django_tables2', +] + +TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' + +NOSE_ARGS = [ + '--with-coverage', + '--cover-package=webapp,members,infoscreen', +] + +MIDDLEWARE_CLASSES = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', + 'corsheaders.middleware.CorsMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] +CORS_ORIGIN_ALLOW_ALL = True + +ROOT_URLCONF = 'sikweb.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': ['templates'], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.template.context_processors.i18n', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + 'django.core.context_processors.static', + ], + }, + }, +] + +WSGI_APPLICATION = 'sikweb.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.9/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'ci', + 'USER': 'postgres', + 'PASSWORD': 'postgres', + 'HOST': 'postgres', + 'PORT': '5432', + }, +} + +# Password validation +# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES': ( + 'rest_framework.permissions.IsAuthenticated', + 'rest_framework.permissions.DjangoModelPermissions', + ), + 'DEFAULT_THROTTLE_CLASSES': ( + 'members.throttles.BurstRateThrottle', + 'members.throttles.SustainedRateThrottle' + ), + 'DEFAULT_THROTTLE_RATES': { + 'burst': '60/min', + 'sustained': '1000/day' + }, +} + +# Email settings (tested working with gmail) +EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +EMAIL_USE_TLS = True +EMAIL_HOST='smtp.gmail.com' +EMAIL_PORT=587 +EMAIL_HOST_USER = '@gmail.com' +EMAIL_HOST_PASSWORD = '' +DEFAULT_EMAIL_FROM = 'SIK Viestintä ' + + +#ReCaptcha +# http://www.yaconiello.com/blog/integrating-google-recaptcha-to-django/ + +GOOGLE_RECAPTCHA_SITE_KEY = "YOUR-PUBLIC-KEY" +GOOGLE_RECAPTCHA_SECRET_KEY = "YOUR-PRIVATE-KEY" + +#Logger level + +LOGGERLEVEL = logging.INFO +LOGPATH = "logs/debug.log" + +# Internationalization +# https://docs.djangoproject.com/en/1.9/topics/i18n/ + +LANGUAGES = ( + ('en', _('English')), + ('fi', _('Finnish')), +) + +LANGUAGE_CODE = 'fi' + +LOCALE_PATHS = ( + os.path.join(BASE_DIR, 'locale'), +) + +print("LOCALE_PATHS: {}".format(LOCALE_PATHS)) + +TIME_ZONE = 'Europe/Helsinki' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.9/howto/static-files/ +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + 'django.contrib.staticfiles.finders.FileSystemFinder', +) +STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static') +STATICFILES_DIRS = ( + os.path.join(BASE_DIR, 'global_static'), +) +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') +MEDIA_URL = '/media/' + +HSL_USERHASH = 'YOUR HSL USERHASH HERE' +HSL_DEPARTURE_THRESHOLD = 8 +HSL_HURRY_THRESHOLD = 13 From ea0808fae03d7bb51ba66cc55d6ea9fed9dd491a Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Wed, 17 May 2017 14:39:28 +0300 Subject: [PATCH 2/4] Edit GitLab build sequence --- .gitlab-ci.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6083455..f1a45ba 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,15 +12,24 @@ before_script: stages: - build - - lint - test + - lint build: stage: build variables: DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB" script: - - sh ./scripts/autoinstall.sh + - cp sikweb/ci-settings.py sikweb/settings.py + - python manage.py migrate --noinput + - python manage.py createdefaultadmin + +test: + stage: test + variables: + DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB" + script: + - docker-compose run web python manage.py test lint: stage: lint @@ -29,9 +38,3 @@ lint: script: - pep8 --count && eslint . -test: - stage: test - variables: - DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB" - script: - - docker-compose run web python manage.py test --settings sikweb.ci-settings From aeacbaa088648d6d19943ba4d4af451ca062db96 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Wed, 17 May 2017 14:45:00 +0300 Subject: [PATCH 3/4] Setup postgres correctly for CI --- .gitlab-ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f1a45ba..05f6fb0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,9 @@ services: - postgres:latest variables: - POSTGRES_DB: sik + POSTGRES_DB: ci + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres before_script: - python -V From 866e665ff92842cadf2241889f4e28db50e9bba3 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Wed, 17 May 2017 14:50:12 +0300 Subject: [PATCH 4/4] Fix brain fart in .gitlab-ci.yml --- .gitlab-ci.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 05f6fb0..b938d98 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,27 +11,20 @@ variables: before_script: - python -V - pip install -r requirements.txt + - cp sikweb/ci-settings.py sikweb/settings.py + - python manage.py migrate --noinput + - python manage.py createdefaultadmin stages: - - build - test - lint -build: - stage: build - variables: - DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB" - script: - - cp sikweb/ci-settings.py sikweb/settings.py - - python manage.py migrate --noinput - - python manage.py createdefaultadmin - test: stage: test variables: DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB" script: - - docker-compose run web python manage.py test + - python manage.py test lint: stage: lint