Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • hub/hub
  • cyroxx/hub
  • myigel/hub
  • thomasdotwtf/hub
4 results
Select Git revision
Loading items
Show changes

Commits on Source 713

613 additional commits have been omitted to prevent performance issues.
...@@ -10,3 +10,9 @@ src/hub/.settings.secret ...@@ -10,3 +10,9 @@ src/hub/.settings.secret
# local media files # local media files
src/media/ src/media/
.tools/
.vscode/
.venv*/
**/*_cache
...@@ -2,18 +2,16 @@ ...@@ -2,18 +2,16 @@
root = true root = true
[*] [*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8 charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true insert_final_newline = true
end_of_line = lf
indent_size = 2
indent_style = space
max_line_length = 120
trim_trailing_whitespace = true
[*.md] [*.md]
trim_trailing_whitespace = false trim_trailing_whitespace = false
[*.{css,html,js,scss,j2}] [*.py, *.toml]
indent_size = 2 indent_size = 4
[*.yml]
indent_size = 2
# Reformat with ruff
cad2f7373a716750d234842d93849af3014b72ad
# Reformat commits # Reformat commits
dc0e95b225cf4db7aa4ff67a4bcd3572625eba56 dc0e95b225cf4db7aa4ff67a4bcd3572625eba56
14b7cb96e61e576ea62f5ee1b98d8bf4337895a8 14b7cb96e61e576ea62f5ee1b98d8bf4337895a8
## ruff
cad2f7373a716750d234842d93849af3014b72ad
## prettier
0bb342a92c644a25ca11b549c7a94c996c591279
## djLint
31839261af33014cbc7d5af93fcd1189d91d4755
# Split PlainUI views # Split PlainUI views
caeff36b26f18a0732ddfcc752752529787a0632 caeff36b26f18a0732ddfcc752752529787a0632
/.yarn/** linguist-vendored
/.yarn/releases/* binary
/.yarn/plugins/**/* binary
/.pnp.* binary linguist-generated
...@@ -83,15 +83,6 @@ db.sqlite3-journal ...@@ -83,15 +83,6 @@ db.sqlite3-journal
profile_default/ profile_default/
ipython_config.py ipython_config.py
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
.pdm-python
# Environments # Environments
.env .env
.venv .venv
...@@ -108,3 +99,13 @@ dmypy.json ...@@ -108,3 +99,13 @@ dmypy.json
# Cython debug symbols # Cython debug symbols
cython_debug/ cython_debug/
# yarn
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
# SDKS are excluded as we do not want them in the repository
# !.yarn/sdks
!.yarn/versions
...@@ -5,6 +5,7 @@ stages: ...@@ -5,6 +5,7 @@ stages:
- container-test - container-test
- publish - publish
- deploy - deploy
- cleanup
workflow: workflow:
rules: rules:
...@@ -28,15 +29,20 @@ workflow: ...@@ -28,15 +29,20 @@ workflow:
# Use build cache to speed up CI # Use build cache to speed up CI
default: default:
cache: cache:
- key:
files:
- uv.lock
paths:
- $UV_CACHE_DIR
- key: "python-default" - key: "python-default"
paths: paths:
- .cache/pip - .cache/pip
- .cache/pdm
- key: - key:
files: files:
- src/plainui/yarn.lock - src/plainui/yarn.lock
- yarn.lock
paths: paths:
- .yarn-cache/ - .yarn/cache/
.django_runner_settings: .django_runner_settings:
before_script: before_script:
...@@ -46,20 +52,27 @@ default: ...@@ -46,20 +52,27 @@ default:
"tag": "$CI_COMMIT_TAG", "tag": "$CI_COMMIT_TAG",
"commit": "$CI_COMMIT_SHA", "commit": "$CI_COMMIT_SHA",
"branch": "$CI_COMMIT_BRANCH", "branch": "$CI_COMMIT_BRANCH",
"ci": true "ci": true,
"pipeline": {
"id": "$CI_PIPELINE_ID",
"url": "$CI_PIPELINE_URL",
"date": "$CI_PIPELINE_CREATED_AT"
}
} }
EOF EOF
services: services:
- name: postgis/postgis:15-3.3 - name: postgis/postgis:15-3.3
alias: db_server alias: db_server
variables: variables:
ALLOWED_HOSTS: "127.0.0.1,hubapp" ALLOWED_HOSTS: "127.0.0.1,hubapp,hubapp-${CI_JOB_ID}"
DJANGO_DEBUG: "I_KNOW_WHAT_I_AM_DOING" DJANGO_DEBUG: "I_KNOW_WHAT_I_AM_DOING"
POSTGRES_HOST_AUTH_METHOD: trust POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_PASSWORD: runner POSTGRES_PASSWORD: runner
POSTGRES_USER: ci POSTGRES_USER: ci
SSO_SECRET_GENERATE: "True" SSO_SECRET_GENERATE: "True"
STORAGE_TYPE: local STORAGE_TYPE: local
UV_CACHE_DIR: .uv-cache
# Kaniko build setup # Kaniko build setup
.build: .build:
...@@ -69,15 +82,13 @@ default: ...@@ -69,15 +82,13 @@ default:
name: gcr.io/kaniko-project/executor:debug name: gcr.io/kaniko-project/executor:debug
entrypoint: [""] entrypoint: [""]
variables: variables:
KANIKO_CACHE_ARGS: KANIKO_CACHE_ARGS: --cache=true
--cache=true
--cache-copy-layers=true --cache-copy-layers=true
--cache-run-layers=true --cache-run-layers=true
--cache-ttl=24h --cache-ttl=24h
--cache-dir=$CI_PROJECT_DIR/.cache/kaniko --cache-dir=$CI_PROJECT_DIR/.cache/kaniko
--cache-repo=$CI_REGISTRY_IMAGE/cache --cache-repo=$CI_REGISTRY_IMAGE/cache
KANIKO_ARGS: KANIKO_ARGS: --skip-unused-stages=true
--skip-unused-stages=true
--context $CI_PROJECT_DIR --context $CI_PROJECT_DIR
--build-arg REGISTRY=git.cccv.de/crews/hub/dependency_proxy/containers/ --build-arg REGISTRY=git.cccv.de/crews/hub/dependency_proxy/containers/
before_script: before_script:
...@@ -105,45 +116,45 @@ default: ...@@ -105,45 +116,45 @@ default:
"ci": true "ci": true
} }
EOF EOF
after_script:
- uv cache prune --ci
# Crane setup
generate_css: .crane:
extends: image:
- .default-rules name: gcr.io/go-containerregistry/crane:debug
image: node:20-bookworm entrypoint: [""]
stage: prepare variables:
needs: [] GIT_STRATEGY: none
script: before_script:
- cd src/plainui/ - '[ -n "$DOCKER_CONFIG" ] || export DOCKER_CONFIG=$HOME/.docker'
- echo 'yarn-offline-mirror ".yarn-cache/"' >> .yarnrc - crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- echo 'yarn-offline-mirror-pruning true' >> .yarnrc
- yarn install --non-interactive --no-progress --frozen-lockfile
- yarn run build
artifacts:
paths:
- src/plainui/static/plainui/rc3*.css*
meta_build: meta_build:
stage: prepare stage: prepare
extends: .build extends: .build
variables: variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" UV_CACHE_DIR: .uv-cache
script: script:
- /kaniko/executor - /kaniko/executor
$KANIKO_ARGS $KANIKO_ARGS
$KANIKO_CACHE_ARGS $KANIKO_CACHE_ARGS
--dockerfile $CI_PROJECT_DIR/Dockerfile --dockerfile $CI_PROJECT_DIR/Dockerfile
--target base --target meta
--destination $CI_REGISTRY_IMAGE/build_image:$CI_PIPELINE_ID --destination $CI_REGISTRY_IMAGE/meta_image:mi-$CI_PIPELINE_ID
rules: rules:
- when: always - when: always
.test: .test:
extends: extends:
- .django_runner_settings - .django_runner_settings
image: $CI_REGISTRY_IMAGE/build_image:$CI_PIPELINE_ID image: $CI_REGISTRY_IMAGE/meta_image:mi-$CI_PIPELINE_ID
variables:
UV_CACHE_DIR: .uv-cache
needs: needs:
- meta_build - meta_build
after_script:
- uv cache prune --ci
app_version: app_version:
stage: test stage: test
...@@ -154,8 +165,8 @@ app_version: ...@@ -154,8 +165,8 @@ app_version:
DATABASE_URL: "postgis://ci:runner@db_server/migrations" DATABASE_URL: "postgis://ci:runner@db_server/migrations"
script: script:
- python3 -V - python3 -V
- pdm sync -d --no-editable -G dev - uv sync
- pdm app_version - uv run task app_version
allow_failure: true allow_failure: true
rules: rules:
- when: always - when: always
...@@ -165,8 +176,7 @@ lint: ...@@ -165,8 +176,7 @@ lint:
extends: .test extends: .test
script: script:
- python3 -V - python3 -V
- pdm sync -d --no-editable -G dev - tox -e py-lint,html-lint
- pdm run lint
allow_failure: true allow_failure: true
rules: rules:
- when: always - when: always
...@@ -176,8 +186,24 @@ format: ...@@ -176,8 +186,24 @@ format:
extends: .test extends: .test
script: script:
- python3 -V - python3 -V
- pdm sync -d --no-editable -G dev - tox -e py-format,html-format
- pdm run format - git diff --exit-code -- . ':!src/version.json'
allow_failure: true
rules:
- when: always
format_prettier:
image: node:22-alpine
stage: test
needs: []
before_script:
- apk add --no-cache git
- corepack enable
- 'echo "cacheFolder: \".yarn/cache/\"" >> .yarnrc.yml'
- yarn install --immutable
script:
- yarn format
- git diff --exit-code -- . ':!src/version.json' ':!.yarnrc.yml'
allow_failure: true allow_failure: true
rules: rules:
- when: always - when: always
...@@ -191,8 +217,8 @@ migration_check: ...@@ -191,8 +217,8 @@ migration_check:
DATABASE_URL: "postgis://ci:runner@db_server/migrations" DATABASE_URL: "postgis://ci:runner@db_server/migrations"
script: script:
- python3 -V - python3 -V
- pdm sync -d --no-editable -G dev - uv run task manage makemigrations --check
- pdm run check-migrations - uv run task manage makemigrations --dry-run
translations_check: translations_check:
stage: test stage: test
...@@ -204,8 +230,8 @@ translations_check: ...@@ -204,8 +230,8 @@ translations_check:
allow_failure: true allow_failure: true
script: script:
- python3 -V - python3 -V
- pdm install --no-editable --prod - uv sync
- pdm manage makemessages - uv run task manage makemessages
- git diff --exit-code -- . ':!src/version.json' - git diff --exit-code -- . ':!src/version.json'
requirements_export: requirements_export:
...@@ -213,16 +239,16 @@ requirements_export: ...@@ -213,16 +239,16 @@ requirements_export:
extends: .test extends: .test
script: script:
- python3 -V - python3 -V
- pdm lock --check - uv lock --check
- pdm export --no-hashes -o requirements.txt --prod - uv export --frozen -o=requirements.dev.txt --no-hashes --all-groups
- pdm export --no-hashes -o requirements.dev.txt --de - uv export --frozen -o=requirements.txt --no-hashes --no-dev
- git diff --exit-code -- . ':!src/version.json' - git diff --exit-code -- . ':!src/version.json'
rules: rules:
- changes: - changes:
- requirements.txt - requirements.txt
- requirements.dev.txt - requirements.dev.txt
- project.toml - project.toml
- pdm.lock - uv.lock
django-tests: django-tests:
stage: test stage: test
...@@ -238,22 +264,24 @@ django-tests: ...@@ -238,22 +264,24 @@ django-tests:
DATABASE_URL: "postgis://ci:runner@db_server/self_test" DATABASE_URL: "postgis://ci:runner@db_server/self_test"
script: script:
- python3 -V - python3 -V
- pdm sync -d --no-editable -G dev - tox -e django-test
- pdm run test - tox -e coverage-report
- pdm run coverage xml -i
coverage: '/(?i)total(?:\s+\d+){4}\s+(\d+)%/' coverage: '/(?i)total(?:\s+\d+){4}\s+(\d+)%/'
artifacts: artifacts:
reports: reports:
coverage_report: coverage_report:
coverage_format: cobertura coverage_format: cobertura
path: .tools/coverage/coverage.xml path: .tools/coverage/report.xml
paths:
- .tools/coverage/html_report/
expire_in: 1 week
expose_as: "HTML Coverage Report"
build_nginx: build_nginx:
stage: build stage: build
extends: extends:
- .build - .build
needs: needs:
- generate_css
- migration_check - migration_check
- django-tests - django-tests
script: script:
...@@ -269,7 +297,6 @@ build_release: ...@@ -269,7 +297,6 @@ build_release:
extends: extends:
- .build - .build
needs: needs:
- generate_css
- migration_check - migration_check
- django-tests - django-tests
script: script:
...@@ -315,12 +342,12 @@ build_test: ...@@ -315,12 +342,12 @@ build_test:
SERVE_API: "no" SERVE_API: "no"
SERVE_BACKOFFICE: "no" SERVE_BACKOFFICE: "no"
SERVE_FRONTEND: "no" SERVE_FRONTEND: "no"
BASE_URL: http://hubapp:8000 BASE_URL: http://hubapp-${CI_JOB_ID}:8000
services: services:
- name: postgis/postgis:15-3.3 - name: postgis/postgis:15-3.3
alias: db_server alias: db_server
- name: "$CI_REGISTRY_IMAGE/ci/hub:ci-$CI_PIPELINE_ID-test" - name: "$CI_REGISTRY_IMAGE/ci/hub:ci-$CI_PIPELINE_ID-test"
alias: hubapp alias: hubapp-${CI_JOB_ID}
variables: variables:
DJANGO_CREATE_ADMIN_PASSWORD: "Test1234" DJANGO_CREATE_ADMIN_PASSWORD: "Test1234"
DJANGO_DEBUG: "no" DJANGO_DEBUG: "no"
...@@ -330,6 +357,8 @@ build_test: ...@@ -330,6 +357,8 @@ build_test:
SELECTED_CONFERENCE_ID: "017c0749-a2ea-4f86-92cd-e60b4508dd98" SELECTED_CONFERENCE_ID: "017c0749-a2ea-4f86-92cd-e60b4508dd98"
before_script: before_script:
- pip3 install requests - pip3 install requests
# TODO: remove this sleep once we have debugged the case for the 0 ms failure
- sleep 30
- echo "testing on $BASE_URL" - echo "testing on $BASE_URL"
- curl --max-time 8 --retry 3 --fail ${BASE_URL}/.well-known/version - curl --max-time 8 --retry 3 --fail ${BASE_URL}/.well-known/version
- curl --max-time 3 --retry 3 --fail ${BASE_URL}/.well-known/health - curl --max-time 3 --retry 3 --fail ${BASE_URL}/.well-known/health
...@@ -381,47 +410,19 @@ test_nginx_static: ...@@ -381,47 +410,19 @@ test_nginx_static:
.publish-image: .publish-image:
stage: publish stage: publish
extends: .crane
needs: needs:
- build_release - build_release
- test_image_frontend - test_image_frontend
- test_image_api - test_image_api
- test_nginx_static - test_nginx_static
image:
name: gcr.io/go-containerregistry/crane:debug
entrypoint: [""]
variables:
GIT_STRATEGY: none
before_script:
- '[ -n "$DOCKER_CONFIG" ] || export DOCKER_CONFIG=$HOME/.docker'
- crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
.publish-clean:
extends:
- .publish-image
after_script:
- crane delete $CI_REGISTRY_IMAGE/ci/hub:ci-${CI_PIPELINE_ID}-test
- crane delete $CI_REGISTRY_IMAGE/ci/hub:ci-${CI_PIPELINE_ID}
- crane delete $CI_REGISTRY_IMAGE/ci/nginx:ci-${CI_PIPELINE_ID}
publish-commit:
extends:
- .publish-clean
script:
- crane tag $CI_REGISTRY_IMAGE/ci/hub:ci-${CI_PIPELINE_ID} ${CI_COMMIT_SHORT_SHA}
- crane tag $CI_REGISTRY_IMAGE/ci/nginx:ci-${CI_PIPELINE_ID} ${CI_COMMIT_SHORT_SHA}
rules:
- if: '$CI_COMMIT_BRANCH == "develop" || $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_TAG'
- when: never
publish-mr: publish-mr:
extends: extends:
- .publish-image - .publish-image
needs:
- publish-commit
script: script:
- crane tag $CI_REGISTRY_IMAGE/ci/hub:${CI_COMMIT_SHORT_SHA} mr-${CI_MERGE_REQUEST_ID} - crane tag $CI_REGISTRY_IMAGE/ci/hub:ci-$CI_PIPELINE_ID mr-${CI_MERGE_REQUEST_ID}
- crane tag $CI_REGISTRY_IMAGE/ci/nginx:${CI_COMMIT_SHORT_SHA} mr-${CI_MERGE_REQUEST_ID} - crane tag $CI_REGISTRY_IMAGE/ci/nginx:ci-$CI_PIPELINE_ID mr-${CI_MERGE_REQUEST_ID}
rules: rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- when: never - when: never
...@@ -429,11 +430,9 @@ publish-mr: ...@@ -429,11 +430,9 @@ publish-mr:
publish-develop: publish-develop:
extends: extends:
- .publish-image - .publish-image
needs:
- publish-commit
script: script:
- crane copy $CI_REGISTRY_IMAGE/ci/hub:${CI_COMMIT_SHORT_SHA} $CI_REGISTRY_IMAGE:development - crane copy $CI_REGISTRY_IMAGE/ci/hub:ci-$CI_PIPELINE_ID $CI_REGISTRY_IMAGE:development
- crane copy $CI_REGISTRY_IMAGE/ci/nginx:${CI_COMMIT_SHORT_SHA} $CI_REGISTRY_IMAGE/nginx:development - crane copy $CI_REGISTRY_IMAGE/ci/nginx:ci-$CI_PIPELINE_ID $CI_REGISTRY_IMAGE/nginx:development
rules: rules:
- if: $CI_COMMIT_BRANCH == 'develop' - if: $CI_COMMIT_BRANCH == 'develop'
- when: never - when: never
...@@ -442,17 +441,33 @@ publish-develop: ...@@ -442,17 +441,33 @@ publish-develop:
publish-production: publish-production:
extends: extends:
- .publish-image - .publish-image
needs:
- publish-commit
script: script:
- crane copy $CI_REGISTRY_IMAGE/ci/hub:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:production - crane copy $CI_REGISTRY_IMAGE/ci/hub:ci-$CI_PIPELINE_ID $CI_REGISTRY_IMAGE:production
- crane tag $CI_REGISTRY_IMAGE:production latest - crane tag $CI_REGISTRY_IMAGE:production latest
- crane copy $CI_REGISTRY_IMAGE/ci/nginx:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE/nginx:production - crane copy $CI_REGISTRY_IMAGE/ci/nginx:ci-$CI_PIPELINE_ID $CI_REGISTRY_IMAGE/nginx:production
- crane tag $CI_REGISTRY_IMAGE/nginx:production latest - crane tag $CI_REGISTRY_IMAGE/nginx:production latest
rules: rules:
- if: '$CI_COMMIT_TAG =~ /^prod-\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$/' - if: '$CI_COMMIT_TAG =~ /^prod-\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$/'
- when: never - when: never
publish-sentry-release:
stage: publish
image: python:3.11-bookworm
needs:
- publish-production
before_script:
- pip3 install sentry-cli
script:
- sentry-cli releases new $CI_COMMIT_TAG
- sentry-cli releases set-commits $CI_COMMIT_TAG --commit "hub / hub@$CI_COMMIT_SHA"
- sentry-cli releases finalize $CI_COMMIT_TAG
rules:
# skip if SENTRY URL is not set
- if: $SENTRY_URL == null
when: never
- if: '$CI_COMMIT_TAG =~ /^prod-\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$/'
- when: never
deploy_develop: deploy_develop:
stage: deploy stage: deploy
allow_failure: true allow_failure: true
...@@ -482,6 +497,7 @@ deploy_production: ...@@ -482,6 +497,7 @@ deploy_production:
allow_failure: true allow_failure: true
needs: needs:
- publish-production - publish-production
- publish-sentry-release
image: python:3.11-bookworm image: python:3.11-bookworm
script: script:
- 'curl -X POST "$DEPLOYMENT_SERVICEWEBHOOK_URL_PRODUCTION"' - 'curl -X POST "$DEPLOYMENT_SERVICEWEBHOOK_URL_PRODUCTION"'
...@@ -500,3 +516,28 @@ deploy_production: ...@@ -500,3 +516,28 @@ deploy_production:
# otherwise, skip this # otherwise, skip this
- when: never - when: never
cleanup-ci-images:
stage: cleanup
extends:
- .crane
script:
- crane delete $CI_REGISTRY_IMAGE/ci/hub:ci-${CI_PIPELINE_ID}
- crane delete $CI_REGISTRY_IMAGE/ci/nginx:ci-${CI_PIPELINE_ID}
- crane delete $CI_REGISTRY_IMAGE/ci/hub:ci-${CI_PIPELINE_ID}-test
- crane delete $CI_REGISTRY_IMAGE/meta_image:mi-$CI_PIPELINE_ID
needs:
- job: publish-production
optional: true
- job: publish-develop
optional: true
- job: publish-mr
optional: true
rules:
- if: $CI_COMMIT_BRANCH == "develop"
- if: $CI_COMMIT_TAG
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $FORCE_PIPELINE_RUN == 'true'
when: on_success
- when: never
allow_failure: true
...@@ -2,14 +2,14 @@ exclude: ^.*.min.*|migrations|yarn.lock|venv$ ...@@ -2,14 +2,14 @@ exclude: ^.*.min.*|migrations|yarn.lock|venv$
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0 rev: v5.0.0
hooks: hooks:
- id: check-yaml - id: check-yaml
- id: check-toml - id: check-toml
- id: check-merge-conflict - id: check-merge-conflict
- id: check-ast - id: check-ast
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.5 rev: v0.9.7
hooks: hooks:
- id: ruff - id: ruff
args: [--fix] args: [--fix]
...@@ -18,31 +18,47 @@ repos: ...@@ -18,31 +18,47 @@ repos:
rev: v1.0.0 rev: v1.0.0
hooks: hooks:
- id: check-json5 - id: check-json5
- repo: https://github.com/pdm-project/pdm - repo: https://github.com/djlint/djLint
rev: 2.19.2 rev: v1.36.4
hooks: hooks:
- name: check production requirements - id: djlint-reformat-django
id: pdm-export - id: djlint-reformat-jinja
args: ['-o', 'requirements.txt', '--without-hashes', '--prod'] - id: djlint-django
files: ^pdm.lock$ - id: djlint-jinja
- repo: https://github.com/pdm-project/pdm - repo: https://github.com/astral-sh/uv-pre-commit
rev: 2.19.2 rev: 0.6.2
hooks: hooks:
- name: check development requirements - id: uv-lock
id: pdm-export - repo: https://github.com/astral-sh/uv-pre-commit
args: ['-o', 'requirements.dev.txt', '--without-hashes', '--dev'] rev: 0.6.2
files: ^pdm.lock$
- repo: https://github.com/pdm-project/pdm
rev: 2.19.2
hooks: hooks:
- id: pdm-lock-check - name: uv-export-prod
id: uv-export
args:
- --frozen
- -o=requirements.txt
- --no-hashes
- --no-dev
- name: uv-export-dev
id: uv-export
args:
- --frozen
- -o=requirements.dev.txt
- --no-hashes
- --all-groups
- repo: local - repo: local
hooks: hooks:
- name: Check for uncreated migrations. - name: Check for uncreated migrations.
id: migrations-check id: migrations-check
language: system language: system
entry: sh -c "src/manage.py makemigrations --check --dry-run" entry: sh -c "uv run task manage makemigrations --check --dry-run"
files: "models/.*.py$" files: "models/.*.py$"
types: types:
- python - python
stages: [pre-commit] stages:
- pre-commit
- name: prettier
id: prettier
entry: yarn prettier --write --ignore-unknown
language: node
"types": [text]
**/*.html
**/*.j2
.yarn
.yarnrc.yml
.venv*
static.dist/
**/vendor/**/*
**/list_script.js
src/core/fixtures/local/**/*
src/plainui/static/plainui/hub.*
src/**/templates/**/*.js
{}
activitypub
Andi
ASGI
backoffice
blocktranslate
clonbares
CLUBFRIENDS
Conferencemember
csrf
csrfmiddlewaretoken
datatables
dect
derefer
dereferrer
Dereferrer
Disclaimern
Einlöseseite
emph
endblocktranslate
endfor
endspaceless
engelsystem
exneuland
favorited
forloop
gettz
Habitatsbeitritt
Habitatseinladung
Habitatszuordnung
Historieneintrag
htmlhead
jitsi
JITSI
keepalive
markdownify
merch
Merch
metanav
mgmt
msgid
msgstr
naturaltime
nplurals
orga
Orga
pentabarf
plainui
pois
pretix
Registrierungs
Registrierungsinformationen
Registrierungsstart
renderable
Roang
Screensharing
Shadowbanned
Shibboleet
unhide
Vorlesungsraum
Vorlesungssaal
yesno
[tool.pylint.main]
# Specify a score threshold under which the program will exit with error.
fail-under = 8.0
# Files or directories to be skipped. They should be base names, not paths.
ignore = ["CVS", ".git", "__pycache__", ".tools", "node_modules", "migrations"]
# Add files or directories matching the regular expressions patterns to the
# ignore-list. The regex matches against paths and can be in Posix or Windows
# format. Because '\\' represents the directory delimiter on Windows systems, it
# can't be used as an escape character.
# ignore-paths =
# Files or directories matching the regular expression patterns are skipped. The
# regex matches against base names, not paths. The default value ignores Emacs
# file locks
ignore-patterns = ["^\\.#"]
# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
# number of processors available to use, and will cap the count on Windows to
# avoid hangs.
#jobs = 0
# List of plugins (as comma separated values of python module names) to load,
# usually to register additional checkers.
load-plugins = ["pylint_django"]
# Pickle collected data for later comparisons.
persistent = true
# Resolve imports to .pyi stubs if available. May reduce no-member messages and
# increase not-an-iterable messages.
prefer-stubs = true
# Minimum Python version to use for version dependent checks. Will default to the
# version used to run pylint.
py-version = "3.13"
[tool.pylint.basic]
# Good variable names which should always be accepted, separated by a comma.
good-names = ["i", "j", "k", "ex", "Run", "_"]
[tool.pylint.classes]
# Warn about protected attribute access inside special methods
# check-protected-access-in-special-methods =
# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods = [
"__init__",
"__new__",
"setUp",
"asyncSetUp",
"__post_init__",
]
[tool.pylint.design]
# List of regular expressions of class ancestor names to ignore when counting
# public methods (see R0903)
# exclude-too-few-public-methods =
# List of qualified class names to ignore when counting class parents (see R0901)
# ignored-parents =
# Maximum number of arguments for function / method.
max-args = 5
# Maximum number of attributes for a class (see R0902).
max-attributes = 7
# Maximum number of boolean expressions in an if statement (see R0916).
max-bool-expr = 5
# Maximum number of branch for function / method body.
max-branches = 12
# Maximum number of locals for function / method body.
max-locals = 15
# Maximum number of parents for a class (see R0901).
max-parents = 7
# Maximum number of positional arguments for function / method.
max-positional-arguments = 5
# Maximum number of public methods for a class (see R0904).
max-public-methods = 20
# Maximum number of return / yield for function / method body.
max-returns = 6
# Maximum number of statements in function / method body.
max-statements = 50
# Minimum number of public methods for a class (see R0903).
# min-public-methods =
[tool.pylint.format]
# Maximum number of characters on a single line.
max-line-length = 160
# Maximum number of lines in a module.
max-module-lines = 1000
[tool.pylint.imports]
# List of modules that can be imported at any level, not just the top level one.
allow-any-import-level = ["core.templatetags.hub_absolute"]
[tool.pylint.logging]
# The type of string formatting that logging methods do. `old` means using %
# formatting, `new` is for `{}` formatting.
logging-format-style = "new"
[tool.pylint."messages control"]
# Disable the message, report, category or checker with the given id(s). You can
# either give multiple identifiers separated by comma (,) or put this option
# multiple times (only on the command line, not in the configuration file where
# it should appear only once). You can also use "--disable=all" to disable
# everything first and then re-enable specific checks. For example, if you want
# to run only the similarities checker, you can use "--disable=all
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable = [
"raw-checker-failed",
"bad-inline-option",
"locally-disabled",
"file-ignored",
"suppressed-message",
"useless-suppression",
"deprecated-pragma",
"use-implicit-booleaness-not-comparison-to-string",
"use-implicit-booleaness-not-comparison-to-zero",
"use-symbolic-message-instead",
"missing-module-docstring", # we did not write docstrings for all modules - Can be enabled with time
"missing-class-docstring", # we did not write docstrings for all classes - Can be enabled with time
"missing-function-docstring", # we did not write docstrings for all functions - Can be enabled with time
"too-many-ancestors", # we do not want to limit the number of ancestors to have full use of django features
"wrong-import-position", # import position is enforced by isort/ruff
"wrong-import-order", # import order is enforced by isort/ruff
"logging-too-many-args", # The way most of our logging is done, would trigger this. Enable with logging statement updates
# Let's ignore design issues for now
"too-few-public-methods",
"too-many-ancestors",
"too-many-arguments",
"too-many-boolean-expressions",
"too-many-branches",
"too-many-function-args",
"too-many-instance-attributes",
"too-many-locals",
"too-many-nested-blocks",
"too-many-positional-arguments",
"too-many-public-methods",
"too-many-return-statements",
"too-many-statements",
"unused-argument",
"protected-access",
]
[tool.pylint.miscellaneous]
# List of note tags to take in consideration, separated by a comma.
notes = ["FIXME", "XXX", "TODO"]
[tool.pylint.refactoring]
# Maximum number of nested blocks for function / method body
max-nested-blocks = 5
[tool.pylint.reports]
# Set the output format. Available formats are: text, parseable, colorized, json2
# (improved json format), json (old json format) and msvs (visual studio). You
# can also give a reporter class, e.g. mypackage.mymodule.MyReporterClass.
output-format = "colorized"
# Tells whether to display a full report or only the messages.
reports = true
# Activate the evaluation score.
score = true
[tool.pylint.typecheck]
# List of decorators that produce context managers, such as
# contextlib.contextmanager. Add to this list to register other decorators that
# produce valid context managers.
contextmanager-decorators = ["contextlib.contextmanager"]
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
# expressions are accepted.
# generated-members =
# Tells whether missing members accessed in mixin class should be ignored. A
# class is considered mixin if its name matches the mixin-class-rgx option.
# Tells whether to warn about missing members when the owner of the attribute is
# inferred to be None.
ignore-none = true
# This flag controls whether pylint should warn about no-member and similar
# checks whenever an opaque object is returned when inferring. The inference can
# return multiple potential results while evaluating a Python object, but some
# branches might not be evaluated, which results in partial inference. In that
# case, it might be useful to still emit no-member and other checks for the rest
# of the inferred objects.
ignore-on-opaque-inference = true
# List of symbolic message names to ignore for Mixin members.
ignored-checks-for-mixins = [
"no-member",
"not-async-context-manager",
"not-context-manager",
"attribute-defined-outside-init",
]
# List of class names for which member attributes should not be checked (useful
# for classes with dynamically set attributes). This supports the use of
# qualified names.
ignored-classes = [
"optparse.Values",
"thread._local",
"_thread._local",
"argparse.Namespace",
]
[tool.pylint.variables]
# Tells whether unused global variables should be treated as a violation.
allow-global-unused-variables = true
File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
yarnPath: .yarn/releases/yarn-4.6.0.cjs
...@@ -50,12 +50,11 @@ Um eine andere Demo Datei zu laden kann die Umgebungsvariable `DJANGO_LOAD_FIXTU ...@@ -50,12 +50,11 @@ Um eine andere Demo Datei zu laden kann die Umgebungsvariable `DJANGO_LOAD_FIXTU
- Linux: Pakete `python3`, `postgresql` und `gettext` - Linux: Pakete `python3`, `postgresql` und `gettext`
- Mac: `brew install python3 postgresql gettext` bzw. https://postgresapp.com/ - Mac: `brew install python3 postgresql gettext` bzw. https://postgresapp.com/
- Windows: [latest stable Python 3 release](https://www.python.org/downloads/windows/) und [PostgreSQL Installer](https://www.postgresql.org/download/windows/) und [gettext binaries](https://mlocati.github.io/articles/gettext-iconv-windows.html) - Windows: [latest stable Python 3 release](https://www.python.org/downloads/windows/) und [PostgreSQL Installer](https://www.postgresql.org/download/windows/) und [gettext binaries](https://mlocati.github.io/articles/gettext-iconv-windows.html)
- Python Paketmanager: `pdm`: - Python Paketmanager: `uv`:
Kann mit OS Installationsmitteln oder mit `pip install pdm` installiert werden. Kann mit OS Installationsmitteln, mit `pip install uv` oder `pipx install uv` installiert werden. (Siehe die [Offizielle Dokumentation](https://docs.astral.sh/uv/getting-started/installation/))
1. Klone dieses Repository an beliebigen Ort. 1. Klone dieses Repository an beliebigen Ort.
1. Erstelle die virtuelle Umgebung mit `pdm info` 1. Installiere die python dependencies mit `uv sync`
1. Installiere die python dependencies mit `pdm install` 1. (falls nicht bereits vorhanden) lege einen PostgreSQL-User an (`createuser -P hub_app`) sowie eine Datenbank (`createdb -O hub_app hub`) - unter Linux ggf. via `sudo -u postgres`
6. (falls nicht bereits vorhanden) lege einen PostgreSQL-User an (`createuser -P hub_app`) sowie eine Datenbank (`createdb -O hub_app hub`) - unter Linux ggf. via `sudo -u postgres`
1. Konfiguriere deine Instanz mittels: 1. Konfiguriere deine Instanz mittels:
- Umgebungsvariablen (z.B. direnv, oder env Datei) - Umgebungsvariablen (z.B. direnv, oder env Datei)
- oder mittels einer `local_settings.py` in `src/hub/` an (Dokumentation zur Datenbankkonfiguration in der [Django-Dokumentation](https://docs.djangoproject.com/en/3.1/ref/settings/#databases)): - oder mittels einer `local_settings.py` in `src/hub/` an (Dokumentation zur Datenbankkonfiguration in der [Django-Dokumentation](https://docs.djangoproject.com/en/3.1/ref/settings/#databases)):
...@@ -67,8 +66,9 @@ SESSION_COOKIE_SECURE = False ...@@ -67,8 +66,9 @@ SESSION_COOKIE_SECURE = False
SESSION_COOKIE_DOMAIN = None SESSION_COOKIE_DOMAIN = None
IS_API = True IS_API = True
IS_FRONTEND = True IS_FRONTEND = True
STORAGE_TYPE = 'local'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # "send" emails as console output EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # "send" emails as console output
SELECTED_CONFERENCE_ID = '40ba6cda-1970-409f-81ef-efb87ef09d95' # change this to the id of your conference you want to display in frontend (matches the one from rc3_2020.json) SELECTED_CONFERENCE_ID = '40ba6cda-1970-409f-81ef-efb87ef09d95' # change this to the id of your conference you want to display in frontend (matches the one from rc3_2021.json)
METRICS_SERVER_IPS = ['127.0.0.1'] # Change this if you want to test the Prometheus / Grafana metrics endpoint (http://127.0.0.1:8000/metrics/) METRICS_SERVER_IPS = ['127.0.0.1'] # Change this if you want to test the Prometheus / Grafana metrics endpoint (http://127.0.0.1:8000/metrics/)
DATABASES = { DATABASES = {
...@@ -83,22 +83,28 @@ DATABASES = { ...@@ -83,22 +83,28 @@ DATABASES = {
} }
``` ```
8. Lege die Datenbanktabellen an: `pdm manage migrate` 8. Lege die Datenbanktabellen an: `uv run task manage migrate`
9. Richte einen Admin-Nutzer (für die Anwendung) ein: `pdm manage createsuperuser` 9. Richte einen Admin-Nutzer (für die Anwendung) ein: `uv run task manage createsuperuser`
10. optional: Import von Demo-Daten: `pdm manage.py loaddata .src/core/fixtures/rc3_2021.json` 10. optional: Import von Demo-Daten: `uv run task.py loaddata .src/core/fixtures/rc3_2021.json`
11. optional: Für deinen Adminuser via [Admin-Seite](http://localhost:8000/c3admin/) einen `ConferenceMember` anlegen um den User für das Frontend freizuschalten 11. optional: Für deinen Adminuser via [Admin-Seite](http://localhost:8000/c3admin/) einen `ConferenceMember` anlegen um den User für das Frontend freizuschalten
## Nutzung ## Nutzung
1. Aktiviere das virtual env `pdm venv activate` 2. Wende ggf. vorhandene DB-Migrations an (wenn du gerade aus dem Git geupdatet hast): `uv run task manage migrate`
2. Wende ggf. vorhandene DB-Migrations an (wenn du gerade aus dem Git geupdatet hast): `pdm manage migrate` 3. Stelle sicher dass alle Translations aktuell sind: `uv run task manage compilemessages`
3. Stelle sicher dass alle Translations aktuell sind: `pdm manage compilemessages` 4. Lasse alle staticfiles einsammeln: `uv run task manage collectstatic --noinput`
4. Lasse alle staticfiles einsammeln: `pdm manage collectstatic` 5. Starte den Dev-Server: `uv run task manage runserver`
5. Starte den Dev-Server: `pdm manage runserver`
6. Besuche die lokale Instanz: [Admin-Seite](http://localhost:8000/c3admin/), [API](http://localhost:8000/api/) und [plainui-Frontend](http://localhost:8000/) 6. Besuche die lokale Instanz: [Admin-Seite](http://localhost:8000/c3admin/), [API](http://localhost:8000/api/) und [plainui-Frontend](http://localhost:8000/)
## PlainUI Development Tipps ## PlainUI Development Tipps
### Ein Theme erstellen
Sämtliche Hub-Komponenten müssen eigene Variablen definieren. Alle Variablen sind in [`_variables-hub.scss`](./src/plainui/styles/_variables-hub.scss) enthalten.
Gegebenenfalls müssen neue Variablen hinzugefügt werden. Ein neues Theme kann dann Variablen aus Bootstrap oder dem Hub überschreiben.
Als Beispiel kann das [`hub-high-contrast.scss`](./src/plainui/styles/themes/hub-high-contrast.scss) genommen werden.
### CSS Kompilieren (PlainUi) ### CSS Kompilieren (PlainUi)
1. Gehe in das Verzeichnis `src/plainui/` 1. Gehe in das Verzeichnis `src/plainui/`
...@@ -106,6 +112,20 @@ DATABASES = { ...@@ -106,6 +112,20 @@ DATABASES = {
3. Führe `yarn build` aus um das CSS zu kompilieren 3. Führe `yarn build` aus um das CSS zu kompilieren
4. Um das CSS beim Entwickeln automatisch neu zu kompilieren gibt es `yarn watch` 4. Um das CSS beim Entwickeln automatisch neu zu kompilieren gibt es `yarn watch`
#### Kompiliertes CSS mit lokalem docker-compose Setup ausliefern
Um das kompilierte CSS über eine lokale Instanz auszuliefern die z.B. mit `docker compose up` ausgeliefert wurde muss dem `nginx` Container in der `docker-compose.yml` ein zusätzlicher Ordner gemounted werden:
```
volumes:
- ./src/plainui/static:/www/static
...
```
#### CSS Watch im Container
1. Um die Styles zu kompilieren und eine watch zu starten benutze `docker compose --profile build up -d local-static`
### Components ### Components
Wiederverwendbare Elemente können als Komponenten integriert werden. Dafür gibt es jeweils 2 "components"-Ordner. Die HTML-Komponenten befinden sich in `plainui/jinja2/plainui/components`. Sollten zusätzliche Styles benötigt werden, können diese in `plainui/styles/components` hinzugefügt werden, welche anschließend in `rc3.scss` integriert werden. Wichtig ist, ein **eigenes File pro Komponente** anzulegen. Für Jinja eignen sich dazu [Macros](https://jinja.palletsprojects.com/en/2.10.x/templates/#import) oder [Includes](https://jinja.palletsprojects.com/en/2.10.x/templates/#include). Zusätzlich ist die Komponente in der Übersicht hinzuzufügen - lokal erreichbar unter <http://localhost:8000/component_gallery>. Wiederverwendbare Elemente können als Komponenten integriert werden. Dafür gibt es jeweils 2 "components"-Ordner. Die HTML-Komponenten befinden sich in `plainui/jinja2/plainui/components`. Sollten zusätzliche Styles benötigt werden, können diese in `plainui/styles/components` hinzugefügt werden, welche anschließend in `rc3.scss` integriert werden. Wichtig ist, ein **eigenes File pro Komponente** anzulegen. Für Jinja eignen sich dazu [Macros](https://jinja.palletsprojects.com/en/2.10.x/templates/#import) oder [Includes](https://jinja.palletsprojects.com/en/2.10.x/templates/#include). Zusätzlich ist die Komponente in der Übersicht hinzuzufügen - lokal erreichbar unter <http://localhost:8000/component_gallery>.
...@@ -114,25 +134,26 @@ Wiederverwendbare Elemente können als Komponenten integriert werden. Dafür gib ...@@ -114,25 +134,26 @@ Wiederverwendbare Elemente können als Komponenten integriert werden. Dafür gib
### Abhängigkeitsverwaltung ### Abhängigkeitsverwaltung
Zur Verwaltung der verwendeten python Abhängigkeiten wir der [Paketmanager PDM](https://pdm-project.org/en/latest/) verwendet. Zur Verwaltung der verwendeten python Abhängigkeiten wir der [Paketmanager UV](https://docs.astral.sh/uv/) verwendet.
Mittels diesem werden die `requirements.txt` und die `requirements.dev.txt` erzeugt. Mittels diesem werden die `requirements.txt` und die `requirements.dev.txt` erzeugt.
#### Installation der aktuellen Abhängigkeiten #### Installation der aktuellen Abhängigkeiten
Um die aktuellen python Abhängigkeiten zu installieren kann das Kommando `pdm install` verwendet werden. Um die aktuellen python Abhängigkeiten zu installieren kann das Kommando `uv sync` verwendet werden.
Mit dem Kommando `pdm sync --clean` kann sichergestellt werden, dass genau die Versionen aus dem pdm lock file installiert werden. Mit dem Kommando `ur sync --frozen` kann sichergestellt werden, dass genau die Versionen aus dem uv lock file installiert werden.
*Achtung*: **Nicht in der Lock Datei enthaltene python Pakete werden deinstalliert!** _Achtung_: **Nicht in der Lock Datei enthaltene python Pakete werden deinstalliert!**
#### Hinzufügen von neuen Abhängigkeiten #### Hinzufügen von neuen Abhängigkeiten
Um neue Abhängigkeiten hinzuzufügen kann das Kommando `pdm add` verwendet werden. Mit dem Parameter `--dev` kann eine Abhängigkeit als Entwicklungs-Abhängigkeit deklariert werden. Diese wird dann in den Produktivinstanzen nicht installiert. Um neue Abhängigkeiten hinzuzufügen kann das Kommando `uv add` verwendet werden. Mit dem Parameter `--dev` kann eine Abhängigkeit als Entwicklungs-Abhängigkeit deklariert werden. Diese wird dann in den Produktivinstanzen nicht installiert.
Anschließend müssen die `requirements.txt` und `requirements.dev.txt` angepasst werden. Anschließend müssen die `requirements.txt` und `requirements.dev.txt` angepasst werden.
Wenn `pre-commit` verwendet wird, passiert dies automatisch beim commit. Wenn `pre-commit` verwendet wird, passiert dies automatisch beim commit.
Alternativ können die folgenden Kommandos verwendet werden Alternativ können die folgenden Kommandos verwendet werden
```bash ```bash
pdm export --no-hashes -o requirements.txt --prod uv export --format requirements-txt --no-hashes -o requirements.txt --no-dev
pdm export --no-hashes -o requirements.dev.txt --dev uv export --format requirements-txt --no-hashes -o requirements.dev.txt --all-groups
``` ```
### Debugging DJANGO ### Debugging DJANGO
...@@ -154,9 +175,9 @@ oder: ...@@ -154,9 +175,9 @@ oder:
### Übersetzungen extrahieren & compilieren ### Übersetzungen extrahieren & compilieren
- `pdm manage makemessages` - `uv run task manage makemessages`
- Die Übersetzungsdateien in `<app>/locale/<sprache>/LC_MESSAGES/django.po` wurden um alle neuen Übersetzungsstrings erweitert. Bearbeiten und jeweils bei `msgstr` die Übersetzungen einfügen! - Die Übersetzungsdateien in `<app>/locale/<sprache>/LC_MESSAGES/django.po` wurden um alle neuen Übersetzungsstrings erweitert. Bearbeiten und jeweils bei `msgstr` die Übersetzungen einfügen!
- `pdm manage compilemessages` - `uv run task manage compilemessages`
- Zum Ausprobieren müsst ihr django neu starten um die neuen Übersetzungsdateien zu laden - Zum Ausprobieren müsst ihr django neu starten um die neuen Übersetzungsdateien zu laden
### Übersetzungen definineren ### Übersetzungen definineren
...@@ -166,7 +187,7 @@ oder: ...@@ -166,7 +187,7 @@ oder:
### Static Files einsammeln lassen ### Static Files einsammeln lassen
- `pdm manage collectstatic` - `uv run task manage collectstatic`
- ohne dies brechen u.a. Unittests mit Fehlern wie "Missing staticfiles manifest entry" ab - ohne dies brechen u.a. Unittests mit Fehlern wie "Missing staticfiles manifest entry" ab
### Tests ### Tests
...@@ -174,7 +195,6 @@ oder: ...@@ -174,7 +195,6 @@ oder:
Es gibt Django (Unit-)Tests für die einzelnen Apps. Diese finden sich jeweils im `tests` Ordner der App. Es gibt Django (Unit-)Tests für die einzelnen Apps. Diese finden sich jeweils im `tests` Ordner der App.
Außerdem gibt es im repository root unter [tests](tests) auch noch einfache Integrationstests. Außerdem gibt es im repository root unter [tests](tests) auch noch einfache Integrationstests.
#### Test mit Übersetzten Inhalten #### Test mit Übersetzten Inhalten
Um sicherzustellen, dass Tests mit Übersetzungen in allen Umgebungen funktionieren, Um sicherzustellen, dass Tests mit Übersetzungen in allen Umgebungen funktionieren,
...@@ -182,6 +202,7 @@ müssen die Übersetzungsfunktionen gemocked werden. ...@@ -182,6 +202,7 @@ müssen die Übersetzungsfunktionen gemocked werden.
Dazu gibt es in `core.tests.utils` eine `mocktrans` Funktion die alle Text einfach mich `_trans` ergänzt (z.B. wird aus "Login" dann "Login_trans"). Dazu gibt es in `core.tests.utils` eine `mocktrans` Funktion die alle Text einfach mich `_trans` ergänzt (z.B. wird aus "Login" dann "Login_trans").
Die Funktion kann dann wie folgt verwendet werden: Die Funktion kann dann wie folgt verwendet werden:
```python ```python
with patch('core.models.ticket._', side_effect=mocktrans): with patch('core.models.ticket._', side_effect=mocktrans):
translation = funktions_aufruf() translation = funktions_aufruf()
...@@ -193,8 +214,8 @@ self.assertEqual(translation, "NoTIcket_trans") ...@@ -193,8 +214,8 @@ self.assertEqual(translation, "NoTIcket_trans")
Um die Tests ausführen zu können muss der Datenbanknutzer das Recht haben neue Datenbaken anzulegen. Um die Tests ausführen zu können muss der Datenbanknutzer das Recht haben neue Datenbaken anzulegen.
Dafür mit `psql postgres` die Datenbankkonsole starten. Dort `ALTER USER hub_app CREATEDB;` ausführen (ggf. `hub_app` durch den gewählten Nutzernamen ersetzen). Am Ende mit `Strg-D` Konsole wieder schließen. Dafür mit `psql postgres` die Datenbankkonsole starten. Dort `ALTER USER hub_app CREATEDB;` ausführen (ggf. `hub_app` durch den gewählten Nutzernamen ersetzen). Am Ende mit `Strg-D` Konsole wieder schließen.
Um die Django Tests auszuführen kann das Kommando `pdm test` verwendet werden. \ Um die Django Tests auszuführen kann das Kommando `uv run tox -e django-test` verwendet werden. \
Um nur die Tests einer App auszuführen stattdessen `pdm test -- <app>.tests` ausführen. \ Um nur die Tests einer App auszuführen stattdessen `uv run tox -e django-test -- <app>.tests` ausführen. \
Hilfreiche Argumente sind `-v 2` um die ausgeführten Tests anzuzeigen, `--failfast` um nach dem ersten Fehler abzubrechen, und `--keepdb` um nicht jedes mal die Migrationen durchführen zu müssen. \ Hilfreiche Argumente sind `-v 2` um die ausgeführten Tests anzuzeigen, `--failfast` um nach dem ersten Fehler abzubrechen, und `--keepdb` um nicht jedes mal die Migrationen durchführen zu müssen. \
Für weitere Infos zu dem Befehl ist https://docs.djangoproject.com/en/3.1/ref/django-admin/#django-admin-test hilfreich. Für weitere Infos zu dem Befehl ist https://docs.djangoproject.com/en/3.1/ref/django-admin/#django-admin-test hilfreich.
...@@ -221,8 +242,21 @@ Dieses hat die folgenden Kommandos: ...@@ -221,8 +242,21 @@ Dieses hat die folgenden Kommandos:
- `ruff check`: Diess Kommando checkt auf häufige Fehler in python code und hat auch teilweise Möglichkeiten diese zu beheben - `ruff check`: Diess Kommando checkt auf häufige Fehler in python code und hat auch teilweise Möglichkeiten diese zu beheben
- `ruff format`: Dieses Kommando re-formatiert alle python dateien nach einem voregebenen Code-Style - `ruff format`: Dieses Kommando re-formatiert alle python dateien nach einem voregebenen Code-Style
### djLint
**Leider ist es nicht möglich djLint so zu konfigurieren, dass es automatisch die richtigen Profile verwendet.**
**Wenn eine Integration in einen Editor gewünscht ist, muss dies berücksichtigt werden!**
Manuell kann es folgendermaßen ausgeführt werden:
- `djlint --profile django --extension html --reformat .` um alle .html Dateien zu formatieren
- `djlint --profile jinja --extension j2 --reformat .` um alle .j2 Dateien zu formatieren
- `djlint --lint .` um alle ein potenzielle Fehler per Linting zu finden
## Häufige Fehler ## Häufige Fehler
**Datenbank-Migration schlägt fehl mit "'DatabaseOperations' object has no attribute 'geo_db_type'"**
``` ```
$ ./manage.py migrate $ ./manage.py migrate
<snip> <snip>
...@@ -231,6 +265,16 @@ AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type' ...@@ -231,6 +265,16 @@ AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
Dieser Fehler tritt auf, wenn man [PostGIS](https://postgis.net/)-Felder mit dem normalen Django-Postgres-Backend anlegen möchte. Statt dessen als Engine `django.contrib.gis.db.backends.postgis` verwenden. Dieser Fehler tritt auf, wenn man [PostGIS](https://postgis.net/)-Felder mit dem normalen Django-Postgres-Backend anlegen möchte. Statt dessen als Engine `django.contrib.gis.db.backends.postgis` verwenden.
**Docker-Build schlägt fehl mit "error creating zfs mount"**
Hierbei handelt es sich um ein Problem von Docker multi-stage Builds und dem ZFS-Storage Treiber.
Da das Problem nur auftritt wenn einzelne Image-Layer nicht im Cache sind lässt sich das Problem umgehen indem man den Build solange ausführt bis er erfolgreich ist.
Ab Version 22 von `docker-ce` sollte das Problem nicht mehr auftreten.
Siehe auch den [zughörigen Issue auf GitHub](https://github.com/moby/buildkit/issues/1758).
## Docker Image Abhängigkeiten ## Docker Image Abhängigkeiten
Das Bild zeigt die aktuellen Docker Image Abhängigkeiten aus dem Multistage Dockerfile Das Bild zeigt die aktuellen Docker Image Abhängigkeiten aus dem Multistage Dockerfile
......
ARG REGISTRY="" ARG REGISTRY=""
FROM ${REGISTRY}python:3.13-bookworm as base FROM ${REGISTRY}python:3.13-bookworm AS base
COPY --from=ghcr.io/astral-sh/uv:0.5.21 /uv /uvx /bin/
ARG DEVELOPMENT=False
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
ENV PDM_CHECK_UPDATE=false # Set up uv environment
ENV UV_LINK_MODE=copy UV_COMPILE_BYTECODE=1 UV_TOOL_BIN_DIR=/opt/uv-bin/
RUN echo 'APT::Install-Recommends "false";' > /etc/apt/apt.conf.d/99-unattended-minimal && \ RUN echo 'APT::Install-Recommends "false";' > /etc/apt/apt.conf.d/99-unattended-minimal && \
echo 'APT::Install-Suggests "false";' >> /etc/apt/apt.conf.d/99-unattended-minimal && \ echo 'APT::Install-Suggests "false";' >> /etc/apt/apt.conf.d/99-unattended-minimal && \
...@@ -12,28 +12,30 @@ RUN echo 'APT::Install-Recommends "false";' > /etc/apt/apt.conf.d/99-unattended- ...@@ -12,28 +12,30 @@ RUN echo 'APT::Install-Recommends "false";' > /etc/apt/apt.conf.d/99-unattended-
RUN --mount=target=/var/lib/apt/lists/,type=cache,sharing=locked \ RUN --mount=target=/var/lib/apt/lists/,type=cache,sharing=locked \
--mount=target=/var/cache/apt/archives/,type=cache,sharing=locked \ --mount=target=/var/cache/apt/archives/,type=cache,sharing=locked \
--mount=target=/root/.cache/pip,type=cache,sharing=locked \
# Prevent apt cache cleaning # Prevent apt cache cleaning
rm -f /etc/apt/apt.conf.d/docker-clean && \ rm -f /etc/apt/apt.conf.d/docker-clean && \
apt-get update && \ apt-get update && \
apt-get install \ apt-get install \
gdal-bin \ gdal-bin \
gettext \ gettext \
locales \ locales && \
rsync && \
dpkg-reconfigure locales && \ dpkg-reconfigure locales && \
locale-gen C.UTF-8 && \ locale-gen C.UTF-8 && \
/usr/sbin/update-locale LANG=C.UTF-8 && \ /usr/sbin/update-locale LANG=C.UTF-8 && \
pip install -U pdm && \
# Fix caching issue with kaniko see: https://github.com/GoogleContainerTools/kaniko/issues/3246 # Fix caching issue with kaniko see: https://github.com/GoogleContainerTools/kaniko/issues/3246
mkdir -p /app/plainui mkdir -p /app/plainui
# Add path for future pdm location # Add path for future uv location
ENV PATH="/install/.venv/bin:$PATH" ENV PATH="/install/.venv/bin:/opt/uv-bin:$PATH"
######################################### [meta] #############################
FROM base AS meta
RUN uv tool install tox --with tox-uv
######################################### [build] ############################# ######################################### [build] #############################
FROM base as build FROM base AS build
ENV LC_ALL=C.UTF-8 ENV LC_ALL=C.UTF-8
...@@ -41,87 +43,53 @@ RUN --mount=target=/var/lib/apt/lists/,type=cache,sharing=locked \ ...@@ -41,87 +43,53 @@ RUN --mount=target=/var/lib/apt/lists/,type=cache,sharing=locked \
--mount=target=/var/cache/apt/archives/,type=cache,sharing=locked \ --mount=target=/var/cache/apt/archives/,type=cache,sharing=locked \
apt-get update && \ apt-get update && \
apt-get install \ apt-get install \
build-essential \ build-essential && \
yarnpkg && \
mkdir /install mkdir /install
WORKDIR /install WORKDIR /install
COPY pyproject.toml pdm.lock README.md /install/ COPY pyproject.toml uv.lock README.md /install/
RUN --mount=target=/root/.cache/pdm,type=cache,sharing=locked \ RUN --mount=type=cache,target=/root/.cache/uv \
pdm install --check --prod --no-editable uv sync --frozen --no-install-project --no-editable
######################################### [build-dev] ######################### ######################################### [build-dev] #########################
FROM build as build-dev FROM build AS build-dev
WORKDIR /install WORKDIR /install
RUN --mount=target=/root/.cache/pdm,type=cache,sharing=locked \ RUN --mount=type=cache,target=/root/.cache/uv \
pdm install --check --dev --no-editable uv sync --frozen --no-install-project --no-editable
######################################### [build-static] ###################### ######################################### [node-build] ########################
FROM build as build-static FROM ${REGISTRY}node:20-alpine AS node-base
# Only copy over the requirements files, use cache if they have not changed.
RUN mkdir -p /app/plainui/ RUN mkdir -p /app/plainui/
COPY src/plainui/package.json src/plainui/yarn.lock /app/plainui/ COPY src/plainui/package.json src/plainui/yarn.lock src/plainui/.yarnrc.yml /app/plainui/
COPY src/plainui/.yarn/releases/yarn-4.5.1.cjs /app/plainui/.yarn/releases/
WORKDIR /app/plainui WORKDIR /app/plainui
RUN /usr/bin/yarnpkg RUN corepack enable && \
/usr/local/bin/yarnpkg set version stable && \
COPY src/ /app/ /usr/local/bin/yarnpkg install
RUN /usr/bin/yarnpkg build
WORKDIR /app
RUN export DJANGO_SETTINGS_MODULE='hub.settings.build' && \
python3 /app/manage.py collectstatic --noinput && \
python3 /app/manage.py compilemessages && \
unset DJANGO_SETTINGS_MODULE
######################################### [nginx] #############################
FROM ${REGISTRY}nginx:1.25-alpine-slim as nginx-forwarder
ENV APP_SOCKET="/run/hub/app.sock"
ENV SCRIPT_NAME=""
VOLUME /www/media
COPY deployment/docker/index.html deployment/docker/error_*.html /www/default/
COPY deployment/docker/nginx.conf /etc/nginx/templates/default.conf.template
FROM nginx-forwarder as nginx
COPY --from=build-static /app/static.dist /www/static
######################################### [webworker-base] #################### ######################################### [webworker-base] ####################
FROM base as webworker-base FROM base AS webworker-base
ARG DEVELOPMENT
ENV APP_HOME=${APP_HOME:-/app_home} ENV APP_HOME=${APP_HOME:-/app_home}
VOLUME /data /app/media
ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1 ENV PYTHONUNBUFFERED=1
ENV LC_ALL=C.UTF-8 ENV LC_ALL=C.UTF-8
ENV DJANGO_SETTINGS_MODULE=hub.settings.default ENV DJANGO_SETTINGS_MODULE=hub.settings.default
ENV DOCKER_UID=1000 ENV DOCKER_UID=1000
RUN --mount=target=/var/lib/apt/lists/,type=cache,sharing=locked \ RUN useradd -u $DOCKER_UID -ms /bin/bash -d /app_home appuser
--mount=target=/var/cache/apt/archives/,type=cache,sharing=locked \
if [ "$DEVELOPMENT" = "True" ]; then\
apt-get install \
yarnpkg; \
fi && \
useradd -u $DOCKER_UID -ms /bin/bash -d /app_home appuser
COPY deployment/docker/app.sh /usr/local/bin/app COPY deployment/docker/app.sh /usr/local/bin/app
COPY deployment/docker/check_django.sh /usr/local/bin/hub_healthcheck COPY deployment/docker/check_django.sh /usr/local/bin/hub_healthcheck
COPY deployment/docker/check_psql.py /usr/local/bin/postgres_healthcheck COPY deployment/docker/check_psql.py /usr/local/bin/postgres_healthcheck
COPY --from=build /install/.venv /install/.venv
ENV PATH="/install/.venv/bin:$PATH" ENV PATH="/install/.venv/bin:$PATH"
RUN install -d -m 0755 -o appuser -g appuser /app/hub /data /app/media /run/hub && \ RUN install -d -m 0755 -o appuser -g appuser /app/hub /data /app/media /run/hub && \
...@@ -131,17 +99,53 @@ RUN install -d -m 0755 -o appuser -g appuser /app/hub /data /app/media /run/hub ...@@ -131,17 +99,53 @@ RUN install -d -m 0755 -o appuser -g appuser /app/hub /data /app/media /run/hub
ENTRYPOINT ["/usr/local/bin/app"] ENTRYPOINT ["/usr/local/bin/app"]
CMD ["webworker"] CMD ["webworker"]
######################################### [node-build] ######################
FROM node-base AS node-build
WORKDIR /app/plainui
COPY src/plainui/styles/ /app/plainui/styles
RUN /usr/local/bin/yarnpkg build
ENTRYPOINT ["/usr/local/bin/yarnpkg"]
CMD ["watch"]
######################################### [build-static] ######################
FROM build AS build-static
COPY --from=node-build /app/plainui/static/plainui/*.css* /app/plainui/static/plainui/
COPY /src/ /app
WORKDIR /app
RUN export DJANGO_SETTINGS_MODULE='hub.settings.build' && \
python3 /app/manage.py collectstatic --noinput && \
python3 /app/manage.py compilemessages && \
unset DJANGO_SETTINGS_MODULE
######################################### [nginx] #############################
FROM ${REGISTRY}nginx:1-alpine-slim AS nginx
ENV APP_SOCKET="/run/hub/app.sock"
ENV SCRIPT_NAME=""
COPY deployment/docker/index.html deployment/docker/error_*.html /www/default/
COPY deployment/docker/nginx.conf /etc/nginx/templates/default.conf.template
COPY --from=build-static /app/static.dist /www/static
######################################### [webworker] ######################### ######################################### [webworker] #########################
FROM webworker-base as webworker FROM webworker-base AS webworker
COPY --from=build /install/.venv /install/.venv
COPY --from=build-static --chown=appuser /app /app COPY --from=build-static --chown=appuser /app /app
USER appuser USER appuser
######################################### [dev] ############################### ######################################### [dev] ###############################
FROM webworker-base as dev FROM webworker-base AS dev
ENV DJANGO_SETTINGS_MODULE=hub.settings.dev ENV DJANGO_SETTINGS_MODULE=hub.settings.dev
ENV SERVE_API=yes ENV SERVE_API=yes
...@@ -154,11 +158,14 @@ RUN install -o appuser -g appuser -m 774 /dev/null /data/django.log ...@@ -154,11 +158,14 @@ RUN install -o appuser -g appuser -m 774 /dev/null /data/django.log
# Copy additional dev dependencies # Copy additional dev dependencies
COPY --from=build-dev /install/.venv /install/.venv COPY --from=build-dev /install/.venv /install/.venv
# Copy plainui styles
COPY --from=node-build /app/plainui/static/*.css* /app/plainui/static/
ENV PATH="/install/.venv/bin:$PATH" ENV PATH="/install/.venv/bin:$PATH"
USER appuser USER appuser
COPY --from=build-static --chown=appuser /app /app COPY --from=build-static --chown=appuser /app /app
WORKDIR /app WORKDIR /app
RUN export DJANGO_SETTINGS_MODULE='hub.settings.build' && \ RUN export DJANGO_SETTINGS_MODULE='hub.settings.build' && \
app build && \ python3 /app/manage.py collectstatic --noinput && \
python3 /app/manage.py compilemessages && \
unset DJANGO_SETTINGS_MODULE unset DJANGO_SETTINGS_MODULE
...@@ -31,17 +31,26 @@ als PDF: [Grobes Datenmodell](docs/Grobes Datenmodell.pdf) und [automatisch expo ...@@ -31,17 +31,26 @@ als PDF: [Grobes Datenmodell](docs/Grobes Datenmodell.pdf) und [automatisch expo
## REST API ## REST API
Am Beispiel der Konferenz-Slug "camp23", grundsätzlich sind alle hier aufgeführten Endpoints per GET abrufbar (Restriktionen bei nicht-öffentlichen Events, etc. sind möglich). Grundsätzlich sind alle hier aufgeführten Endpoints per GET abrufbar (Restriktionen bei nicht-öffentlichen Events, etc. sind möglich).
Manche Endpunkte sind zusätzlich "schreibbar" und können zur Anlage bzw. Bearbeitung der jeweiligen Daten genutzt werden. Manche Endpunkte sind zusätzlich "schreibbar" und können zur Anlage bzw. Bearbeitung der jeweiligen Daten genutzt werden.
Testinstanz: <https://hub.test.c3voc.de/api/> / <https://staging.hub.c3events.de/api/> \ Testinstanz: <https://hub.test.c3voc.de/api/> / <https://staging.hub.c3events.de/api/> \
Prodinstanz: <https://api.events.ccc.de/congress/2023/> Prodinstanz: <https://api.events.ccc.de/congress/2024/>
| Kategorie | Endpunkt | GET | POST | PUT | DEL | Beschreibung | | Kategorie | Endpunkt | GET | POST | PUT | DEL | Beschreibung |
| ---------- | ---------------------------------------- | --- | ---- | --- | --- | ----------------------------------------------------- | | ---------- | ---------------------------------------- | --- | ---- | --- | --- | ----------------------------------------------------- |
| Auth | `/auth/get-token` | | x | | | Ausstellen eines API-Tokens |
| Persönlich | `/me` | x | | x | | eigenes Profil / Settings | | Persönlich | `/me` | x | | x | | eigenes Profil / Settings |
| Persönlich | `/me/friends` | x | | x | x | Liste der Buddies |
| Persönlich | `/me/badges` | x | | | | Liste aller Badges/Achievements | | Persönlich | `/me/badges` | x | | | | Liste aller Badges/Achievements |
| Persönlich | `/me/events` | x | | | | Favorisierte Events |
| Persönlich | `/me/events/<uuid>/` | | | x | x | Events (ent-)favorisieren |
| Persönlich | `/me/friends` | x | | x | x | Liste der Buddies |
| Persönlich | `/me/received-messages/` | x | | | | Übersicht empfangener PN |
| Persönlich | `/me/received-messages/<uuid>` | x | | | | Details einer empfangenen PN |
| Persönlich | `/me/send-message` | | x | | | Send a new PN |
| Persönlich | `/me/sent-messages/` | x | | | | Übersicht gesendeter PN |
| Persönlich | `/me/sent-messages/<uuid>` | x | | | | Details einer gesendeten PN |
| Persönlich | `/me/delete-message/<uuid>` | x | | | | PN löschen |
| Konferenz | `/` | x | | | | Metadaten des Konferenz | | Konferenz | `/` | x | | | | Metadaten des Konferenz |
| Konferenz | `/tags` | x | | | | Liste aller Tags auf der Konferenz | | Konferenz | `/tags` | x | | | | Liste aller Tags auf der Konferenz |
| Konferenz | `/tracks` | x | x | | | Liste der Tracks | | Konferenz | `/tracks` | x | x | | | Liste der Tracks |
...@@ -63,3 +72,21 @@ Prodinstanz: <https://api.events.ccc.de/congress/2023/> ...@@ -63,3 +72,21 @@ Prodinstanz: <https://api.events.ccc.de/congress/2023/>
Per POST werden neue Einträge angelegt, per PUT bestehende verändert. Per POST werden neue Einträge angelegt, per PUT bestehende verändert.
Details zu den einzelnen Endpunkten folgen in Kürze™. Details zu den einzelnen Endpunkten folgen in Kürze™.
### API-Beispiel mit cURL
Zuerst einen Token generieren:
```bash
curl https://{API_URL}/api/auth/get-token -H "Content-Type: application/json" -X POST --data '{"username": "{USERNAME}", "password": "{PASSWORD}"}'
```
Mit diesem Token können dann Endpunkte aufgerufen werden die eine Authentifizierung erfordern:
```bash
curl https://{API_URL}/api/me -H "Content-Type: application/json" -H "Authorization: Token {API_TOKEN}"
```
## Development
see [Development.md](./Development.md)
---
$schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json
version: "0.2"
import:
- "@cspell/dict-python/cspell-ext.json"
- "@cspell/dict-de-de/cspell-ext.json"
dictionaryDefinitions:
- name: project-words
path: "./.project-dictionary.txt"
addWords: true
dictionaries:
- python
- html
- project-words
- en_US
- de-de
ignorePaths:
- "node_modules"
- ".venv"
- ".tools"
- "/.project-dictionary.txt"
- "src/**/migrations"
- "src/**/fixtures"
- "src/**/vendor"
- "src/**/tests"
- "src/static.dist"
- "src/hub/settings"
- "*.svg"
- "tox.ini"
languageSettings:
- languageId: markdown
caseSensitive: true
- languageId: python
ignoreRegExpList:
- /from .* import .*/g
- /import .*/g
Deployment # Deployment
===========
# Überblick # Überblick
...@@ -12,6 +11,7 @@ Alternativ kann aich wie gehabt die Konfiguration mit einer `local_settings.py` ...@@ -12,6 +11,7 @@ Alternativ kann aich wie gehabt die Konfiguration mit einer `local_settings.py`
Egal welche der Methden gewählt wir, muss zumindest angegeben werden welche Funktionen auszurollen sind und wie die Datenbank zu erreichen ist. Egal welche der Methden gewählt wir, muss zumindest angegeben werden welche Funktionen auszurollen sind und wie die Datenbank zu erreichen ist.
Für die Umgebungsvariablen Konfiguration kann die `docker-compose.yml` als Beispiel zu rate gezogen werden. Für die Umgebungsvariablen Konfiguration kann die `docker-compose.yml` als Beispiel zu rate gezogen werden.
Beispiel einer `local_settings.py`: Beispiel einer `local_settings.py`:
```python ```python
IS_API = False IS_API = False
IS_BACKOFFICE = False IS_BACKOFFICE = False
...@@ -30,7 +30,6 @@ DATABASES = { ...@@ -30,7 +30,6 @@ DATABASES = {
} }
``` ```
# Tipps & Tricks # Tipps & Tricks
## Backup ## Backup
...@@ -40,6 +39,7 @@ Allgemein: für ein normales Backup sollte einfach die Datenbank über Bordmitte ...@@ -40,6 +39,7 @@ Allgemein: für ein normales Backup sollte einfach die Datenbank über Bordmitte
Django hat auch eine Funktion für den Export von Daten eingebaut, diese Variante ist allerdings nicht für den Produktiven Einsatz empfohlen. Django hat auch eine Funktion für den Export von Daten eingebaut, diese Variante ist allerdings nicht für den Produktiven Einsatz empfohlen.
Das Problem liegt hier in der Struktur der Daten bei der Wiederherstellung. Diese ist mit `dumpdata`/`loadata` nicht garaniert. Das Problem liegt hier in der Struktur der Daten bei der Wiederherstellung. Diese ist mit `dumpdata`/`loadata` nicht garaniert.
Grundsätzlich funktioniert es wie folgt: Grundsätzlich funktioniert es wie folgt:
1. Docker Container mit "debug" Kommando starten 1. Docker Container mit "debug" Kommando starten
2. `./manage.py dumpdata` mit natural keys und ohne Django-Interna laufen lassen 2. `./manage.py dumpdata` mit natural keys und ohne Django-Interna laufen lassen
......
...@@ -9,7 +9,6 @@ if [ "$1" == "version" ]; then ...@@ -9,7 +9,6 @@ if [ "$1" == "version" ]; then
exec python3 $APP_HOME/manage.py appversion exec python3 $APP_HOME/manage.py appversion
fi fi
if [[ "$1" != "build" ]]; then
RETRIES=10 RETRIES=10
until postgres_healthcheck; do until postgres_healthcheck; do
if [[ ${RETRIES} -eq 0 ]]; then if [[ ${RETRIES} -eq 0 ]]; then
...@@ -20,11 +19,10 @@ if [[ "$1" != "build" ]]; then ...@@ -20,11 +19,10 @@ if [[ "$1" != "build" ]]; then
sleep 1 sleep 1
RETRIES=$((RETRIES-1)) RETRIES=$((RETRIES-1))
done done
fi
cd $APP_HOME cd $APP_HOME
CONTAINER_MIGRATED="CONTAINER_MIGRATED_FLAG" CONTAINER_MIGRATED="CONTAINER_MIGRATED_FLAG"
if [[ ! -e "$HOME/$CONTAINER_MIGRATED" && ("$DJANGO_MIGRATE" == "yes" || "$STARTMODE" == "init") ]]; then if [[ ! -e "$HOME/$CONTAINER_MIGRATED" && "$DJANGO_MIGRATE" == "yes" ]]; then
python3 $APP_HOME/manage.py migrate --noinput python3 $APP_HOME/manage.py migrate --noinput
touch $HOME/$CONTAINER_MIGRATED touch $HOME/$CONTAINER_MIGRATED
fi fi
...@@ -47,34 +45,7 @@ if [ ! -e "$HOME/$ADMIN_CREATED" -a -n "$DJANGO_CREATE_ADMIN_PASSWORD" ]; then ...@@ -47,34 +45,7 @@ if [ ! -e "$HOME/$ADMIN_CREATED" -a -n "$DJANGO_CREATE_ADMIN_PASSWORD" ]; then
touch $HOME/$ADMIN_CREATED touch $HOME/$ADMIN_CREATED
fi fi
if [ "$1" == "init" -o "$STARTMODE" == "init" ]; then touch $HOME/PREPARATION_DONE
# activate provided SSH key, if any
if [ -n "${INIT_STATICFILES_SSH_KEY_SECRET}" ]; then
cat "/run/secrets/${INIT_STATICFILES_SSH_KEY_SECRET}" > "$HOME/.ssh/id_rsa"
echo >> "$HOME/.ssh/id_rsa" # ensure newline at the end of the key file -.-
chmod 600 "$HOME/.ssh/id_rsa"
fi
# build gzip files for static assets for better performance
find /app/static.dist -type f -not -name "*.png" -not -name "*.jpg" -exec gzip -k {} +
# copy static files to destination
if [ -n "${INIT_STATICFILES_RSYNC_TARGET}" ]; then
echo -n "rsyncing static files to \"${INIT_STATICFILES_RSYNC_TARGET}\" ... "
rsync -az -e "ssh -o StrictHostKeyChecking=accept-new" --stats /app/static.dist/ "${INIT_STATICFILES_RSYNC_TARGET}"
echo "done"
else
echo "WARNING: not copying static files anywhere because you did not provide a INIT_STATICFILES_RSYNC_TARGET"
fi
# django migrations will be run automatically already if STARTMODE=init
[ "$STARTMODE" == "init" ] || python3 $APP_HOME/manage.py migrate --noinput
# idle forever (docker swarm does not have a restart-policy)
echo "Initialization complete."
while true; do sleep 5; done
exit 0
fi
if [ "$1" == "webworker" -o "$STARTMODE" == "webworker" ]; then if [ "$1" == "webworker" -o "$STARTMODE" == "webworker" ]; then
# start gunicorn (might be called indirectly via supervisor when started with 'all') # start gunicorn (might be called indirectly via supervisor when started with 'all')
...@@ -106,25 +77,10 @@ if [ "$1" == "shell" -o "$1" == "createsuperuser" -o "$1" == "test" ]; then ...@@ -106,25 +77,10 @@ if [ "$1" == "shell" -o "$1" == "createsuperuser" -o "$1" == "test" ]; then
fi fi
if [ "$1" == "housekeeping" ]; then if [ "$1" == "housekeeping" ]; then
interval="${HOUSEKEEPING_SLEEP_SECONDS:-300}" python3 $APP_HOME/manage.py housekeeping --forever
if [ "$interval" -gt 0 ]; then
python3 $APP_HOME/manage.py housekeeping --forever --forever-delay="$interval"
else
python3 $APP_HOME/manage.py housekeeping
fi
fi
if [ "$1" == "build" ]; then
cd $APP_HOME/plainui
/usr/bin/yarnpkg
/usr/bin/yarnpkg build
cd $APP_HOME
python3 $APP_HOME/manage.py collectstatic --no-input
exec python3 $APP_HOME/manage.py compilemessages
fi fi
cat <<EOD cat <<EOD
Specify argument: init|webworker|shell|createsuperuser Specify argument: webworker|shell|createsuperuser
Additional development image arguments: build
EOD EOD
exit 1 exit 1
...@@ -9,11 +9,6 @@ if [[ -z "$TARGET" ]]; then ...@@ -9,11 +9,6 @@ if [[ -z "$TARGET" ]]; then
exit 1; exit 1;
fi fi
if [ "$STARTMODE" == "init" ]; then
# the init container must always be considered 'healthy'
exit 0;
fi
response="$(curl --silent --show-error --fail-with-body --unix-socket /run/hub/app.sock --resolve "${TARGET}:80:127.0.0.1" "http://${TARGET}${SCRIPT_NAME}/.well-known/health")" response="$(curl --silent --show-error --fail-with-body --unix-socket /run/hub/app.sock --resolve "${TARGET}:80:127.0.0.1" "http://${TARGET}${SCRIPT_NAME}/.well-known/health")"
echo "$response" echo "$response"
......