Skip to content

Commit

Permalink
Merge branch 'develop' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurVardevanyan committed Nov 4, 2021
2 parents 204c33c + bf8240a commit 537fa2f
Show file tree
Hide file tree
Showing 19 changed files with 184 additions and 270 deletions.
75 changes: 36 additions & 39 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,45 @@ on:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get install mysql-server
sudo apt-get install python3-pip libmysqlclient-dev
python -m pip install --upgrade pip
python -m pip install flake8
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Setup Database
run: |
sudo /etc/init.d/mysql start
sudo mysql -uroot -proot -Bse "CREATE USER 'spotifyTest'@'localhost' IDENTIFIED BY 'spotifyTest';"
sudo mysql -uroot -proot -Bse "GRANT ALL PRIVILEGES ON *.* TO 'spotifyTest'@'localhost';"
sudo mysql -uroot -proot -Bse "flush privileges;"
sudo mysql -uroot -proot -Bse "create database spotifyTest;"
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with Django
run: |
echo "[client]
host = localhost
database = spotifyTest
user = spotifyTest
password = spotifyTest
default-character-set = utf8"> AnalyticsforSpotify/my.cnf
python3 manage.py test
env:
TEST: test
- name: Coveralls Python
uses: AndreMiras/coveralls-python-action@master
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get install mysql-server
sudo apt-get install python3-pip libmysqlclient-dev
python -m pip install --upgrade pip
python -m pip install flake8
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Setup Database
run: |
sudo /etc/init.d/mysql start
sudo mysql -uroot -proot -Bse "CREATE USER 'spotifyTest'@'localhost' IDENTIFIED BY 'spotifyTest';"
sudo mysql -uroot -proot -Bse "GRANT ALL PRIVILEGES ON *.* TO 'spotifyTest'@'localhost';"
sudo mysql -uroot -proot -Bse "flush privileges;"
sudo mysql -uroot -proot -Bse "create database spotifyTest;"
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with Django
run: |
export DB_HOST=localhost
export DATABASE=spotifyTest
export DB_USER=spotifyTest
export DB_PASSWORD=spotifyTest
python3 manage.py test
env:
TEST: test
- name: Coveralls Python
uses: AndreMiras/coveralls-python-action@master
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ cover/*
.coverage
*/my.cnf
*.env
bin/*
lib/*
share/*
man/*
lib64
pyvenv.cfg
76 changes: 20 additions & 56 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ variables:
stages:
- test
- build
- push
- deploy

PythonTests:
Expand All @@ -22,13 +21,10 @@ PythonTests:
MARIADB_ROOT_PASSWORD: root
MARIADB_DATABASE: spotify
before_script:
- |
echo "[client]
host = mariadb
database = spotify
user = root
password = root
default-character-set = utf8"> AnalyticsforSpotify/my.cnf
- export DB_HOST=mariadb
- export DATABASE=spotify
- export DB_USER=root
- export DB_PASSWORD=root
- apt-get update
- apt-get install -y libmariadb-dev gcc
- python -m pip install --upgrade pip
Expand All @@ -53,46 +49,6 @@ DockerBuild:
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH || true
- docker build --network host --cache-from $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA

PushProduction:
stage: push
image: docker:latest
variables:
GIT_STRATEGY: none
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
services:
- name: docker:dind
alias: docker
command: ["--tls=false"]
only:
- production
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH

PushDevelop:
stage: push
image: docker:latest
variables:
GIT_STRATEGY: none
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
services:
- name: docker:dind
alias: docker
command: ["--tls=false"]
only:
- develop
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH

Expand All @@ -108,14 +64,22 @@ DeployKubernetes:
- sed -i "s/<VERSION>/${CI_COMMIT_SHA}/g" kubernetes/deployment.yaml
- kubectl apply -f kubernetes/deployment.yaml

- sed -i "s,<CLIENT_ID>,${CLIENT_ID},g" kubernetes/configmap.yaml
- sed -i "s/<CLIENT_SECRET>/${CLIENT_SECRET}/g" kubernetes/configmap.yaml
- sed -i "s,<REDIRECT_URL>,${REDIRECT_URL},g" kubernetes/configmap.yaml
- sed -i "s,<HOST>,${HOST},g" kubernetes/configmap.yaml
- sed -i "s,<DATABASE>,${DATABASE},g" kubernetes/configmap.yaml
- sed -i "s,<USER>,${USER},g" kubernetes/configmap.yaml
- sed -i "s,<PASSWORD>,${PASSWORD},g" kubernetes/configmap.yaml
- kubectl apply -f kubernetes/configmap.yaml
- CLIENT_ID=$(echo -n ${CLIENT_ID} | base64 -w 0 | tr -d \\n)
- CLIENT_SECRET=$(echo -n ${CLIENT_SECRET} | base64 -w 0 | tr -d \\n)
- REDIRECT_URL=$(echo -n ${REDIRECT_URL} | base64 -w 0 | tr -d \\n)
- DB_HOST=$(echo -n ${DB_HOST} | base64 -w 0 | tr -d \\n)
- DATABASE=$(echo -n ${DATABASE} | base64 -w 0 | tr -d \\n)
- DB_USER=$(echo -n ${DB_USER} | base64 -w 0 | tr -d \\n)
- DB_PASSWORD=$(echo -n ${DB_PASSWORD} | base64 -w 0 | tr -d \\n)

- sed -i "s,<CLIENT_ID>,${CLIENT_ID},g" kubernetes/secret.yaml
- sed -i "s/<CLIENT_SECRET>/${CLIENT_SECRET}/g" kubernetes/secret.yaml
- sed -i "s,<REDIRECT_URL>,${REDIRECT_URL},g" kubernetes/secret.yaml
- sed -i "s,<DB_HOST>,${DB_HOST},g" kubernetes/secret.yaml
- sed -i "s,<DATABASE>,${DATABASE},g" kubernetes/secret.yaml
- sed -i "s,<DB_USER>,${DB_USER},g" kubernetes/secret.yaml
- sed -i "s,<DB_PASSWORD>,${DB_PASSWORD},g" kubernetes/secret.yaml
- kubectl apply -f kubernetes/secret.yaml

- kubectl apply -f kubernetes/service.yaml

Expand Down
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"files.insertFinalNewline": true,
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.tabSize": 4,
"editor.tabSize": 2,
"editor.renderControlCharacters": true,
"editor.renderWhitespace": "all",

}
"python.pythonPath": "bin/python", // Python VENV
}
74 changes: 7 additions & 67 deletions AnalyticsforSpotify/settings.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
"""
Django settings for AnalyticsforSpotify project.
Generated by 'django-admin startproject' using Django 3.0.5.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""


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/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'LocalAcessOnly'


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = False

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'webBackend.apps.WebBackendConfig',
'django_nose',
]
Expand All @@ -57,60 +39,25 @@
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
# Local Only Acesss 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', # Comment for Testing
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
CORS_ORIGIN_ALLOW_ALL = True

CORS_ORIGIN_ALLOW_ALL = False # True For Testing

ROOT_URLCONF = 'AnalyticsforSpotify.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': BASE_DIR + '/AnalyticsforSpotify/my.cnf',
},
'NAME': os.environ.get('DATABASE'),
'USER': os.environ.get('DB_USER'),
'PASSWORD': os.environ.get('DB_PASSWORD'),
'HOST': os.environ.get('DB_HOST'),
}
}
WSGI_APPLICATION = 'AnalyticsforSpotify.wsgi.application'

# Password validation
# https://docs.djangoproject.com/en/3.0/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',
},
]

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
Expand All @@ -131,17 +78,10 @@
},
}

# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Detroit'

USE_I18N = True

USE_L10N = True

USE_TZ = True

SESSION_COOKIE_HTTPONLY = True
Expand Down
19 changes: 2 additions & 17 deletions AnalyticsforSpotify/urls.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
"""AnalyticsforSpotify URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
"""AnalyticsforSpotify URL Configuration"""
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path('analytics/', include('webBackend.urls')),
path('', include('webBackend.urls')),
path('spotify/', include('webBackend.urls')),

path('analytics/', include('webBackend.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
13 changes: 2 additions & 11 deletions AnalyticsforSpotify/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
"""
WSGI config for AnalyticsforSpotify project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
"""

import os

"""WSGI config for AnalyticsforSpotify project."""
from django.core.wsgi import get_wsgi_application
import os

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'AnalyticsforSpotify.settings')
application = get_wsgi_application()
Loading

0 comments on commit 537fa2f

Please sign in to comment.