Skip to content

Commit

Permalink
Project VisualEditor support (#49)
Browse files Browse the repository at this point in the history
added VisualEditor support:
* T02-04 Implement delete feature: update delete api for document to return a 405 error if the document is attached to a module

* JSON Schema: Manage object, array and number types + fix some issues

* JSON schema validation for document REST api + generate automatic slug for document

* fix issue with the JSON schema validation for document REST api

* Manage multiple error messages in the document serializer

* Update the schema example

* Add service to generate preview + fix the update of document to remove content

* Manage 404 error for the generate_snapshot service.

* Update README.md

* remove SessionAuthentication in Django Reest Api to handle auth correctly from outside miller  (with auth bearer)

* enable watchmedo autorestart for docker-compose dev

* Fix the validation of the json field using the JSON schema

* add en_GB for both title and description in the default schema for document payloads.

* bump version number to 2.2.0

Co-authored-by: frederic.reis <[email protected]>
  • Loading branch information
danieleguido and frederic-reis authored Mar 2, 2021
2 parents c525553 + 63b2dd0 commit 613381f
Show file tree
Hide file tree
Showing 16 changed files with 542 additions and 309 deletions.
12 changes: 6 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
DEBUG=True
SECRET_KEY=yoursecretkeyhere
MILLER_DATABASE_NAME=
MILLER_DATABASE_USER=
MILLER_DATABASE_PASSWORD=
REDIS_HOST=localhost
REDIS_PORT=63790
MILLER_SCHEMA_ROOT=schema
MILLER_DATABASE_NAME=miller
MILLER_DATABASE_USER=miller
MILLER_DATABASE_PASSWORD=miller
REDIS_HOST=redis
REDIS_PORT=6379
MILLER_SCHEMA_ROOT=/miller/schema
37 changes: 37 additions & 0 deletions .github/workflows/docker-build-publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build and publish Docker image for Release
on:
# Trigger the workflow on push or pull request,
# for the develop branch and all new tags
push:
tags:
- v*
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Fetch Prune Unshallow Tags
run: git fetch --prune --unshallow --tags
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Extract commit hash
shell: bash
run: echo "##[set-output name=hash;]$(git rev-parse --short ${GITHUB_SHA})"
id: extract_hash
- name: Extract latest tag
shell: bash
run: echo "RELEASE_VERSION="$(git describe --tags --abbrev=0 ${GITHUB_SHA}) >> $GITHUB_ENV
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
env:
GIT_BRANCH: ${{ steps.extract_branch.outputs.branch }}
GIT_REVISION: ${{ steps.extract_hash.outputs.hash }}
GIT_TAG: ${{ env.RELEASE_VERSION }}
with:
name: c2dhunilu/miller-v2
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
buildargs: GIT_BRANCH,GIT_REVISION,GIT_TAG
tags: "${{ env.RELEASE_VERSION }}"
12 changes: 5 additions & 7 deletions .github/workflows/docker-build-publish.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name: Build and publish Docker image
name: "Build and publish :latest Docker image"
on:
# Trigger the workflow on push or pull request,
# for the develop branch and all new tags
push:
branches:
- miller-v2
tags:
- v*
- preview-*
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -25,15 +22,16 @@ jobs:
id: extract_hash
- name: Extract latest tag
shell: bash
run: echo ::set-env name=RELEASE_VERSION::$(git describe --tags --abbrev=0 ${GITHUB_SHA})
run: echo "RELEASE_VERSION="$(git describe --tags --abbrev=0 ${GITHUB_SHA}) >> $GITHUB_ENV
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
env:
GIT_BRANCH: ${{ steps.extract_branch.outputs.branch }}
GIT_REVISION: ${{ steps.extract_hash.outputs.hash }}
GIT_TAG: ${{ env.RELEASE_VERSION }}
with:
name: c2dhunilu/miller-v2
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
buildargs: GIT_BRANCH,GIT_REVISION
tags: "${{ env.RELEASE_VERSION }}"
buildargs: GIT_BRANCH,GIT_REVISION,GIT_TAG
tags: "latest"
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ run-dev:
&& export GIT_REVISION=$(shell git rev-parse --short HEAD) \
&& cd docker && docker-compose -f docker-compose.dev.yml up --force-recreate

run-dev-build:
export GIT_TAG=$(shell git describe --tags)\
&& export GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD) \
&& export GIT_REVISION=$(shell git rev-parse --short HEAD) \
&& cd docker && docker-compose -f docker-compose.dev.yml up --force-recreate --build

run-dev-detach:
export GIT_TAG=$(shell git describe --tags)\
&& export GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD) \
Expand Down
87 changes: 55 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,79 @@ a very basic django app to run "digital exhibition websites"

# Install for development
We use docker to make development easier:

cp docker/.env.example docker/.env

edit the `docker/.env` file setting proper database name and password; then
edit the `./docker/.env` file using a proper database name and change the password; then
copy the `./example.env` file to `.env` and fill the fields using the same database name and password.
This second step is needed because the **environment variable names** are different in
docker and in miller.

