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
*.sqlite3
.git*
__pycache__
*.pyc
env
*.env
*.sqlite3
.git*
__pycache__
*.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
*.pot
*.pyc
__pycache__
db.sqlite3
media
# Backup files #
*.bak
# If you are using PyCharm #
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/gradle.xml
.idea/**/libraries
*.iws /out/
# Python #
*.py[cod]
*$py.class
# Distribution / packaging
.Python build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
.pytest_cache/
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# staticfiles
staticfiles/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery
celerybeat-schedule.*
# SageMath parsed files
*.sage.py
# Environments
.env
.db.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# mkdocs documentation
/site
# mypy
.mypy_cache/
# Sublime Text #
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
*.sublime-workspace
*.sublime-project
# sftp configuration file
sftp-config.json
# Package control specific files Package
Control.last-run
Control.ca-list
Control.ca-bundle
Control.system-ca-bundle
GitHub.sublime-settings
# Visual Studio Code #
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history
# misc
.DS_Store
# Created by https://www.toptal.com/developers/gitignore/api/django
# Edit at https://www.toptal.com/developers/gitignore?templates=django
### 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
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
# Django stuff:
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# 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
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
*.env
.venv
env/
venv/
ENV/
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
WORKDIR /app/backend
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt .
RUN apk add --no-cache --virtual .build-deps \
gcc postgresql-dev libpq musl-dev \
&& pip install --upgrade pip \
&& pip install -r requirements.txt \
&& find /usr/local \
\( -type d -a -name test -o -name tests \) \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
-exec rm -rf '{}' + \
&& runDeps="$( \
scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --virtual .rundeps $runDeps \
&& apk del .build-deps
COPY ./entrypoint.sh .
COPY . .
ENTRYPOINT ["/app/backend/entrypoint.sh"]
FROM python:3.8.3-alpine
WORKDIR /app/backend
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt .
RUN apk add --no-cache --virtual .build-deps \
gcc postgresql-dev libpq musl-dev \
&& pip install --upgrade pip \
&& pip install -r requirements.txt \
&& find /usr/local \
\( -type d -a -name test -o -name tests \) \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
-exec rm -rf '{}' + \
&& runDeps="$( \
scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --virtual .rundeps $runDeps \
&& apk del .build-deps
COPY ./entrypoint.sh .
COPY . .
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'
services:
backend:
build:
context: ./
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./:/app/backend/
ports:
- 8000:8000
env_file:
- .env
depends_on:
- db
db:
image: postgres:12.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- .db.env
volumes:
postgres_data:
version: '3.7'
services:
backend:
build:
context: ./
command: gunicorn sizakat.wsgi --bind 0.0.0.0:8000 --log-file -
volumes:
- ./:/app/backend/
ports:
- ${BACKEND_PORT:-8000}:8000
env_file:
- .env
depends_on:
- db
db:
image: postgres:12.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- .db.env
volumes:
postgres_data:
File mode changed from 100644 to 100755
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sizakat.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sizakat.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()