YCC backend service.
Sad news as of 2025-03: This approach did not catch on, Enrico decided to do his own thing with Flask and Vue.js and Bartek is also doing his own thing. Stays for now as backend for the YCC App & Python practice project.
- Install Python 3.12
- Install Oracle Instant Client
- Install Poetry & poetry-plugin-up
pipx install poetry && pipx inject poetry poetry-plugin-up
- Optionally install Docker & Docker Compose if you want to run the full stack locally
Note: these instructions guide you to run everything locally. But you can also have a "thin" local development environment with the DEV DB and Keycloak (you need a CERN account) or with a local SQLite DB and DEV Keycloak (no CERN account needed). In either case, you would need to update conf/config.json .
Initialise environment:
poetry installStart database:
cd ../ycc-infra/ycc-db-local && docker-compose upStart Keycloak & configure clients if needed (see below for details):
cd ../ycc-infra/ycc-keycloak-local
./init.sh
./kc.sh start-devStart Mailpit (if you do not want to test email testing, copy conf/config.json to conf/config-dev.json and remove email):
docker run -d --name=mailpit --restart unless-stopped -e TZ=Europe/Zurich -p 8025:8025 -p 1025:1025 axllent/mailpit
// SMTP: localhost:1025
// Web: http://localhost:8025Start application:
poetry run start- Address: http://localhost:8000/
- API Docs: http://localhost:8000/docs
You can also separately verify the DB and the email configuration:
poetry run db-playground
poetry run email-playgroundFor a clean config two clients are recommended, one for ycc-hull and one for the Swagger UI. The latter is optional.
For ycc-hull create a client with:
- Client authentication enabled (authorisation disabled)
- Service accounts roles enabled
- Ensure that the
ycc-client-groups-and-rolesclient scope is enabled - Save the credentials to
config/conf.json
For the Swagger UI (optional) create a client with:
- Client authentication disabled
- Direct access grants enabled
- Ensure that the
ycc-client-groups-and-rolesclient scope is enabled - URLs
http://localhost:8000(base, home, admin) andhttp://localhost:8000/*(redirect) - Web origins
+ - Optionally you can increase token refresh for example to 1 hour under the advanced settings
generated_entities: generated entities for referencelegacy_password_hashing: Perl-compatible password hashingtest_data: test data & generatortests: testsload_tests: load testssrc/ycc_hull: published moduleapi: API endpoints, which are also responsible for authorisationcontrollers: controllers, responsible for business logic and DB to DTO conversiondb: DB-related components, entitiesmodels: models, DTOs
You can regenerate entities using the following commands:
poetry run sqlacodegen oracle+oracledb://ycclocal:[email protected]:1521/XE --outfile generated_entities/entities_generated.py
poetry run isort generated_entities/entities_generated.py
poetry run black generated_entities/entities_generated.pyGenerated entities does not work as good as handwritten ones. Please use the generated entities as a reference for updating handwritten entities in entities.py.
For non-sensitive data such as membership types or boats, we can use directly the real YCC data.
For sensitive data (names, addresses, bookings, boat logs), automatic one-shot generation is preferred with tools like Faker or Mockaroo.
Upgrade to latest compatible versions:
poetry up
Upgrade to latest versions:
poetry up --latest
poetry run pytest --cov=ycc_hull --cov-branch --cov-report=html -x -vvv
poetry run isort .
poetry run black .
poetry run mypy .
poetry run flake8 .
poetry run pylint --jobs 0 legacy_password_hashing load_tests test_data tests ycc_hullLoad tests are located in load_tests. They are written using Locust.
# LOCAL
poetry run locust --locustfile load_tests/load_test_helpers.py --host http://localhost:8000
# DEV
poetry run locust --locustfile load_tests/load_test_helpers.py --host https://ycc-hull-dev.web.cern.chYou can use either YCC-DEV or YCC-LOCAL for auth (you can configure it in load_tests/load_test_config.py).
For more info about test execution see poetry run locust --help.
See the ycc-infra repository for updating the Docker image. Then apply the update to ycc-hull:
- Regenerate entities from the database (see above)
- Update entities and test data if necessary
Deployed on CERN OKD.
You can test the build locally. If you do not want to run the instance, but only inspect the contents, you can set the entry point in your local copy to /bin/bash for simplicity.
You can test the build with this command:
docker build . -t ycc-hull-local-testThen start a new container from the image:
# You might want to update the config file to work on your computer
CONFIG_JSON=$(cat conf/config.json)
LOGGING_CONF=$(cat conf/logging.conf)
docker run -p 8000:8080 -e CONFIG_JSON="$CONFIG_JSON" -e LOGGING_CONF="$LOGGING_CONF" -it ycc-hull-local-testThis section records which technologies were dropped during PoC and why.
- Node.js frameworks (notable Sails and TypeORM): poor integration with the existing Oracle Database. YCC Hull will provide a backend service, which can be used from other applications without having to worry about Oracle integration.
- Django: Django ORM is inferior to SQLAlchemy, plus, this service only provides an API. Django would have worked, but it would have complicated too much.
Note that other services can be in Node.js/Django, since they only communicate with this one over the network.
(On the funny note when ycc-hull was already under development, Sequelize (Node/JS) came out with Oracle support...)