SECRET_KEY=*****
DEBUG=True
MILLER_DATABASE_NAME=your db name
MILLER_DATABASE_USER=your db user
MILLER_DATABASE_PASSWORD=your db pass
MILLER_DATABASE_HOST=localhost

then start the development docker with:

make run-dev

Will install all images (redis, postgres...) and build locally celery and miller for you.

This will install all images (redis, postgres...) and build locally celery and miller for you.
`Watchdog` takes care of restarting miller and celery when a py file change in the codebase.

Make sure the db is aligned:
For the first time, of whenever a new migration is available, make sure the db is aligned with:

make run-migrate

then test that everything works as expected:

make run-test

## Install without docker (not recommended)
We followed the doc at https://hackernoon.com/reaching-python-development-nirvana-bb5692adf30c
To create a new superuser

docker exec -it docker_miller_1 python manage.py makemigrations

## Add support for the visual editor
The Visual Editor is our favorite way to handle themes and documents in Miller.
It is a React app that connects flawlessy with the Miller JSON based api, and a few Configuration
are needed to make the connection

Create a new *Application* instance in Miller admin. [This](http://localhost/admin/oauth2_provider/application/add/)
will be the URL if you run with the development docker compose. Fill with **Client Type**
set to `Public` and **Authorization Grant Type** to `Resource owner password-based`.

Put the given **Client Id** inside the .env file of the VisualEditor along with
the relative URL of the JSON schema to validate documents:

REACT_APP_DOCUMENT_SCHEMA=
REACT_APP_MILLER_CLIENT_ID=


## Install without docker (deprecated)

To install the correct version of python, you can follow
the doc at https://hackernoon.com/reaching-python-development-nirvana-bb5692adf30c

pyenv installs 3.8.0
pyenv local 3.8.0

In order to install pipenv using the correct version of python,
use pip shipped with local python version:
use the `pip` module that is shipped with local python version:

python -m pip install pipenv

Install the library imagemagick6, then install requirements:
Install the library `imagemagick6` according to your OS, then install requirements:

pipenv install


## configure
Copy the `.example.env` file to `.development.env` and fill the fields:
## Run using pipenv
Copy the `./env.example` file to `./.development.env`, then edit the values accoring to your system.

An example of a `./.development.env` file:

SECRET_KEY=*****
DEBUG=True
Expand All @@ -47,7 +84,8 @@ Copy the `.example.env` file to `.development.env` and fill the fields:
MILLER_DATABASE_PASSWORD=your db pass
MILLER_DATABASE_HOST=localhost

These values replace the default values in miller/settings.py file thanks to the function `get_env_variable`:
These values replace the default values in `./miller/settings.py` thanks to
the method `get_env_variable`:

DATABASES = {
'default': {
Expand All @@ -60,37 +98,22 @@ These values replace the default values in miller/settings.py file thanks to the
}
}

As we're going to use docker for development purposes, remember to copy the postgres credentials to the
`docker/.env` file (use the given `docker/.env.example` file as example):
All values in `get_env_variable` can be replaced with the one of your choice
(e.g; postgres or redis port number can be changed)

POSTGRES_USER=your db name
POSTGRES_DB=your db user
POSTGRES_PASSWORD=your db pass

Docker compose file used for development is `docker/docker-compose.dev.yml` and as you see expose postgres to the port 54320 and redis to port 63790.
This comes in handy if we want to use those services with external software (eg pgadmin). This allows also to use management commands outside of docker.
For instance, we might run django migration command to check that the system is working properly:
Complete the intallation:

ENV=development pipenv run ./manage.py migrate

# run!
Using docker for devlopment, from the folder where the Makefile is, run:

make run-dev

then go to http://localhost:8008

## with pipenv

Using pipenv:
Run with:

ENV=development pipenv run ./manage.py runserver

With celery tasks:
In parallel, launch the celery tasks manager:

ENV=development pipenv run celery -A miller worker -l info

# test
## test
Use test runner without DB:

ENV=development pipenv run ./manage.py test --testrunner=miller.test.NoDbTestRunner
2 changes: 1 addition & 1 deletion docker/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
POSTGRES_USER=miller
POSTGRES_DB=miller
POSTGRES_PASSWORD=**
POSTGRES_PASSWORD=miller
MILLER_TAG=latest
ALLOWED_HOSTS=localhost
STATIC_URL=/miller-assets/
Expand Down
7 changes: 6 additions & 1 deletion docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ services:
depends_on:
- redis
- postgresdb
entrypoint: /bin/sh -c "PYTHONPATH=/ python miller/dbconnection.py && python manage.py init_git && python manage.py collectstatic --clear --no-input && python manage.py runserver 0.0.0.0:8000"
entrypoint: >
/bin/sh -c "PYTHONPATH=/ python miller/dbconnection.py &&
python manage.py init_git &&
python manage.py collectstatic --clear --no-input &&
python manage.py migrate &&
watchmedo auto-restart --recursive --patterns='*.py;*.json' --directory=. -- gunicorn --bind=0.0.0.0:8000 -w 2 -k gthread miller.wsgi"
# ports:
# - 8008:8000
volumes:
Expand Down
Loading

0 comments on commit 613381f

Please sign in to comment.