From 39d3f304e5f58a9f933122578b4e32e0313cf57b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20M=C3=A9rigot?= Date: Fri, 11 Jan 2019 15:15:11 +0100 Subject: [PATCH] Initial commit --- .gitignore | 4 ++ .gitlab-ci.yml | 30 +++++++++ README.md | 66 +++++++++++++++++++ djangoldp_example/__init__.py | 2 + djangoldp_example/admin.py | 4 ++ djangoldp_example/apps.py | 4 ++ djangoldp_example/factories.py | 12 ++++ djangoldp_example/management/__init__.py | 0 .../management/commands/__init__.py | 0 .../management/commands/mock_example.py | 12 ++++ djangoldp_example/migrations/__init__.py | 0 djangoldp_example/models.py | 4 ++ djangoldp_example/urls.py | 9 +++ setup.cfg | 22 +++++++ setup.py | 5 ++ 15 files changed, 174 insertions(+) create mode 100644 .gitignore create mode 100644 .gitlab-ci.yml create mode 100644 README.md create mode 100644 djangoldp_example/__init__.py create mode 100644 djangoldp_example/admin.py create mode 100644 djangoldp_example/apps.py create mode 100644 djangoldp_example/factories.py create mode 100644 djangoldp_example/management/__init__.py create mode 100644 djangoldp_example/management/commands/__init__.py create mode 100644 djangoldp_example/management/commands/mock_example.py create mode 100644 djangoldp_example/migrations/__init__.py create mode 100644 djangoldp_example/models.py create mode 100644 djangoldp_example/urls.py create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9901035 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +dist +*.egg-info +build +__pycache__ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..c86fdd3 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,30 @@ +--- +image: python:3.6 + +stages: + - test + - release + +test: + stage: test + script: + - echo 'Make your tests here !' + except: + - master + tags: + - sib + +publish: + stage: release + before_script: + - git config user.name "${GITLAB_USER_NAME}" + - git config user.email "${GITLAB_USER_EMAIL}" + - git remote set-url origin "https://gitlab-ci-token:${GL_TOKEN}@git.happy-dev.fr/${CI_PROJECT_PATH}.git" + - pip install git+https://github.com/plup/python-semantic-release + - pip install sib-commit-parser + script: + - semantic-release publish + only: + - do_not_publish + tags: + - sib diff --git a/README.md b/README.md new file mode 100644 index 0000000..6617514 --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +# Django LDP example + +## Step by step quickstart + +1. Installation +- `git clone git@git.happy-dev.fr:startinblox/djangoldp-packages/djangoldp-example.git /path/to/myawesomepackage` +- `git remote set-url origin the_repository_url` +- rename djangoldp_example directory to djangoldp_myawesomepackage + +NB: +- replace /path/to/myawesomepackage with the local path of your package. +- replace the_repository_url with the git url of your package (example: git@git.happy-dev.fr:startinblox/djangoldp-packages/djangoldp-example.git). +- replace djangoldp_myawesomepackage with your package name. Please respect the naming convention (singular word, starting by `djangoldp_`) + +2. Developpement environnement + +In order to test and developp your package, you need to put the package src directory at the same level of a working django ldp app. By exemple, you can clone the sib app data server +`git clone git@git.happy-dev.fr:startinblox/applications/sib-app-data-server.git server /path/to/app` + +- The classical way : +`ln -s /path/to/myawesomepackage/djangoldp_myawesomepackage /path/to/app/djangoldp_myawesomepackage` + +- The docker way : in the *volumes* section, add a line in docker-compose.override.yml. Example +``` +volumes: + - ./:/app + - /path/to/myawesomepackage/djangoldp_myawesomepackage:/app/djangoldp_myawesomepackage +``` + +Add your package in settings.py of the app. Now, you can test if your package is imported propefully by doing a +`python manage.py shell` then +from djangoldp_myawesomepackage.models import ExampleModel + +If, no error, it's working. + +3. Customization +- `setup.cfg` : please, fill the name, version, url, author_email, description +- `djangoldp_example/__init__.py`: fill the name, don't touch the version number ! +- everything under the djangoldp_example is part of your package, you probably would replace "example" by your package name. + +4. Push on the repository you've created + +## Notes + +### CICD +When you're ready to publish your app : +1. Add the `sib-deploy` user as a `maintainer` to the project (`Settings > Members`) + +2. Configure `pipeline strategy` to `clone` (`Settings > CI/CD > Pipelines`) + +3. Protect the `master` branch allowing only `maintainers` to push (`Settings > Repository > Protected branches`) + +4. Configure CI/CD variables to authenticate on pypi.org: + +Variable | Value | Protection +----------------|--------------------|----------- +`GL_TOKEN` | `sib-deploy-token` | protected +`PYPI_PASSWORD` | `pypi-password` | protected +`PYPI_USERNAME` | startinblox | protected + +5. Replace the "do_not_publish" by "master" in the .gitlab-ci.yml + +### Factories +If you dont need factory, you can remove the mock_example command, the factories files and the extras_require section in setup.cfg + +Provide a factory is a good pratice in order to simplify the mocking of data on a server / in a test pipeline. diff --git a/djangoldp_example/__init__.py b/djangoldp_example/__init__.py new file mode 100644 index 0000000..d176d53 --- /dev/null +++ b/djangoldp_example/__init__.py @@ -0,0 +1,2 @@ +__version__ = '0.0.0' +name = "djangoldp_example" diff --git a/djangoldp_example/admin.py b/djangoldp_example/admin.py new file mode 100644 index 0000000..acec33d --- /dev/null +++ b/djangoldp_example/admin.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from .models import ExampleModel + +admin.site.register(ExampleModel) diff --git a/djangoldp_example/apps.py b/djangoldp_example/apps.py new file mode 100644 index 0000000..cfb5ce2 --- /dev/null +++ b/djangoldp_example/apps.py @@ -0,0 +1,4 @@ +from django.apps import AppConfig + +class DjangoldpExampleConfig(AppConfig): + name = 'djangoldp_example' diff --git a/djangoldp_example/factories.py b/djangoldp_example/factories.py new file mode 100644 index 0000000..41838f7 --- /dev/null +++ b/djangoldp_example/factories.py @@ -0,0 +1,12 @@ +import factory +import hashlib +from .models import ExampleModel +from django.db.models.signals import post_save + +@factory.django.mute_signals(post_save) +class ExampleFactory(factory.django.DjangoModelFactory): + class Meta: + model = ExampleModel + + # Please refer to Factory boy documentation + # https://factoryboy.readthedocs.io diff --git a/djangoldp_example/management/__init__.py b/djangoldp_example/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/djangoldp_example/management/commands/__init__.py b/djangoldp_example/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/djangoldp_example/management/commands/mock_example.py b/djangoldp_example/management/commands/mock_example.py new file mode 100644 index 0000000..2b0ac09 --- /dev/null +++ b/djangoldp_example/management/commands/mock_example.py @@ -0,0 +1,12 @@ +from django.core.management.base import BaseCommand, CommandError +from djangoldp_example.factories import ExampleFactory + +class Command(BaseCommand): + help = 'Mock data' + + def add_arguments(self, parser): + parser.add_argument('--size', type=int, default=0, help='Number of example to create') + + def handle(self, *args, **options): + ExampleFactory.create_batch(options['size'], thread=thread) + self.stdout.write(self.style.SUCCESS('Successful data mock install')) diff --git a/djangoldp_example/migrations/__init__.py b/djangoldp_example/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/djangoldp_example/models.py b/djangoldp_example/models.py new file mode 100644 index 0000000..1b20ddd --- /dev/null +++ b/djangoldp_example/models.py @@ -0,0 +1,4 @@ +from django.db import models + +class ExampleModel(models.Model): + # Please refer to Django documentation diff --git a/djangoldp_example/urls.py b/djangoldp_example/urls.py new file mode 100644 index 0000000..5a2b7e3 --- /dev/null +++ b/djangoldp_example/urls.py @@ -0,0 +1,9 @@ +"""djangoldp project URL Configuration""" +from django.conf.urls import url +from djangoldp.views import LDPViewSet + +from .models import ExampleModel + +urlpatterns = [ + url(r'^examples/', LDPViewSet.urls(model=ExampleModel)), +] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..dfbad9a --- /dev/null +++ b/setup.cfg @@ -0,0 +1,22 @@ +[metadata] +name = djangoldp_example +version = attr: djangoldp_example.__version__ +url = http://git.happy-dev.fr/startinblox/djangoldp_example +author = Startin'blox +author_email = nicolas@happy-dev.fr +description = djangoldp example package +license = MIT + +[options] +packages = find: +install_requires = + djangoldp~=0.5 + +[options.extras_require] +dev = + factory_boy>=2.11.0 + +[semantic_release] +version_source = tag +version_variable = djangoldp_example/__init__.py:__version__ +commit_parser = commit_parser.parse diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..beda28e --- /dev/null +++ b/setup.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python + +from setuptools import setup + +setup()