Skip to content

Commit

Permalink
Merge pull request #50 from mrsarm/master
Browse files Browse the repository at this point in the history
Push latest changes to 4.2 branch
  • Loading branch information
mrsarm authored Sep 10, 2024
2 parents 9afb901 + 85ebc14 commit c8fa56a
Show file tree
Hide file tree
Showing 19 changed files with 221 additions and 232 deletions.
25 changes: 0 additions & 25 deletions .env.example

This file was deleted.

16 changes: 0 additions & 16 deletions .github/workflows/docker-image.yml

This file was deleted.

84 changes: 84 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Docker Image CI

on: [push]

jobs:

build-test-release:
name: Build, Test and Release

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
if: ${{ env.DOCKERHUB_TOKEN }}
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
env:
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Install pose
run: |
wget https://github.com/mrsarm/pose/releases/download/0.4.0/pose-0.4.0-x86_64-unknown-linux-gnu.tar.gz -O - \
| tar -xz
- name: Define $TAG variable
run: echo "TAG=$(./pose slug $GITHUB_REF_NAME)" >> "$GITHUB_ENV"
- name: Print tag and image names
run: |
echo "- TAG --> $TAG"
echo "- IMAGE --> mrsarm/django-coleman:$TAG"
- name: Build the Docker image
run: ./docker-build.sh $TAG

- name: Run tests
run: docker run --rm -e PROCESS_TYPE=test --name django-coleman "mrsarm/django-coleman:$TAG"

- name: Release Docker image
if: ${{ env.DOCKERHUB_TOKEN }}
run: docker push "mrsarm/django-coleman:$TAG"
env:
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Get compose.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./pose get -H "Authorization: token $GITHUB_TOKEN" \
"https://raw.githubusercontent.com/mrsarm/dcoleman-e2e/$TAG/compose.yaml" "$TAG:main"
- name: Get .env.example
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./pose get -H "Authorization: token $GITHUB_TOKEN" \
"https://raw.githubusercontent.com/mrsarm/dcoleman-e2e/$TAG/.env.example" "$TAG:main"
- name: Setup environment variables
run: cp .env.example .env

- name: Build compose file for CI
run: |
./pose --no-docker config --tag $TAG --tag-filter regex=mrsarm/ --progress -o ci.yaml
- name: Pull images
run: docker compose -f ci.yaml pull
&& docker compose -f ci.yaml pull dcoleman-e2e # services with profiles are not pulled by default

- name: Run e2e tests
run: docker compose -f ci.yaml run dcoleman-e2e

- name: Tag "latest"
if: ${{ env.DOCKERHUB_TOKEN && github.ref == 'refs/heads/master' }}
run: docker tag "mrsarm/django-coleman:$TAG" mrsarm/django-coleman:latest
env:
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Release "latest"
if: ${{ env.DOCKERHUB_TOKEN && github.ref == 'refs/heads/master' }}
run: docker push mrsarm/django-coleman:latest
env:
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ venv*/

/htmlcov
/.coverage

ci*.yaml
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11-slim
FROM python:3.11-slim-bookworm
LABEL maintainer="Mariano Ruiz <[email protected]>"

ENV CXXFLAGS="-mtune=intel -Os -pipe" \
Expand Down Expand Up @@ -76,4 +76,7 @@ RUN honcho start collectstatic compilemessages \

USER worker

HEALTHCHECK --interval=20s --timeout=3s \
CMD curl -f http://localhost:8000/health/?format=json || exit 1

CMD ["sh", "-c", "exec honcho start --no-prefix $PROCESS_TYPE"]
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ compilemessages: ./manage.py compilemessages --ignore 'venv*' --ignore '.venv*'
migrate: ./manage.py showmigrations && ./manage.py migrate
makemigrations: ./manage.py makemigrations && ./manage.py makemigrations partner mtasks
createadmin: ./manage.py shell -c "from django.contrib.auth.models import User; User.objects.create_superuser('$ADMIN_USERNAME', password='$ADMIN_PASSWORD')" && printf "User \"$ADMIN_USERNAME\" created.\n---> DON'T forget to CHANGE the password <---\n"
provision: honcho start createdb && honcho start migrate && honcho start createadmin
provision: honcho start createdb && honcho start migrate && honcho start createadmin || true
test: pytest --cov --cov-report=html --cov-report=term-missing --no-cov-on-fail --color=yes
38 changes: 24 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Features
partner (customer, provider...), description, responsible of the task, priority...
* Each task may have items: sub-tasks to be done.
* The built-in Django *Authentication and Authorization* system
to manage users and groups, login, etc.
to manage users and groups, login, etc, and optionally SSO with Google
within the Admin (`django-google-sso <https://github.com/megalus/django-google-sso>`_).
* Module `django-adminfilters <https://github.com/mrsarm/django-adminfilters>`_
that allows multiselection searches.
* Send emails when a task is created.
Expand All @@ -28,6 +29,11 @@ Features
* Pytest with some tests as example and code coverage reports configured.
* Docker and Docker Compose configurations (images published in
`Docker Hub <https://hub.docker.com/r/mrsarm/django-coleman>`_).
* CI environment, and E2E tests written with Playwright:
`dcoleman-e2e <https://github.com/mrsarm/dcoleman-e2e>`_. CI is executed with
GitHub Actions, and executed on each push in this project,
the viewer repo, or the E2E repo itself. The task also releases the image
in the Docker Registry.
* Ready to use "production" configurations as reference.

