summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Gonzalez <roger@rogs.me>2021-01-10 14:34:56 -0300
committerRoger Gonzalez <roger@rogs.me>2021-01-10 14:34:56 -0300
commit36e77f145d64ccaf6904d0664029f7bec997cbaa (patch)
treee712f02fb36fb9c7cde1d6db624ebda51d4a3959
Initial commitHEADmaster
-rw-r--r--.gitignore219
-rw-r--r--Dockerfile23
-rw-r--r--README.md3
-rw-r--r--app/app/__init__.py0
-rw-r--r--app/app/asgi.py16
-rw-r--r--app/app/settings.py133
-rw-r--r--app/app/urls.py21
-rw-r--r--app/app/wsgi.py16
-rw-r--r--app/example/__init__.py0
-rw-r--r--app/example/admin.py5
-rw-r--r--app/example/apps.py5
-rw-r--r--app/example/migrations/0001_initial.py24
-rw-r--r--app/example/migrations/__init__.py0
-rw-r--r--app/example/models.py13
-rw-r--r--app/example/tests.py3
-rw-r--r--app/example/views.py3
-rwxr-xr-xapp/manage.py22
-rw-r--r--docker-compose.yml38
-rw-r--r--requirements.txt7
19 files changed, 551 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4578bb6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,219 @@
+.DS_Store
+.idea
+*.log
+tmp/
+
+
+# Created by https://www.toptal.com/developers/gitignore/api/python,django
+# Edit at https://www.toptal.com/developers/gitignore?templates=python,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/
+pytestdebug.log
+
+# Translations
+*.mo
+
+# Django stuff:
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+doc/_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/
+pythonenv*
+
+# 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/
+
+# profiling data
+.prof
+
+### 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
+
+# Django stuff:
+
+# Flask stuff:
+
+# Scrapy stuff:
+
+# Sphinx documentation
+
+# PyBuilder
+
+# Jupyter Notebook
+
+# IPython
+
+# 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.
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
+
+# Celery stuff
+
+# SageMath parsed files
+
+# Environments
+
+# Spyder project settings
+
+# Rope project settings
+
+# mkdocs documentation
+
+# mypy
+
+# Pyre type checker
+
+# pytype static type analyzer
+
+# profiling data
+
+# End of https://www.toptal.com/developers/gitignore/api/python,django
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..69931cd
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,23 @@
+FROM python:3.7.6-alpine
+
+ENV PYTHONUNBUFFERED 1
+
+RUN apk add --update --no-cache postgresql-client python3-dev \
+ libffi-dev jpeg-dev freetype-dev libjpeg-turbo-dev libpng-dev \
+ curl libxml2-dev libxslt-dev libstdc++
+RUN apk add --update --no-cache --virtual .tmp-build-deps \
+ gcc libc-dev linux-headers postgresql-dev musl-dev zlib zlib-dev \
+ g++
+
+RUN /usr/local/bin/python -m pip install --upgrade pip
+
+COPY ./requirements.txt /requirements.txt
+RUN pip install -r /requirements.txt
+RUN apk del .tmp-build-deps
+
+RUN mkdir /app
+WORKDIR /app
+COPY ./app /app
+
+RUN adduser -D user
+USER user
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..9ec5601
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# minio-example
+
+This is an example app to demonstrate MinIO functionality.
diff --git a/app/app/__init__.py b/app/app/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/app/__init__.py
diff --git a/app/app/asgi.py b/app/app/asgi.py
new file mode 100644
index 0000000..7d386be
--- /dev/null
+++ b/app/app/asgi.py
@@ -0,0 +1,16 @@
+"""
+ASGI config for app 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', 'app.settings')
+
+application = get_asgi_application()
diff --git a/app/app/settings.py b/app/app/settings.py
new file mode 100644
index 0000000..38737ce
--- /dev/null
+++ b/app/app/settings.py
@@ -0,0 +1,133 @@
+"""
+Django settings for app project.
+
+Generated by 'django-admin startproject' using Django 3.1.5.
+
+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 = "kcq6+9o_aoq94+==^1g7kx(_)!0+@12f47fxto3gga*r37mml9"
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = os.environ.get("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",
+ "example",
+]
+
+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 = "app.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 = "app.wsgi.application"
+
+
+# Database
+# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
+
+DATABASES = {
+ "default": {
+ "ENGINE": "django.db.backends.sqlite3",
+ "NAME": BASE_DIR / "db.sqlite3",
+ }
+}
+
+
+# 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/"
+
+# S3 configuration
+
+DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
+
+AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID", "access-key")
+AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY", "secret-key")
+AWS_STORAGE_BUCKET_NAME = os.environ.get("AWS_STORAGE_BUCKET_NAME", "my-local-bucket")
+
+if DEBUG:
+ AWS_S3_ENDPOINT_URL = "http://minio:9000"
diff --git a/app/app/urls.py b/app/app/urls.py
new file mode 100644
index 0000000..1192fe4
--- /dev/null
+++ b/app/app/urls.py
@@ -0,0 +1,21 @@
+"""app 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
+
+urlpatterns = [
+ path('admin/', admin.site.urls),
+]
diff --git a/app/app/wsgi.py b/app/app/wsgi.py
new file mode 100644
index 0000000..8ab68e5
--- /dev/null
+++ b/app/app/wsgi.py
@@ -0,0 +1,16 @@
+"""
+WSGI config for app 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', 'app.settings')
+
+application = get_wsgi_application()
diff --git a/app/example/__init__.py b/app/example/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/example/__init__.py
diff --git a/app/example/admin.py b/app/example/admin.py
new file mode 100644
index 0000000..b77621a
--- /dev/null
+++ b/app/example/admin.py
@@ -0,0 +1,5 @@
+from django.contrib import admin
+
+from example import models
+
+admin.site.register(models.Person)
diff --git a/app/example/apps.py b/app/example/apps.py
new file mode 100644
index 0000000..dbb0083
--- /dev/null
+++ b/app/example/apps.py
@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class ExampleConfig(AppConfig):
+ name = 'example'
diff --git a/app/example/migrations/0001_initial.py b/app/example/migrations/0001_initial.py
new file mode 100644
index 0000000..a2f5d32
--- /dev/null
+++ b/app/example/migrations/0001_initial.py
@@ -0,0 +1,24 @@
+# Generated by Django 3.1.5 on 2021-01-10 16:06
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Person',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('first_name', models.CharField(max_length=50)),
+ ('last_name', models.CharField(max_length=50)),
+ ('date_of_birth', models.DateField()),
+ ('picture', models.ImageField(upload_to='')),
+ ],
+ ),
+ ]
diff --git a/app/example/migrations/__init__.py b/app/example/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/example/migrations/__init__.py
diff --git a/app/example/models.py b/app/example/models.py
new file mode 100644
index 0000000..0632304
--- /dev/null
+++ b/app/example/models.py
@@ -0,0 +1,13 @@
+from django.db import models
+
+
+class Person(models.Model):
+ """This is a demo person model"""
+
+ first_name = models.CharField(max_length=50)
+ last_name = models.CharField(max_length=50)
+ date_of_birth = models.DateField()
+ picture = models.ImageField()
+
+ def __str__(self):
+ return f"{self.first_name} {self.last_name} {str(self.date_of_birth)}"
diff --git a/app/example/tests.py b/app/example/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/app/example/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/app/example/views.py b/app/example/views.py
new file mode 100644
index 0000000..91ea44a
--- /dev/null
+++ b/app/example/views.py
@@ -0,0 +1,3 @@
+from django.shortcuts import render
+
+# Create your views here.
diff --git a/app/manage.py b/app/manage.py
new file mode 100755
index 0000000..4931389
--- /dev/null
+++ b/app/manage.py
@@ -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', 'app.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/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..4b54a94
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,38 @@
+version: "3"
+
+services:
+ app:
+ build:
+ context: .
+ volumes:
+ - ./app:/app
+ ports:
+ - 8000:8000
+ depends_on:
+ - minio
+ command: >
+ sh -c "python manage.py migrate &&
+ python manage.py runserver 0.0.0.0:8000"
+
+ minio:
+ image: minio/minio
+ ports:
+ - 9000:9000
+ environment:
+ - MINIO_ACCESS_KEY=access-key
+ - MINIO_SECRET_KEY=secret-key
+ command: server /export
+
+ createbuckets:
+ image: minio/mc
+ depends_on:
+ - minio
+ entrypoint: >
+ /bin/sh -c "
+ apk add nc &&
+ while ! nc -z minio 9000; do echo 'Wait minio to startup...' && sleep 0.1; done; sleep 5 &&
+ /usr/bin/mc config host add myminio http://minio:9000 access-key secret-key;
+ /usr/bin/mc mb myminio/my-local-bucket;
+ /usr/bin/mc policy download myminio/my-local-bucket;
+ exit 0;
+ "
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..6763de8
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,7 @@
+Django==3.1.5
+python-language-server[all]>=0.36.2,<0.37.0
+pylint-django>=2.4.2,<2.5.0
+pyls-black>=0.4.6,<0.5.0
+django-storages>=1.10.1,<1.11.0
+Pillow>=8.1.0,<8.2.0
+boto3>=1.16.27,<1.17.0