From 189326b30f27af83735c9c81e99dfa8298706946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Tue, 29 Dec 2020 21:43:31 +0100 Subject: [PATCH] make it kubernetes friendly --- .drone.yml | 25 +++++++++++ .gitignore | 1 + .idea/.gitignore | 8 ++++ .idea/geogame.iml | 30 +++++++++++++ .idea/inspectionProfiles/Project_Default.xml | 23 ++++++++++ .../inspectionProfiles/profiles_settings.xml | 6 +++ .idea/misc.xml | 4 ++ .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ Dockerfile | 16 +++++++ geogame/settings.py | 42 +++++++------------ requirements.txt | 4 +- 12 files changed, 145 insertions(+), 28 deletions(-) create mode 100644 .drone.yml create mode 100644 .idea/.gitignore create mode 100644 .idea/geogame.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Dockerfile diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..087f1d5 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,25 @@ +kind: pipeline +type: docker +name: default + +steps: + - name: code-analysis + image: aosapps/drone-sonar-plugin + settings: + sonar_host: + from_secret: SONAR_HOST + sonar_token: + from_secret: SONAR_CODE + + - name: kaniko + image: banzaicloud/drone-kaniko + settings: + registry: registry.kmlabz.com + repo: tormakris/${DRONE_REPO_NAME} + username: + from_secret: DOCKER_USERNAME + password: + from_secret: DOCKER_PASSWORD + tags: + - latest + - ${DRONE_BUILD_NUMBER} diff --git a/.gitignore b/.gitignore index 98cd6fb..68f24de 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ env_secret_key.txt /static !.gitignore gunicorn.conf.py +venv/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..f0d461a --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/../../../../../../../:\Users\torma\Documents\projects\geogame\.idea/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/geogame.iml b/.idea/geogame.iml new file mode 100644 index 0000000..0205cda --- /dev/null +++ b/.idea/geogame.iml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..8619759 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,23 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d2f1080 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..caebe26 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b8b1f71 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM python:3-slim + +ENV TZ Europe/Budapest +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +WORKDIR /app + +COPY requirements.txt ./ + +RUN pip install --no-cache-dir -r requirements.txt && rm -rf requirements.txt + +COPY ./geogame . + +EXPOSE 8080 + +ENTRYPOINT ["gunicorn", "-b", "0.0.0.0:8080", "--workers", "4", "--threads", "4", "wsgi:application"] diff --git a/geogame/settings.py b/geogame/settings.py index b433889..e6e9561 100644 --- a/geogame/settings.py +++ b/geogame/settings.py @@ -15,13 +15,11 @@ import os # 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/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -with open(os.path.join(BASE_DIR, "env_secret_key.txt")) as secret_key: - SECRET_KEY = secret_key.read().strip() +SECRET_KEY = os.environ.get("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False @@ -53,7 +51,6 @@ INSTALLED_APPS = [ 'geogame.main', 'django_countries', - ] MIDDLEWARE = [ @@ -71,7 +68,7 @@ ROOT_URLCONF = 'geogame.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [os.path.join(BASE_DIR, "geogame/templates"),], + 'DIRS': [os.path.join(BASE_DIR, "geogame/templates"), ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -86,21 +83,19 @@ TEMPLATES = [ WSGI_APPLICATION = 'geogame.wsgi.application' - # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases -with open(os.path.join(BASE_DIR, "env_db.txt")) as db_pw: - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'geogame', - 'USER': 'geogame', - 'PASSWORD': db_pw.read().strip(), - 'HOST': 'localhost', - 'PORT': '', - } +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'geogame', + 'USER': 'geogame', + 'PASSWORD': os.environ.get("DB_PW"), + 'HOST': '192.168.8.4', + 'PORT': '5432', } +} # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators @@ -120,7 +115,6 @@ AUTH_PASSWORD_VALIDATORS = [ }, ] - # Internationalization # https://docs.djangoproject.com/en/2.2/topics/i18n/ @@ -143,16 +137,12 @@ STATIC_ROOT = os.path.join(BASE_DIR, "static") MEDIA_ROOT = os.path.join(BASE_DIR, "media") MEDIA_URL = '/attachments/' - -with open(os.path.join(BASE_DIR, "env_email_key.txt")) as email_key: - SENDGRID_API_KEY = email_key.read().strip() -EMAIL_HOST = 'smtp.sendgrid.net' -EMAIL_HOST_USER = 'apikey' -EMAIL_HOST_PASSWORD = SENDGRID_API_KEY -EMAIL_PORT = 587 +EMAIL_HOST = '192.168.8.7' +EMAIL_HOST_USER = '' +EMAIL_HOST_PASSWORD = '' +EMAIL_PORT = 25 EMAIL_USE_TLS = True -DEFAULT_FROM_EMAIL = "admin@peakdistrictwalks.org.uk" - +DEFAULT_FROM_EMAIL = "geogame@kmlabz.com" # AUTH diff --git a/requirements.txt b/requirements.txt index 8e3d468..0125cfe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,10 +11,10 @@ django-extensions==2.2.1 django-starfield==1.0.post1 geographiclib==1.49 geopy==1.20.0 -gunicorn==19.9.0 +gunicorn idna==2.8 oauthlib==3.1.0 -psycopg2==2.8.3 +psycopg2-binary python3-openid==3.1.0 pytz==2019.2 requests==2.22.0