diff --git a/.copier-answers.yml b/.copier-answers.yml index 3f23233..499d6d8 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -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 @@ -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 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..6203f93 --- /dev/null +++ b/.github/workflows/docs.yml @@ -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 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 104f4be..e9e5db7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 @@ -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 diff --git a/README.md b/README.md index bf64162..708885e 100644 --- a/README.md +++ b/README.md @@ -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. @@ -32,7 +32,7 @@ The development setup will by default create a administrator user (admin@nina.no 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: ``` @@ -40,7 +40,7 @@ djcli_dev makemigrations # it will detect changes in your model files and will c ``` 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: @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 76549ff..44fb8c2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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 diff --git a/docs/Dockerfile b/docs/Dockerfile deleted file mode 100644 index ac3dacb..0000000 --- a/docs/Dockerfile +++ /dev/null @@ -1,35 +0,0 @@ -FROM rust:1.74-slim-bookworm AS base - - -FROM base as builder -RUN apt-get update && \ - apt-get install --no-install-recommends -y \ - musl-tools -ENV ARC="x86_64-unknown-linux-musl" -RUN rustup target add "${ARC}" -ARG MDBOOK_VERSION=0.4.36 -RUN cargo install mdbook --version "${MDBOOK_VERSION}" --target "${ARC}" - - -FROM base as dev -RUN apt-get update && \ - apt-get install --no-install-recommends -y \ - musl-tools libssl-dev pkg-config -RUN cargo install mdbook-kroki-preprocessor -COPY --from=builder /usr/local/cargo/bin/mdbook /usr/local/bin/mdbook -WORKDIR /book -ENTRYPOINT [ "/usr/local/bin/mdbook" ] - - -FROM dev as build -ARG KROKI_ENDPOINT="https://kroki.io/" -ENV MDBOOK_PREPROCESSOR__KROKI_PREPROCESSOR__ENDPOINT="${KROKI_ENDPOINT}" -COPY src src -COPY theme theme -COPY book.toml . -RUN mdbook build - - -FROM nginx as prod -COPY --from=build /book/book/ /var/www/ -COPY default.conf.template /etc/nginx/templates/ diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..daa678a --- /dev/null +++ b/docs/README.md @@ -0,0 +1,8 @@ +# How to document + +``` +nix-shell + +mdbook serve +mdbook build +``` diff --git a/docs/default.conf.template b/docs/default.conf.template deleted file mode 100644 index 2e15fdc..0000000 --- a/docs/default.conf.template +++ /dev/null @@ -1,10 +0,0 @@ -server { - listen 80; - server_name localhost; - root /var/www; - - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; - } -} diff --git a/docs/shell.nix b/docs/shell.nix new file mode 100644 index 0000000..ae04d7b --- /dev/null +++ b/docs/shell.nix @@ -0,0 +1,9 @@ +with import { +}; + +let in pkgs.mkShell rec { + buildInputs = [ + mdbook + mdbook-kroki-preprocessor + ]; +} diff --git a/pyproject.toml b/pyproject.toml index 787f524..aeb2c91 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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]", @@ -17,6 +17,7 @@ dependencies = [ "django-model-utils", "django-allauth", "django-crispy-forms", + "crispy-bootstrap5", "django-health-check", "django-probes", "django-postgres-extra", @@ -33,6 +34,7 @@ dependencies = [ "drf-standardized-errors[openapi]", "djangorestframework-simplejwt", "django-cors-headers", + "procrastinate[django]", "django-polymorphic", "django-unfold", "crispy-tailwind", @@ -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"] diff --git a/src/config/settings/base.py b/src/config/settings/base.py index 5cfe980..02847b9 100644 --- a/src/config/settings/base.py +++ b/src/config/settings/base.py @@ -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 # ------------------------------------------------------------------------------ @@ -113,6 +114,7 @@ "django_vite", "django_filters", "drf_standardized_errors", + "procrastinate.contrib.django", ] LOCAL_APPS = [ diff --git a/src/genlab_bestilling/tasks.py b/src/genlab_bestilling/tasks.py new file mode 100644 index 0000000..8c8e967 --- /dev/null +++ b/src/genlab_bestilling/tasks.py @@ -0,0 +1,6 @@ +from procrastinate.contrib.django import app + + +@app.task(name="print-hello") +def print_hello(): + print("hello")