Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push latest changes to 4.2 branch #50

Merged
merged 74 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
b368835
Merge pull request #33 from mrsarm/django/4.2
mrsarm Apr 27, 2023
cde8746
Bump django from 4.2 to 4.2.1 in /requirements
dependabot[bot] May 9, 2023
d426e81
Merge pull request #35 from mrsarm/dependabot/pip/requirements/django…
mrsarm May 10, 2023
fcc6e08
Add health-check
mrsarm Jun 16, 2023
86e21b4
Bump django from 4.2.1 to 4.2.3 in /requirements
dependabot[bot] Jul 5, 2023
d68c4b1
Merge pull request #36 from mrsarm/dependabot/pip/requirements/django…
mrsarm Aug 15, 2023
a6eb132
Bump uwsgi from 2.0.21 to 2.0.22 in /requirements
dependabot[bot] Aug 24, 2023
7a02e51
Merge pull request #37 from mrsarm/dependabot/pip/requirements/uwsgi-…
mrsarm Aug 25, 2023
5b5255e
Bump django from 4.2.3 to 4.2.7 in /requirements
dependabot[bot] Nov 2, 2023
4ade8d3
Merge pull request #38 from mrsarm/dependabot/pip/requirements/django…
mrsarm Nov 2, 2023
0e86dd4
Compose: DB healthcheck
mrsarm Jan 18, 2024
fc13ab3
Compose: root name
mrsarm Jan 18, 2024
0b4d0a0
Pytest opts
mrsarm Jan 18, 2024
9933225
Bump django from 4.2.7 to 4.2.10 in /requirements
dependabot[bot] Feb 7, 2024
2c9ad85
Merge pull request #39 from mrsarm/dependabot/pip/requirements/django…
mrsarm Feb 7, 2024
e9759d6
Bump django from 4.2.10 to 4.2.11 in /requirements
dependabot[bot] Mar 18, 2024
36dde43
Merge pull request #41 from mrsarm/dependabot/pip/requirements/django…
mrsarm Apr 9, 2024
9e2db1c
Bump sqlparse from 0.4.4 to 0.5.0 in /requirements
dependabot[bot] Apr 15, 2024
9441cd3
Merge pull request #42 from mrsarm/dependabot/pip/requirements/sqlpar…
mrsarm Apr 16, 2024
35dc349
Provision task can run more than once without fail
mrsarm Apr 17, 2024
2c86b71
Build the right image in CI
mrsarm Apr 17, 2024
99fd0c9
Publish docker image from CI
mrsarm Apr 17, 2024
c684d49
Slug version of branch for tag
mrsarm Apr 17, 2024
52856c0
Release latest on master
mrsarm Apr 17, 2024
79ed3fa
Merge pull request #43 from mrsarm/feature/push-image
mrsarm Apr 17, 2024
54e643a
Don't release "master" image
mrsarm Apr 17, 2024
0684702
Fix CI pipeline for master / latest
mrsarm Apr 17, 2024
dfb3fb0
Fix CI pipeline
mrsarm Apr 17, 2024
7009c58
Fix CI pipeline again
mrsarm Apr 17, 2024
a467ad5
Run e2e tests from CI
mrsarm Apr 19, 2024
8c5adac
Fix downloader
mrsarm Apr 19, 2024
c6c43a9
Fix downloader token
mrsarm Apr 19, 2024
82faa4c
Fix downloader order
mrsarm Apr 19, 2024
1b3f7cc
Rename CI workflow
mrsarm Apr 19, 2024
2950c2b
Download compose config with new pose
mrsarm Apr 24, 2024
8076804
CI pull all images
mrsarm Apr 25, 2024
d5ea44d
Typo
mrsarm Apr 25, 2024
fe62f81
Use pose to define tag
mrsarm Apr 25, 2024
ed50beb
Typo
mrsarm Apr 25, 2024
edd349c
Fix script definition
mrsarm Apr 25, 2024
4eaf389
Echo tag
mrsarm Apr 25, 2024
8606a9e
Fix print tag
mrsarm Apr 25, 2024
ff02537
Does run works without \ breaks?
mrsarm Apr 26, 2024
9f6240d
Rollback escaping
mrsarm Apr 26, 2024
486b6b2
Simply pose install
mrsarm Apr 28, 2024
1608918
Fix pipe to tar
mrsarm Apr 28, 2024
073ca0d
Doc updates
mrsarm Apr 29, 2024
7e93199
UUpdate pose version
mrsarm Apr 30, 2024
24356d7
Fix CI config
mrsarm Apr 30, 2024
222e7b0
Merge pull request #44 from mrsarm/feature/e2e
mrsarm Apr 30, 2024
f0f6ed3
Fix CI step
mrsarm Apr 30, 2024
3265ebf
Split echo command
mrsarm May 10, 2024
e952f89
Merge pull request #45 from mrsarm/fix/ci-split-echo
mrsarm May 10, 2024
a92d541
Bump djangorestframework from 3.14.0 to 3.15.2 in /requirements
dependabot[bot] Jun 26, 2024
6c39c15
Bump django from 4.2.11 to 4.2.15 in /requirements
dependabot[bot] Aug 7, 2024
8bd0036
CI conditional steps
mrsarm Aug 7, 2024
24c5eaa
Fix CI conditional steps
mrsarm Aug 7, 2024
b4d80c0
Fix CI conditional steps
mrsarm Aug 7, 2024
ed3f126
Merge pull request #48 from mrsarm/dependabot/pip/requirements/django…
mrsarm Aug 7, 2024
4c15674
Merge pull request #46 from mrsarm/dependabot/pip/requirements/django…
mrsarm Aug 7, 2024
89f7d11
Update test libs
mrsarm Aug 29, 2024
8d1772a
Add SSO with Google within the Admin
mrsarm Aug 29, 2024
1a11b86
Google SSO enable/disable at runtime
mrsarm Sep 2, 2024
4cb565f
Bump health package
mrsarm Sep 2, 2024
4fb8537
Bump django-extensions package
mrsarm Sep 2, 2024
796adba
Bump dj-database-url package
mrsarm Sep 2, 2024
163001c
Bump prod packages
mrsarm Sep 2, 2024
833bf14
Bump environs package
mrsarm Sep 2, 2024
4c214e2
Bump django-adminfilters package
mrsarm Sep 2, 2024
4bd2385
Fix package version
mrsarm Sep 2, 2024
6176adb
Expire session cookie after 8 hours
mrsarm Sep 2, 2024
1786ca1
README fixes
mrsarm Sep 2, 2024
45a2d01
Fix migration deps
mrsarm Sep 3, 2024
85ebc14
Merge pull request #49 from mrsarm/improvement/sso-google
mrsarm Sep 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading