Fakultas Ilmu Komputer UI

Commit 10b4f6e4 authored by addffa's avatar addffa
Browse files

Merge branch 'testing' of...

Merge branch 'testing' of https://gitlab.cs.ui.ac.id/sizakat/5.0/sizakat-backend into PBI-15-pencatatan_mustahik
parents 3376c467 630d488d
plugins:
pep8:
enabled: true
pylint:
enabled: true
plugins:
- django
isort:
enabled: true
radon:
enabled: true
sonar-python:
enabled: true
env env
*.env *.env
*.sqlite3 *.sqlite3
.git* .git*
__pycache__ __pycache__
*.pyc *.pyc
# https://editorconfig.org/
root = true
[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8
# Docstrings and comments use max_line_length = 79
[*.py]
max_line_length = 119
# The JSON files contain newlines inconsistently
[*.json]
indent_size = 2
insert_final_newline = ignore
# Makefiles always use tabs for indentation
[Makefile]
indent_style = tab
# https://git-scm.com/docs/gitattributes/#_end_of_line_conversion
* text=auto
# Django #
*.log # Created by https://www.toptal.com/developers/gitignore/api/django
*.pot # Edit at https://www.toptal.com/developers/gitignore?templates=django
*.pyc
__pycache__ ### Django ###
db.sqlite3 *.log
media *.pot
*.pyc
# Backup files # __pycache__/
*.bak local_settings.py
db.sqlite3
# If you are using PyCharm # db.sqlite3-journal
.idea/**/workspace.xml media
.idea/**/tasks.xml
.idea/dictionaries # If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
.idea/**/dataSources/ # in your Git repository. Update and uncomment the following line accordingly.
.idea/**/dataSources.ids # <django-project-name>/staticfiles/
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml ### Django.Python Stack ###
.idea/**/sqlDataSources.xml # Byte-compiled / optimized / DLL files
.idea/**/dynamic.xml *.py[cod]
.idea/**/uiDesigner.xml *$py.class
.idea/**/gradle.xml
.idea/**/libraries # C extensions
*.iws /out/ *.so
# Python # # Distribution / packaging
*.py[cod] .Python
*$py.class build/
develop-eggs/
# Distribution / packaging dist/
.Python build/ downloads/
develop-eggs/ eggs/
dist/ .eggs/
downloads/ lib/
eggs/ lib64/
.eggs/ parts/
lib/ sdist/
lib64/ var/
parts/ wheels/
sdist/ pip-wheel-metadata/
var/ share/python-wheels/
wheels/ *.egg-info/
*.egg-info/ .installed.cfg
.installed.cfg *.egg
*.egg MANIFEST
*.manifest
*.spec # PyInstaller
# Usually these files are written by a python script from a template
# Installer logs # before PyInstaller builds the exe, so as to inject date/other infos into it.
pip-log.txt *.manifest
pip-delete-this-directory.txt *.spec
# Unit test / coverage reports # Installer logs
htmlcov/ pip-log.txt
.tox/ pip-delete-this-directory.txt
.coverage
.coverage.* # Unit test / coverage reports
.cache htmlcov/
.pytest_cache/ .tox/
nosetests.xml .nox/
coverage.xml .coverage
*.cover .coverage.*
.hypothesis/ .cache
nosetests.xml
# staticfiles coverage.xml
staticfiles/ *.cover
*.py,cover
# Jupyter Notebook .hypothesis/
.ipynb_checkpoints .pytest_cache/
# pyenv # Translations
.python-version *.mo
# celery # Django stuff:
celerybeat-schedule.*
# Flask stuff:
# SageMath parsed files instance/
*.sage.py .webassets-cache
# Environments # Scrapy stuff:
.env .scrapy
.db.env
.venv # Sphinx documentation
env/ docs/_build/
venv/
ENV/ # PyBuilder
env.bak/ target/
venv.bak/
# Jupyter Notebook
# mkdocs documentation .ipynb_checkpoints
/site
# IPython
# mypy profile_default/
.mypy_cache/ ipython_config.py
# Sublime Text # # pyenv
*.tmlanguage.cache .python-version
*.tmPreferences.cache
*.stTheme.cache # pipenv
*.sublime-workspace # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
*.sublime-project # 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
# sftp configuration file # install all needed dependencies.
sftp-config.json #Pipfile.lock
# Package control specific files Package # PEP 582; used by e.g. github.com/David-OConnor/pyflow
Control.last-run __pypackages__/
Control.ca-list
Control.ca-bundle # Celery stuff
Control.system-ca-bundle celerybeat-schedule
GitHub.sublime-settings celerybeat.pid
# Visual Studio Code # # SageMath parsed files
.vscode/* *.sage.py
!.vscode/settings.json
!.vscode/tasks.json # Environments
!.vscode/launch.json *.env
!.vscode/extensions.json .venv
.history env/
venv/
# misc ENV/
.DS_Store env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# End of https://www.toptal.com/developers/gitignore/api/django
include:
- template: Code-Quality.gitlab-ci.yml
- template: SAST.gitlab-ci.yml
- template: Secret-Detection.gitlab-ci.yml
- template: Dependency-Scanning.gitlab-ci.yml
- template: License-Scanning.gitlab-ci.yml
stages:
- test
- deploy
code_quality:
tags:
- docker
artifacts:
paths: [gl-code-quality-report.json]
sast:
tags:
- docker
artifacts:
paths: [gl-sast-report.json]
django-test:
image: python:3.8.3
stage: test
variables:
SECRET_KEY: "2c4=+s-cv(@z%vs_zkw*(+juf=)0&j1(0yn^ekap)s+z2jsqt3"
ALLOWED_HOSTS: "*"
DEBUG: 1
before_script:
- pip install -r requirements.txt
- python manage.py migrate
script:
- coverage run --include='sizakat/*' manage.py test
- coverage report -m
when: on_success
deploy-development:
image:
name: alpine/git:latest
entrypoint: [""]
stage: deploy
environment: development
variables:
GIT_URL: git@$REMOTE_SERVER:sizakat-5.0-backend.git
before_script:
- mkdir ~/.ssh
- cat "$SSH_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- mv "$KNOWN_HOSTS" ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- git config remote.development.url >&- || git remote add development $GIT_URL
- git checkout $CI_COMMIT_TAG
- git push --force development $CI_COMMIT_TAG 2>&1 | tee git-push.log
- "$(grep -E 'remote: Return with exit [0-9]+' git-push.log | grep -oE 'exit [0-9]+')"
rules:
- if: '$CI_COMMIT_TAG =~ /^development-\d+$/'
deploy-testing:
image:
name: alpine/git:latest
entrypoint: [""]
stage: deploy
environment: testing
variables:
GIT_URL: git@$REMOTE_SERVER:sizakat-5.0-backend.git
before_script:
- mkdir ~/.ssh
- cat "$SSH_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- mv "$KNOWN_HOSTS" ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- git config remote.testing.url >&- || git remote add testing $GIT_URL
- git checkout $CI_COMMIT_BRANCH
- git push testing $CI_COMMIT_BRANCH 2>&1 | tee git-push.log
- "$(grep -E 'remote: Return with exit [0-9]+' git-push.log | grep -oE 'exit [0-9]+')"
rules:
- if: '$CI_COMMIT_BRANCH == "testing"'
FROM python:3.8.3-alpine FROM python:3.8.3-alpine
WORKDIR /app/backend WORKDIR /app/backend
ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1 ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt . COPY ./requirements.txt .
RUN apk add --no-cache --virtual .build-deps \ RUN apk add --no-cache --virtual .build-deps \
gcc postgresql-dev libpq musl-dev \ gcc postgresql-dev libpq musl-dev \
&& pip install --upgrade pip \ && pip install --upgrade pip \
&& pip install -r requirements.txt \ && pip install -r requirements.txt \
&& find /usr/local \ && find /usr/local \
\( -type d -a -name test -o -name tests \) \ \( -type d -a -name test -o -name tests \) \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \ -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
-exec rm -rf '{}' + \ -exec rm -rf '{}' + \
&& runDeps="$( \ && runDeps="$( \
scanelf --needed --nobanner --recursive /usr/local \ scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \ | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \ | sort -u \
| xargs -r apk info --installed \ | xargs -r apk info --installed \
| sort -u \ | sort -u \
)" \ )" \
&& apk add --virtual .rundeps $runDeps \ && apk add --virtual .rundeps $runDeps \
&& apk del .build-deps && apk del .build-deps
COPY ./entrypoint.sh . COPY ./entrypoint.sh .
COPY . . COPY . .
ENTRYPOINT ["/app/backend/entrypoint.sh"] ENTRYPOINT ["/app/backend/entrypoint.sh"]
## Pipeline status and coverage report
[![pipeline status](https://gitlab.cs.ui.ac.id/sizakat/5.0/sizakat-backend/badges/master/pipeline.svg)](https://gitlab.cs.ui.ac.id/sizakat/5.0/sizakat-backend/-/commits/master)
[![coverage report](https://gitlab.cs.ui.ac.id/sizakat/5.0/sizakat-backend/badges/master/coverage.svg)](https://gitlab.cs.ui.ac.id/sizakat/5.0/sizakat-backend/-/commits/master)
# SiZakat 5.0
## Environment
### Backend environment
File `.env`:
```
SECRET_KEY=foobarbarfoo
ALLOWED_HOSTS=*
DEBUG=1
SQL_DATABASE=sizakat
SQL_USER=postgres
SQL_PASSWORD=postgres
SQL_HOST=db
SQL_PORT=5432
BACKEND_PORT=8000
```
- `SECRET_KEY`
https://docs.djangoproject.com/en/3.0/ref/settings/#std:setting-SECRET_KEY
- `ALLOWED_HOSTS`
https://docs.djangoproject.com/en/3.0/ref/settings/#std:setting-ALLOWED_HOSTS
- `DEBUG`
https://docs.djangoproject.com/en/3.0/ref/settings/#debug
- `SQL_*`
Pengaturan untuk database
- `BACKEND_PORT`
Port untuk service backend. Digunakan dalam `docker-compose`
### Database environment
File `.db.env`
```
POSTGRES_DB=sizakat
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
```
https://github.com/docker-library/docs/tree/master/postgres#environment-variables
version: '3.7' version: '3.7'
services: services:
backend: backend:
build: build:
context: ./ context: ./
command: python manage.py runserver 0.0.0.0:8000 command: gunicorn sizakat.wsgi --bind 0.0.0.0:8000 --log-file -
volumes: volumes:
- ./:/app/backend/ - ./:/app/backend/
ports: ports:
- 8000:8000 - ${BACKEND_PORT:-8000}:8000
env_file: env_file:
- .env - .env
depends_on: depends_on:
- db - db
db: db:
image: postgres:12.0-alpine image: postgres:12.0-alpine
volumes: volumes:
- postgres_data:/var/lib/postgresql/data/ - postgres_data:/var/lib/postgresql/data/
env_file: env_file:
- .db.env - .db.env
volumes: volumes:
postgres_data: postgres_data:
File mode changed from 100644 to 100755
#!/usr/bin/env python #!/usr/bin/env python
"""Django's command-line utility for administrative tasks.""" """Django's command-line utility for administrative tasks."""
import os import os
import sys import sys
def main(): def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sizakat.settings') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sizakat.settings')
try: try:
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
except ImportError as exc: except ImportError as exc:
raise ImportError( raise ImportError(
"Couldn't import Django. Are you sure it's installed and " "Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you " "available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?" "forget to activate a virtual environment?"
) from exc ) from exc
execute_from_command_line(sys.argv) execute_from_command_line(sys.argv)
if __name__ == '__main__': if __name__ == '__main__':
main() main()
[pep8]
max-line-length = 119
[isort]
combine_as_imports = true
default_section = THIRDPARTY
include_trailing_comma = true
known_first_party = sizakat
line_length = 79
multi_line_output = 5
""" """
ASGI config for sizakat project. ASGI config for sizakat project.
It exposes the ASGI callable as a module-level variable named ``application``. It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
""" """
import os import os
from django.core.asgi import get_asgi_application from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sizakat.settings') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sizakat.settings')
application = get_asgi_application() application = get_asgi_application()
from django.contrib import admin <