Skip to content

Commit

Permalink
upgrade template, install queues
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Dec 2, 2024
1 parent fa3a765 commit 730610b
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 107 deletions.
3 changes: 2 additions & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: v0.0.1
_commit: v0.0.2
_src_path: gh:ninanor/python-template
author_name: Niccolò Cantù
debug: false
Expand All @@ -9,6 +9,7 @@ gis: false
ldap: false
project_name: GenLab Bestilling System
project_slug: genlab_bestilling
queue: true
repo_name: genlab_bestilling
repo_org: ninanor
rest: true
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Publish
on:
workflow_dispatch:
push:
pull_request:

jobs:
build:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: read
pages: write
id-token: write

environment:
# environment created automatically by GitHub
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Nix
uses: cachix/install-nix-action@v27
with:
nix_path: nixpkgs=channel:nixos-unstable

- name: Build
run: cd docs && nix-shell --run "mdbook build"

- name: Archive book
uses: actions/upload-artifact@v4
with:
name: book
path: docs/book/*

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: "docs/book"

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
35 changes: 2 additions & 33 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ jobs:
include:
- context: .
target: django
image: ghcr.io/ninanor/genlab_bestilling/backend-django
image: ghcr.io/${{ github.repository }}/backend-django
- context: ./nginx
image: ghcr.io/ninanor/genlab_bestilling/backend-nginx
- context: ./docs
image: ghcr.io/ninanor/genlab_bestilling/backend-docs
target: prod
image: ghcr.io/${{ github.repository }}/backend-nginx

permissions:
contents: read
Expand Down Expand Up @@ -55,31 +52,3 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# publish_docs:
# if: github.ref == 'refs/heads/main'
# needs: build
# runs-on: ubuntu-latest
# container:
# image: ghcr.io/ninanor/genlab_bestilling/backend-docs:main
# credentials:
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}

# permissions:
# pages: write
# id-token: write

# environment:
# # environment created automatically by GitHub
# name: github-pages
# url: ${{ steps.deployment.outputs.page_url }}

# steps:
# - name: Upload artifact
# uses: actions/upload-pages-artifact@v1
# with:
# path: "/var/www"
# # - name: Deploy to GitHub Pages
# # id: deployment
# # uses: actions/deploy-pages@v2
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This will create some shortcuts to run docker commands.
### Development setup
```
docker compose --profile dev up -d --build
# or dpli_dev up -d --build
# or dpcli_dev up -d --build
```
This will build the docker images for local development and startup everything.
**NOTE**: the `docker-compose.yml` uses bind-mounts, so editing your local django files will trigger a server reload without needing to rebuild the whole image.
Expand All @@ -32,15 +32,15 @@ The development setup will by default create a administrator user ([email protected]
At every container start it will apply new migrations.

#### Django commands
Django provides useful command line tools that can be executed with `manage.py`, to see a list of all the available commands run inside the django container `manage.py help`.
Django provides useful command line tools that can be executed with `manage.py`, to see a list of all the available commands run inside the django container `src/manage.py help`.
Check [Django documentation](https://docs.djangoproject.com/en/5.0/ref/django-admin/) for a list of the builtin commands.
Here are some examples of how to run them from your command line:
```
djcli_dev makemigrations # it will detect changes in your model files and will create SQL scripts to migrate tables accordingly
```
This is actually an alias for
```
docker compose --profile dev exec -it django-dev mange.py makemigrations
docker compose --profile dev exec -it django-dev src/manage.py makemigrations
```

You can then review the migration script created and apply it with:
Expand All @@ -62,7 +62,7 @@ models2puml #
This setup will create docker images optimized for production, without devtools installed
```
docker compose --profile prod up -d --build
# or dpli_prod up -d --build
# or dpcli_prod up -d --build
```

## How to update
Expand Down
36 changes: 14 additions & 22 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ services:
<<: *django-dev-env
DJANGO_MIGRATE: 1

queue:
<<: *django-prod
environment:
<<: *django-prod-env
WAIT_FOR_HTTP: http://django:8000/ht/
command: python manage.py procrastinate worker

queue-dev:
<<: *django-dev
environment:
<<: *django-dev-env
WAIT_FOR_HTTP: http://django:8000/ht/
command: python manage.py procrastinate worker

tailwind:
<<: *django-dev
tty: true
Expand All @@ -95,28 +109,6 @@ services:
ports:
- 5432:5432

# documentation
docs-dev:
build:
context: ./docs
target: dev
volumes:
- ./docs:/book
ports:
- '3001:3000'
command: serve --hostname 0.0.0.0
profiles:
- dev

docs:
build:
context: ./docs
target: prod
ports:
- '3000:80'
profiles:
- prod

nginx:
build:
context: ./nginx
Expand Down
35 changes: 0 additions & 35 deletions docs/Dockerfile

This file was deleted.

8 changes: 8 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# How to document

```
nix-shell
mdbook serve
mdbook build
```
10 changes: 0 additions & 10 deletions docs/default.conf.template

This file was deleted.

9 changes: 9 additions & 0 deletions docs/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
with import <nixpkgs> {
};

let in pkgs.mkShell rec {
buildInputs = [
mdbook
mdbook-kroki-preprocessor
];
}
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
dependencies = [
"django-environ",
"python-slugify>=8.0.1",
"Pillow==10.3.0",
"Pillow>=10.3.0",
"rcssmin",
"argon2-cffi",
"psycopg[binary]",
Expand All @@ -17,6 +17,7 @@ dependencies = [
"django-model-utils",
"django-allauth",
"django-crispy-forms",
"crispy-bootstrap5",
"django-health-check",
"django-probes",
"django-postgres-extra",
Expand All @@ -33,6 +34,7 @@ dependencies = [
"drf-standardized-errors[openapi]",
"djangorestframework-simplejwt",
"django-cors-headers",
"procrastinate[django]",
"django-polymorphic",
"django-unfold",
"crispy-tailwind",
Expand Down Expand Up @@ -109,4 +111,4 @@ select = ["E", "W", "I", "F", "UP", "S", "B", "A", "COM", "LOG", "PTH", "Q"]

[tool.ruff.lint.per-file-ignores]
"**/migrations/*.py" = ["E501", "ANN"]
"init.py" = ["S603", "S607"]
"nina-python-init.py" = ["S603", "S607"]
2 changes: 2 additions & 0 deletions src/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
DATABASES["default"]["ATOMIC_REQUESTS"] = True
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
DATABASES["default"]["CONN_MAX_AGE"] = env.int("CONN_MAX_AGE", default=None) # noqa F405

# URLS
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -113,6 +114,7 @@
"django_vite",
"django_filters",
"drf_standardized_errors",
"procrastinate.contrib.django",
]

LOCAL_APPS = [
Expand Down
6 changes: 6 additions & 0 deletions src/genlab_bestilling/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from procrastinate.contrib.django import app


@app.task(name="print-hello")
def print_hello():
print("hello")

0 comments on commit 730610b

Please sign in to comment.