-
-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
local dev environment
- Loading branch information
Showing
10 changed files
with
166 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
Yiannis Stergiou - ys.stergiou@gmail.com | ||
Markos Gogoulos - mgogoulos@gmail.com | ||
Swift Ugandan - swiftugandan@gmail.com | ||
|
||
Please see https://github.com/mediacms-io/mediacms/graphs/contributors for complete list of contributors to this repository! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Development settings, used in docker-compose-dev.yaml | ||
import os | ||
|
||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'allauth', | ||
'allauth.account', | ||
'allauth.socialaccount', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
'django.contrib.sites', | ||
'rest_framework', | ||
'rest_framework.authtoken', | ||
'imagekit', | ||
'files.apps.FilesConfig', | ||
'users.apps.UsersConfig', | ||
'actions.apps.ActionsConfig', | ||
'debug_toolbar', | ||
'mptt', | ||
'crispy_forms', | ||
'uploader.apps.UploaderConfig', | ||
'djcelery_email', | ||
'ckeditor', | ||
'drf_yasg', | ||
'corsheaders', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
'corsheaders.middleware.CorsMiddleware', | ||
'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', | ||
'debug_toolbar.middleware.DebugToolbarMiddleware', | ||
] | ||
|
||
DEBUG = True | ||
CORS_ORIGIN_ALLOW_ALL = True | ||
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static/'),) | ||
STATIC_ROOT = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Developer Experience | ||
There is ongoing effort to provide a better developer experience and document it. | ||
|
||
## How to develop locally with Docker | ||
First install a recent version of [Docker](https://docs.docker.com/get-docker/), and [Docker Compose](https://docs.docker.com/compose/install/). | ||
|
||
Then run `docker-compose -f docker-compose-dev.yaml up` | ||
|
||
``` | ||
user@user:~/mediacms$ docker-compose -f docker-compose-dev.yaml up | ||
``` | ||
|
||
In a few minutes the app will be available at http://localhost . Login via admin/admin | ||
|
||
### What does docker-compose-dev.yaml do? | ||
It build the two images used for backend and frontend. | ||
|
||
* Backend: `mediacms/mediacms-dev:latest` | ||
* Frontend: `frontend` | ||
|
||
and will start all services required for MediaCMS, as Celery/Redis for asynchronous tasks, PostgreSQL database, Django and React | ||
|
||
For Django, the changes from the image produced by docker-compose.yaml are these: | ||
|
||
* Django runs in debug mode, with `python manage.py runserver` | ||
* uwsgi and nginx are not run | ||
* Django runs in Debug mode, with Debug Toolbar | ||
* Static files (js/css) are loaded from static/ folder | ||
* corsheaders is installed and configured to allow all origins | ||
|
||
For React, it will run `npm start` in the frontend folder, which will start the development server. | ||
Check it on http://localhost:8088/ | ||
|
||
### How to develop in Django | ||
Django starts at http://localhost and is reloading automatically. Making any change to the python code should refresh Django. | ||
|
||
### How to develop in React | ||
React is started on http://localhost:8088/ , code is located in frontend/ , so making changes there should have instant effect on the page. Keep in mind that React is loading data from Django, and that it has to be built so that Django can serve it. | ||
|
||
### Making changes to the frontend | ||
|
||
The way React is added is more complicated than the usual SPA project and this is because React is used as a library loaded by Django Templates, so it is not a standalone project and is not handling routes etc. | ||
|
||
The two directories to consider are: | ||
* frontend/src , for the React files | ||
* templates/, for the Django templates. | ||
|
||
Django is using a highly intuitive hierarchical templating system (https://docs.djangoproject.com/en/4.2/ref/templates/), where the base template is templates/root.html and all other templates are extending it. | ||
|
||
React is called through the Django templates, eg templates/cms/media.html is loading js/media.js | ||
|
||
In order to make changes to React code, edit code on frontend/src and check it's effect on http://localhost:8088/ . Once ready, build it and copy it to the Django static folder, so that it is served by Django. | ||
|
||
### Development workflow with the frontend | ||
1. Edit frontend/src/ files | ||
2. Check changes on http://localhost:8088/ | ||
3. Build frontend with `docker-compose -f docker-compose-dev.yaml exec frontend npm run dist` | ||
4. Copy static files to Django static folder with`cp -r frontend/dist/static/* static/` | ||
5. Restart Django - `docker-compose -f docker-compose-dev.yaml restart web` so that it uses the new static files | ||
6. Commit the changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ pytest-cov | |
pytest-django | ||
pytest-factoryboy | ||
Faker | ||
django-cors-headers | ||
|