.. image:: docs/source/_static/img/django-coleman.png
Expand All @@ -39,7 +45,7 @@ Requirements

Docker, or:

* Python 3.8+ (tested with Python 3.8 and 3.11).
* Python 3.10+ (tested with 3.11).
* Django 4.2 LTS and other dependencies declared in
the ``requirements.txt`` file (use virtual environments or containers!).
* A Django compatible database like PostgreSQL (by default uses
Expand Down Expand Up @@ -117,21 +123,24 @@ Docker
A reference `<Dockerfile>`_ is provided, and the image published
in `Docker Hub <https://hub.docker.com/r/mrsarm/django-coleman>`_.

Also `<compose.yml>`_ and `<.env.example>`_ files are provided, you can run
all from here, Django Coleman, the viewer app and Postgres.
Also ``compose.yaml`` and ``.env.example`` files are provided in the
`dcoleman-e2e <https://github.com/mrsarm/dcoleman-e2e>`_ project, you
can run all from there, Django Coleman, the
`viewer <https://github.com/mrsarm/tornado-dcoleman-mtasks-viewer>`_ app
and Postgres, and the E2E tests.

First, copy the ``.env.example`` file as ``.env`` file, and edit whatever
value you want to::
First, copy the ``.env.example`` file as ``.env`` files from the E2E repo,
and edit whatever value you want to::

$ cp .env.example .env
$ cp ../dcoleman-e2e/.env.example .env

Then before run for the first time the containers, you have to either
download the images from Docker Hub or build them from the source code. To
build the images from the source code, execute::

$ docker compose build
$ ./docker-build.sh

Or to get the images from Docker Hub, execute::
Or to get the images from Docker Hub, execute from the dcoleman-e2e repo::

$ docker compose pull

Expand Down Expand Up @@ -168,7 +177,7 @@ to the Postgres container so even executing ``docker compose down``
won't delete the data, but if you want to start from scratch::

$ docker compose down
$ docker volume rm pg-coleman_data
$ docker volume rm django-coleman_data

Add changes in the code
^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -178,7 +187,7 @@ When adding changes in the code, the image needs to be updated::
$ docker compose build

Then run again. A script ``docker-build.sh`` with more advance
features and without using docker-compose is also provided
features and without using docker compose is also provided
to re-build the image.


Expand All @@ -192,10 +201,11 @@ set *debug* options to false::
$ DEBUG=False LANGUAGE_CODE=es-ar python3 manage.py runserver

Also in development environments an ``.env`` file can be used to setup
the environment variables easily, checkout the `<.env.example>`_ as example.
the environment variables easily, checkout the
`.env.example <https://github.com/mrsarm/dcoleman-e2e/blob/main/.env.example>`_ as example.
You can copy the example file and edit the variables you want to change::

$ cp .env.example .env
$ cp ../dcoleman-e2e/.env.example .env
$ vi .env

Some available settings:
Expand Down Expand Up @@ -300,6 +310,6 @@ About

**Project**: https://github.com/mrsarm/django-coleman

**Authors**: (2017-2023) Mariano Ruiz <[email protected]>
**Authors**: (2017-2024) Mariano Ruiz <[email protected]>

**License**: AGPL-v3
16 changes: 16 additions & 0 deletions coleman/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'health_check',
]

REST_ENABLED = env.bool('REST_ENABLED', False)
Expand Down Expand Up @@ -175,6 +176,21 @@
]
}

SESSION_COOKIE_AGE = 8 * 60 * 60


# Google SSO (django-google-sso)
GOOGLE_SSO_ENABLED = env.bool('GOOGLE_SSO_ENABLED', False)
if GOOGLE_SSO_ENABLED:
SSO_SHOW_FORM_ON_ADMIN_PAGE = env.bool('SSO_SHOW_FORM_ON_ADMIN_PAGE', True)
GOOGLE_SSO_CLIENT_ID = env.str("GOOGLE_SSO_CLIENT_ID", None)
GOOGLE_SSO_CLIENT_SECRET = env.str('GOOGLE_SSO_CLIENT_SECRET', None)
GOOGLE_SSO_PROJECT_ID = env.str('GOOGLE_SSO_PROJECT_ID', "django-coleman")
GOOGLE_SSO_AUTO_CREATE_USERS = True
GOOGLE_SSO_STAFF_LIST = ["*"]
GOOGLE_SSO_ALLOWABLE_DOMAINS = env.str('GOOGLE_SSO_ALLOWABLE_DOMAINS', "gmail.com").split(',')
INSTALLED_APPS += ['django_google_sso']


#
# Custom configurations
Expand Down
14 changes: 12 additions & 2 deletions coleman/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.urls import re_path, include
from django.urls import path, re_path, include
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.http import HttpResponseRedirect

Expand All @@ -29,6 +28,7 @@

urlpatterns = [
re_path('^api/v1/', include(router.urls)),
re_path(r'^health/', include('health_check.urls')),
]

if settings.ADMIN:
Expand All @@ -37,5 +37,15 @@
path('admin/', admin.site.urls),
] + urlpatterns

if settings.GOOGLE_SSO_ENABLED:
urlpatterns = [
path(
"google_sso/", include(
"django_google_sso.urls",
namespace="django_google_sso"
)
),
] + urlpatterns

admin.site.site_title = admin.site.site_header = settings.SITE_HEADER
admin.site.index_title = settings.INDEX_TITLE
Loading

0 comments on commit c8fa56a

Please sign in to comment.