diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..e2da498ed43c06a03187e2e60cca613960236080 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +env +*.env +*.sqlite3 +.git* +__pycache__ +*.pyc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..db16b2442d90de53fa1ea53a16225d44a51c0eab --- /dev/null +++ b/.gitignore @@ -0,0 +1,126 @@ +# 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/ + +# migrations file +*/migrations/ + +# 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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..5f08151bd7fd5b11e2496763afc55e0015b13849 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +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"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..5c4e1107bba428a4c4a7b3496315c98eb183bbb2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +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: diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000000000000000000000000000000000000..37fa201ef618de06c9d68b31e57f8f18c7d69280 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +if [ "$DATABASE" = "postgres" ] +then + echo "Waiting for postgres..." + + while ! nc -z $SQL_HOST $SQL_PORT; do + sleep 0.1 + done + + echo "PostgreSQL started" +fi + +exec "$@" diff --git a/manage.py b/manage.py new file mode 100644 index 0000000000000000000000000000000000000000..9120de3a8437ba1583088b87309710cf51213c17 --- /dev/null +++ b/manage.py @@ -0,0 +1,21 @@ +#!/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() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..74a30fa9ec638a5a792a935cc24811b2c7311295 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,9 @@ +asgiref==3.2.10 +Django==3.0.7 +django-cors-headers==3.4.0 +django-graphql-jwt==0.3.1 +graphene-django==2.10.1 +gunicorn==20.0.4 +psycopg2-binary==2.8.5 +pytz==2020.1 +sqlparse==0.3.1 diff --git a/sizakat/__init__.py b/sizakat/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/sizakat/apps/mustahik/__init__.py b/sizakat/apps/mustahik/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/sizakat/apps/mustahik/admin.py b/sizakat/apps/mustahik/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..ea5d68b7c457cb7f92da9c00a5c4df77ace36cef --- /dev/null +++ b/sizakat/apps/mustahik/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/sizakat/apps/mustahik/apps.py b/sizakat/apps/mustahik/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..90871a259e79c35f0b2271a7a339e5d56e51d0fe --- /dev/null +++ b/sizakat/apps/mustahik/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class MustahikConfig(AppConfig): + name = 'mustahik' diff --git a/sizakat/apps/mustahik/migrations/__init__.py b/sizakat/apps/mustahik/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/sizakat/apps/mustahik/models.py b/sizakat/apps/mustahik/models.py new file mode 100644 index 0000000000000000000000000000000000000000..fd18c6eac0dc9ffbdf025c31d136901350a0d9f2 --- /dev/null +++ b/sizakat/apps/mustahik/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/sizakat/apps/mustahik/tests.py b/sizakat/apps/mustahik/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..de8bdc00eb2fed53494a534d48e400faa830dbd9 --- /dev/null +++ b/sizakat/apps/mustahik/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/sizakat/asgi.py b/sizakat/asgi.py new file mode 100644 index 0000000000000000000000000000000000000000..e4c84f3b9ede5b7f4a20b4e09e68b7e2424240be --- /dev/null +++ b/sizakat/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for sizakat project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sizakat.settings') + +application = get_asgi_application() diff --git a/sizakat/schema.py b/sizakat/schema.py new file mode 100644 index 0000000000000000000000000000000000000000..642be04a63219408e9b23e2ab268024605ada912 --- /dev/null +++ b/sizakat/schema.py @@ -0,0 +1,14 @@ +from graphene_django import DjangoObjectType +import graphene + +ABOUT = 'Si Zakat merupakan sistem informasi untuk membantu masjid dalam \ +mengelola transaksi zakat. Sistem ini dibuat oleh tim lab 1231, \ +yang dipimpin oleh Prof. Dr. Wisnu Jatmiko.' + +class Query(graphene.ObjectType): + about = graphene.String() + + def resolve_about(self, info): + return ABOUT + +schema = graphene.Schema(query=Query) diff --git a/sizakat/settings.py b/sizakat/settings.py new file mode 100644 index 0000000000000000000000000000000000000000..f2caf3f04fc945634ab1875795897b3ea3e63475 --- /dev/null +++ b/sizakat/settings.py @@ -0,0 +1,130 @@ +""" +Django settings for sizakat project. + +Generated by 'django-admin startproject' using Django 3.0.7. + +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 = os.environ.get('SECRET_KEY') + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = os.environ.get("DEBUG", False) + +ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS').split() + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'graphene_django', +] + +GRAPHENE = { + 'SCHEMA': 'sizakat.schema.schema', +} + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'sizakat.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', + ], + }, + }, +] + +WSGI_APPLICATION = 'sizakat.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': os.environ.get('SQL_DATABASE'), + 'USER': os.environ.get('SQL_USER'), + 'PASSWORD': os.environ.get('SQL_PASSWORD'), + 'HOST': os.environ.get('SQL_HOST'), + 'PORT': os.environ.get('SQL_PORT'), + } +} + + +# 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', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.0/howto/static-files/ + +STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles") diff --git a/sizakat/urls.py b/sizakat/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..214fc527ad851ba5fbee74377f1ae91a31d54b78 --- /dev/null +++ b/sizakat/urls.py @@ -0,0 +1,24 @@ +"""sizakat 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')) +""" +from django.contrib import admin +from django.urls import path +from django.views.decorators.csrf import csrf_exempt +from graphene_django.views import GraphQLView + +urlpatterns = [ + path('admin/', admin.site.urls), + path('graphql/', csrf_exempt(GraphQLView.as_view(graphiql=True))), +] diff --git a/sizakat/wsgi.py b/sizakat/wsgi.py new file mode 100644 index 0000000000000000000000000000000000000000..5f7d7282b80d6408f7ab773d4a4cac79484296b0 --- /dev/null +++ b/sizakat/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for sizakat 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 + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sizakat.settings') + +application = get_wsgi_application()