Fakultas Ilmu Komputer UI

Commit a520ec33 authored by Putu Agastya's avatar Putu Agastya
Browse files

[CHORES] Setup CI/CD

parent 99944dd1
Pipeline #37368 failed with stages
in 1 minute and 15 seconds
# Created by https://www.gitignore.io/api/venv,django,python,visualstudiocode
# Edit at https://www.gitignore.io/?templates=venv,django,python,visualstudiocode
### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
db.sqlite3-journal
media
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
# <django-project-name>/staticfiles/
### Django.Python Stack ###
# Byte-compiled / optimized / DLL files
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
### Python ###
# Byte-compiled / optimized / DLL files
# C extensions
# Distribution / packaging
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
# Installer logs
# Unit test / coverage reports
# Translations
# Scrapy stuff:
# Sphinx documentation
# PyBuilder
# pyenv
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
# celery beat schedule file
# SageMath parsed files
# Spyder project settings
# Rope project settings
# Mr Developer
# mkdocs documentation
# mypy
# Pyre type checker
### venv ###
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
pyvenv.cfg
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
pip-selfcheck.json
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
# End of https://www.gitignore.io/api/venv,django,python,visualstudiocode
#misc
__pycache__/
db.sqlite3
.coverage
htmlcov/
\ No newline at end of file
stages:
- test
- sonarqube
- deploy
UnitTest:
image: python:3.7
stage: test
coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+)%/'
before_script:
- pip install -r requirements.txt
- python manage.py makemigrations
- python manage.py migrate
- python manage.py collectstatic --no-input
when: on_success
script:
- coverage run --include="./*" --omit="manage.py,digipus/*,env/*" manage.py test
- coverage report -m
- coverage xml
artifacts:
paths:
- coverage.xml
SonarScanner:
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [""]
stage: sonarqube
script:
- sonar-scanner
-Dsonar.host.url=https://pmpl.cs.ui.ac.id/sonarqube
-Dsonar.login=$SONARQUBE_TOKEN
-Dsonar.branch.name=$CI_COMMIT_REF_NAME
-Dsonar.projectKey=$SONARQUBE_PROJECT_KEY
Staging:
image: ruby:2.4
stage: deploy
only:
refs:
- staging
before_script:
- gem install dpl
- wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
script:
- dpl --provider=heroku --app=$HEROKU_APPNAME_STAGING --api-key=$HEROKU_APIKEY
- export HEROKU_API_KEY=$HEROKU_APIKEY
- heroku run --app $HEROKU_APPNAME_STAGING migrate
environment:
name: staging
url: $HEROKU_APP_HOST_STAGING
# Deployment:
# image: ruby:2.4
# stage: deploy
# only:
# refs:
# - master
# before_script:
# - gem install dpl
# - wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
# script:
# - dpl --provider=heroku --app=$HEROKU_APPNAME --api-key=$HEROKU_APIKEY
# - export HEROKU_API_KEY=$HEROKU_APIKEY
# - heroku run --app $HEROKU_APPNAME migrate
# environment:
# name: production
# url: $HEROKU_APP_HOST
{
"python.pythonPath": "env\\Scripts\\python.exe"
}
\ No newline at end of file
migrate: bash deployment.sh
web: gunicorn digipus.wsgi --log-file -
#!/bin/bash
python manage.py makemigrations
python manage.py migrate
......@@ -10,6 +10,9 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
from decouple import config
import dj_database_url
import django_heroku
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
......@@ -20,10 +23,10 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '$!!9pqc0tgj97djgjb&x=e05x61(ts77fwv_f&vjgr7e=2$tyd'
SECRET_KEY = config('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = config('DEBUG', cast=bool)
ALLOWED_HOSTS = ['*']
......@@ -42,6 +45,7 @@ INSTALLED_APPS = [
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
......@@ -73,15 +77,28 @@ WSGI_APPLICATION = 'digipus.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
is_local = config('IS_LOCAL', cast=bool, default=False)
is_heroku = config('IS_HEROKU', cast=bool, default=False)
if is_local:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': config('DB_NAME'),
'USER': config('DB_USER'),
'PASSWORD': config('DB_PASSWORD'),
'HOST': config('DB_HOST'),
'PORT': '',
}
}
}
if is_heroku:
database_url = os.getenv("DATABASE_URL")
DATABASES["default"] = dj_database_url.parse(database_url, conn_max_age=600)
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static"), ]
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
......@@ -119,3 +136,19 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
STORAGE_TYPE = config('STORAGE_TYPE', default="normal")
if STORAGE_TYPE == 'normal':
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
# Add configuration for static files storage using whitenoise
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (BASE_DIR + '/static',)
COMPRESS_ROOT = BASE_DIR + '/static/'
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
\ No newline at end of file
asgiref==3.2.5
autopep8==1.5
dj-database-url==0.5.0
Django==3.0.3
django-heroku==0.3.1
gunicorn==20.0.4
psycopg2==2.8.4
pycodestyle==2.5.0
python-decouple==3.3
pytz==2019.3
sqlparse==0.3.1
\ No newline at end of file
sqlparse==0.3.1
whitenoise==5.0.1
\ No newline at end of file
# SonarScanner properties file
## Server
sonar.host.url=https://pmpl.cs.ui.ac.id/sonarqube
sonar.login=$SONARQUBE_TOKEN
## Project configuration
sonar.projectKey=$SONARQUBE_PROJECT_KEY
## Path to sources
sonar.sources=.
sonar.exclusions=**/migrations/**, **/__init__.py, digipus/**, **/test.py, manage.py
#sonar.inclusions=
## Path to tests
sonar.tests=.
#sonar.test.exclusions=
sonar.test.inclusions=**/test.py
## Source encoding
sonar.sourceEncoding=UTF-8
## Branch analysis
sonar.branch.name=$CI_COMMIT_REF_NAME
## Coverage Report
sonar.python.coverage.reportPath=coverage.xml
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment