parent
f0bfdb2fdd
commit
5ad62e882f
@ -0,0 +1,46 @@
|
||||
FROM python:3.10.4-alpine3.15
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . /app
|
||||
|
||||
RUN apk add --no-cache \
|
||||
mariadb-client \
|
||||
py3-mysqlclient \
|
||||
mysql-client \
|
||||
libffi \
|
||||
gettext \
|
||||
gettext-libs \
|
||||
jpeg-dev \
|
||||
zlib-dev \
|
||||
&& apk add --no-cache --virtual build-requirements \
|
||||
cargo \
|
||||
freetype-dev \
|
||||
gcc \
|
||||
libffi-dev \
|
||||
linux-headers \
|
||||
mariadb-dev \
|
||||
musl-dev \
|
||||
rust \
|
||||
&& pip install --no-cache-dir --upgrade pip \
|
||||
&& pip install --no-cache-dir virtualenv \
|
||||
&& virtualenv /env \
|
||||
&& /env/bin/pip install --no-cache-dir --upgrade \
|
||||
pip \
|
||||
uwsgi \
|
||||
&& /env/bin/pip install -r /app/requirements.txt \
|
||||
&& apk del build-requirements \
|
||||
&& rm -rf /root/.cache
|
||||
|
||||
RUN adduser -D -H nicolas \
|
||||
&& mkdir -p /app/log \
|
||||
&& touch /app/log/skeletondjango.log \
|
||||
&& chown -R nicolas:nicolas /app \
|
||||
&& chmod +x /app/docker/entrypoint.sh
|
||||
|
||||
|
||||
COPY docker/uwsgi.ini.template /etc/uwsgi.ini.template
|
||||
|
||||
EXPOSE 8091
|
||||
|
||||
CMD ["/app/docker/entrypoint.sh"]
|
@ -0,0 +1,20 @@
|
||||
SHELL := /bin/bash
|
||||
|
||||
all: clean build test
|
||||
|
||||
build:
|
||||
docker-compose build
|
||||
|
||||
up:
|
||||
docker-compose up -d
|
||||
|
||||
test: up
|
||||
docker-compose exec skeleton-django-service /env/bin/python /app/manage.py test --noinput
|
||||
|
||||
migrate: up
|
||||
docker-compose exec skeleton-django-service /env/bin/python /app/manage.py migrate
|
||||
|
||||
makemigrations: up
|
||||
docker-compose exec skeleton-django-service /env/bin/python /app/manage.py makemigrations
|
||||
|
||||
.PHONY: build up test clean
|
@ -1 +1,27 @@
|
||||
# skeleton_django
|
||||
# skeleton-django
|
||||
|
||||
Skeleton of a backend Django App.
|
||||
|
||||
## Organization
|
||||
|
||||
```shell
|
||||
apps/
|
||||
app_one/
|
||||
apputils/
|
||||
migrations/
|
||||
models/
|
||||
serializers/
|
||||
tests/
|
||||
views/
|
||||
urls.py
|
||||
project_name/
|
||||
settings/
|
||||
default.py
|
||||
development.py
|
||||
production.py
|
||||
staging.py
|
||||
utils/
|
||||
```
|
||||
|
||||
- Each package is located inside the apps package.
|
||||
- Each model, serializer, view is defined in a separate .py file.
|
||||
|
@ -0,0 +1,13 @@
|
||||
from django.urls import reverse
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
|
||||
class DummyTest(APITestCase):
|
||||
|
||||
endpoint = reverse('dummy-view')
|
||||
|
||||
def test_dummy_view(self):
|
||||
response = self.client.get(
|
||||
self.endpoint
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
@ -0,0 +1,14 @@
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
|
||||
path(
|
||||
'',
|
||||
views.DummyViewSet.as_view({'get': 'dummy_view'}),
|
||||
name='dummy-view'
|
||||
),
|
||||
|
||||
]
|
@ -0,0 +1 @@
|
||||
from .dummy import DummyViewSet
|
@ -0,0 +1,9 @@
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.status import HTTP_200_OK
|
||||
from rest_framework.viewsets import GenericViewSet
|
||||
|
||||
|
||||
class DummyViewSet(GenericViewSet):
|
||||
|
||||
def dummy_view(self, request, *args, **kwargs):
|
||||
return Response(status=HTTP_200_OK)
|
@ -0,0 +1,31 @@
|
||||
version: "2"
|
||||
|
||||
services:
|
||||
skeleton-django-db:
|
||||
image: mariadb
|
||||
volumes:
|
||||
- db_data:/var/lib/mysql
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: rootpassword
|
||||
MYSQL_DATABASE: skeletondjango
|
||||
MYSQL_USER: nicolas
|
||||
MYSQL_PASSWORD: qwerty
|
||||
|
||||
skeleton-django-service:
|
||||
build: .
|
||||
depends_on:
|
||||
- skeleton-django-db
|
||||
command: /env/bin/python /app/manage.py runserver 0.0.0.0:8990
|
||||
env_file:
|
||||
- variables.dev
|
||||
environment:
|
||||
- DJANGO_SETTINGS_MODULE=skeletondjango.settings.development
|
||||
- RDS_HOSTNAME=skeleton-django-db
|
||||
ports:
|
||||
- 8990:8990
|
||||
volumes:
|
||||
- .:/app
|
||||
|
||||
volumes:
|
||||
db_data:
|
||||
driver: local
|
@ -0,0 +1,5 @@
|
||||
CREATE SCHEMA `skeletondjango` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
|
||||
CREATE SCHEMA `test_skeletondjango` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
|
||||
CREATE USER 'nicolas'@'%' IDENTIFIED BY 'qwerty';
|
||||
GRANT ALL PRIVILEGES ON skeletondjango.* TO 'nicolas'@'%';
|
||||
GRANT ALL PRIVILEGES ON test_skeletondjango.* TO 'nicolas'@'%';
|
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
/env/bin/python /app/manage.py migrate --noinput
|
||||
|
||||
/env/bin/uwsgi --ini /etc/uwsgi.ini
|
@ -0,0 +1,19 @@
|
||||
[uwsgi]
|
||||
# Django-related settings
|
||||
# the base directory (full path)
|
||||
chdir = /app/
|
||||
# Django's wsgi file
|
||||
module = skeletondjango.wsgi
|
||||
# the virtualenv (full path)
|
||||
home = /env/
|
||||
|
||||
# maximum number of worker processes
|
||||
processes = ${UWSGI_WORKERS}
|
||||
threads = ${UWSGI_THREADS}
|
||||
# the socket (use the full path to be safe
|
||||
# socket = /path/to/your/project/mysite.sock
|
||||
# http = :8990
|
||||
# ... with appropriate permissions - may be needed
|
||||
# chmod-socket = 664
|
||||
# clear environment on exit
|
||||
vacuum = true
|
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'skeletondjango.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()
|
@ -0,0 +1,8 @@
|
||||
django==4.1
|
||||
djangorestframework==3.13.1
|
||||
|
||||
mysqlclient==2.0.1
|
||||
|
||||
# -------------------------------- Dev
|
||||
|
||||
ipdb
|
@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for skeletondjango 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.1/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'skeletondjango.settings')
|
||||
|
||||
application = get_asgi_application()
|
@ -0,0 +1,127 @@
|
||||
"""
|
||||
Django settings for skeletondjango project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 3.1.7.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.1/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/3.1/ref/settings/
|
||||
"""
|
||||
import os
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = '=!qo=#f1s+^41prd^obim16(hn6s0qtq0&m_l#u551b66sf+f3'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
]
|
||||
|
||||
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 = 'skeletondjango.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 = 'skeletondjango.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': os.getenv('RDS_DB_NAME'),
|
||||
'USER': os.getenv('RDS_USERNAME'),
|
||||
'PASSWORD': os.getenv('RDS_PASSWORD'),
|
||||
'HOST': os.getenv('RDS_HOSTNAME'),
|
||||
'PORT': os.getenv('RDS_PORT')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/3.1/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.1/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.1/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY', '.vF\D;j3B`k"m}"ShZv.Cb9/)RLM$upHBDkfoYocp6ypQ3&2irUM#S)J{[392')
|
@ -0,0 +1,4 @@
|
||||
from skeletondjango.settings.default import *
|
||||
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = True
|
@ -0,0 +1,24 @@
|
||||
"""skeletondjango URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/3.1/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, include
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
|
||||
path('dummy/', include('apps.dummy.urls')),
|
||||
]
|
@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for skeletondjango 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.1/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'skeletondjango.settings')
|
||||
|
||||
application = get_wsgi_application()
|
@ -0,0 +1,14 @@
|
||||
DEPLOYMENT_ENVIRONMENT=dev
|
||||
|
||||
DJANGO_SECRET_KEY=4~@cwwSJ"<R^HYZ.f]KniGR(kaaT*/zG;BpMcu__@XTV2QR~$BB\E#sM^"88.
|
||||
DJANGO_SETTINGS_MODULE=skeletondjango.settings.development
|
||||
|
||||
RDS_DB_NAME=skeletondjango
|
||||
RDS_HOSTNAME=172.17.0.2
|
||||
RDS_RO_HOSTNAME=172.17.0.2
|
||||
RDS_PASSWORD=qwerty
|
||||
RDS_PORT=3306
|
||||
RDS_USERNAME=nicolas
|
||||
|
||||
UWSGI_THREADS=4
|
||||
UWSGI_WORKERS=2
|
Loading…
Reference in new issue