diff --git a/.github/workflows/docker-compose-tests.yml b/.github/workflows/docker-compose-tests.yml index c85e0ff54..929d74134 100644 --- a/.github/workflows/docker-compose-tests.yml +++ b/.github/workflows/docker-compose-tests.yml @@ -39,7 +39,7 @@ jobs: pip install -r tests/requirements-test.txt docker compose -f docker-compose.yml \ -f tests/docker-compose-test.yml up \ - --build --exit-code-from backend + --build --exit-code-from backend backend - name: Setup upterm session uses: lhotari/action-upterm@v1 diff --git a/.gitignore b/.gitignore index 3b2121b96..9316eccb4 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,7 @@ safespring_invoicespec.csv dds_web/development/invoicing/* dds_variables.env cython_tools -coverage/* \ No newline at end of file +coverage/* +# Local SeaweedFS (weed mini) data, if volumes are enabled in docker-compose.yml +weedmini-data/ +weedmini2-data/ diff --git a/.gitpod.yml b/.gitpod.yml index bcf1f8dfd..244772aa1 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -11,7 +11,7 @@ tasks: init: > chmod a+x /workspace/ && docker compose build --pull - command: docker compose --profile cli up + command: docker compose up - name: Open dds cli openMode: split-right command: > @@ -28,10 +28,7 @@ ports: # open-browser is blocked by Chrome pop-up blocker onOpen: ignore visibility: public - - port: 9000 # minio - onOpen: ignore - visibility: public - - port: 9001 # minio + - port: 9000 # seaweedfs onOpen: ignore visibility: public - port: 3306 # db diff --git a/README.md b/README.md index bc14156c1..ff051bc7e 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ ## Table of Contents - [Development Setup](#development-setup) - - [Profiles](#profiles) + - [Running locally](#running-locally) - [Debugging inside docker](#python-debugger-inside-docker) - [Config settings](#config-settings) - [Database changes](#database-changes) @@ -70,55 +70,54 @@ When developing this software, we recommend that you run the web server locally You can download Docker here: Then, fork this repository and clone to your local system. -In the root folder of the repo, run the server with one of the following profiles (_plain_, _dev_, _full-dev_, _cli_) depending on your needs. -### Profiles +### Running locally -#### Application & Database: Plain +The development environment requires that [dds_cli](https://github.com/ScilifelabDataCentre/dds_cli) is checked out next to this repo, in `../dds_cli` (otherwise adapt the volume path in `docker-compose.yml`). Without it, the `cli` container fails to start. + +In the root folder of the repo, start the development environment: ```bash -docker-compose up +docker compose up ``` -This command will orchestrate the building and running of two containers: one for the SQL database (`mariadb`) and one for the application. +This builds and starts all containers needed for development: -#### Mailcatcher: `dev` +- `backend`: the web app and API, at `localhost:5000` +- `db`: the MariaDB database +- `redis`: the job queue. To also use it for API rate limiting, uncomment `RATELIMIT_STORAGE_URI` in `docker-compose.yml` +- `weedmini`: SeaweedFS (weed mini) S3 storage, at `localhost:9000` +- `mailcatcher`: catches emails sent by the app; read them at `localhost:1080` +- `cli`: for running the CLI against the local setup (see [below](#cli-development-against-local-environment)) +- `node_builder`: recompiles the CSS when SCSS files change -```bash -docker-compose --profile dev up -``` +Add `-d` to run in detached mode, and stop the containers with `docker compose down`. -This will give you the above two containers, but also `mailcatcher` that will allow you to read -any sent emails by going to `localhost:1080` in a web browser. - -#### Minio S3 Storage & Limiter: `full-dev` +If you are updating from an older setup (for example from before the switch from MinIO to SeaweedFS), remove the old containers before starting: ```bash -docker-compose --profile full-dev up +docker compose down --remove-orphans ``` -Will also activate minio for s3 storage (clearly not functional with cli) and redis to enable a persistent limiter for the API. -You also need to uncomment `RATELIMIT_STORAGE_URI` in `docker-compose.yml` to enable redis. - -If you prefer, you can run the web servers in 'detached' mode with the `-d` flag, which does not block your terminal. -If using this method, you can stop the web server with the command `docker-compose down`. +Otherwise old containers that are no longer in `docker-compose.yml` can keep running and block ports, and the database keeps data that points to the old storage. -#### CLI development against local environment: `cli` +#### Second S3 storage: `s3-switch` ```bash -docker-compose --profile cli up +docker compose --profile s3-switch up ``` -Will start database, backend, minio, and mailcatcher. Will also start an extra container prepared for working with the CLI. +Also starts `weedmini2`, a second SeaweedFS S3 storage at `localhost:9002`. It is only needed for testing a switch between two S3 storages. -Requires that dds_cli is checked out in `../dds_cli` (otherwise adapt the volume path in `docker-compose.yml`). +Stop it with `docker compose --profile s3-switch down`, since a plain `docker compose down` may leave `weedmini2` running. -1. Start docker-compose with the `cli` profile -2. Inject into the `dds_cli` container: +#### CLI development against local environment - ```bash - docker exec -it dds_cli /bin/sh - ``` +The `cli` container runs your local checkout of dds_cli in `../dds_cli`. With the containers running, shell into the `dds_cli` container: + +```bash +docker exec -it dds_cli /bin/sh +``` Then you can freely use the dds cli component against the local development setup in the active CLI. @@ -184,7 +183,7 @@ For instructions on how to do this, see [the README in the migrations directory] Tests run on github actions on every pull request and push against master and dev. To run the tests locally, use this command: ```bash -docker-compose -f docker-compose.yml -f tests/docker-compose-test.yml up --build --exit-code-from backend +docker compose -f docker-compose.yml -f tests/docker-compose-test.yml up --build --exit-code-from backend backend ``` This will create a test database in the mariadb container called `DeliverySystemTest` which will be populated before a test and emptied after a test has finished. @@ -195,7 +194,7 @@ For example to only run the `test_x` inside the file `tests/test_y.py` you would To run interactively, use the following command: ```bash -docker-compose -f docker-compose.yml -f tests/docker-compose-test-interactive.yml up --build --exit-code-from backend +docker compose -f docker-compose.yml -f tests/docker-compose-test-interactive.yml up --build --exit-code-from backend backend ``` Then in a new terminal, shell into the container and run pytest: diff --git a/SPRINTLOG.md b/SPRINTLOG.md index acab8db60..251f276c8 100644 --- a/SPRINTLOG.md +++ b/SPRINTLOG.md @@ -705,3 +705,4 @@ _Nothing merged during this sprint_ - Update dependency Mako to v1.4.2 [SECURITY] ([#1880]https://github.com/ScilifelabDataCentre/dds_web/pull/1880) - Update dependency Authlib to v1.9.1 [SECURITY] ([#1886]https://github.com/ScilifelabDataCentre/dds_web/pull/1886) - Bump dnspython from 2.6.1 to 2.9.0 ([#1888]https://github.com/ScilifelabDataCentre/dds_web/pull/1888) +- Replace MinIO with SeaweedFS (weed mini) as local S3 storage and make full dev setup the docker compose default ([#1889]https://github.com/ScilifelabDataCentre/dds_web/pull/1889) diff --git a/dds_web/config.py b/dds_web/config.py index d6cc91b42..ff457d86d 100644 --- a/dds_web/config.py +++ b/dds_web/config.py @@ -32,10 +32,10 @@ class Config(object): # Expected paths - these are the bind paths *inside* the container USE_LOCAL_DB = True LOGS_DIR = "/dds_web/logs" - SAFESPRING_URL = os.environ.get("DDS_SAFESPRING_URL", "http://minio:9000") + SAFESPRING_URL = os.environ.get("DDS_SAFESPRING_URL", "http://weedmini:9000") DDS_SAFESPRING_PROJECT = os.environ.get("DDS_SAFESPRING_PROJECT", "project-name.example.se") - DDS_SAFESPRING_ACCESS = os.environ.get("DDS_SAFESPRING_ACCESS", "minio") - DDS_SAFESPRING_SECRET = os.environ.get("DDS_SAFESPRING_SECRET", "minioPassword") + DDS_SAFESPRING_ACCESS = os.environ.get("DDS_SAFESPRING_ACCESS", "weedMini") + DDS_SAFESPRING_SECRET = os.environ.get("DDS_SAFESPRING_SECRET", "weedMiniPassword") # Use short-lived session cookies: PERMANENT_SESSION_LIFETIME = datetime.timedelta(hours=1) diff --git a/docker-compose.yml b/docker-compose.yml index d1682440a..4e214dd8a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,6 @@ -# Use --profile full-dev and uncomment RATELIMIT_STORAGE_URI to use redis +# `docker compose up` starts everything needed for development. +# Add `--profile s3-switch` to also start weedmini2 (only for testing a switch between two S3 storages). +# Uncomment RATELIMIT_STORAGE_URI under backend to use redis for rate limiting. --- services: db: @@ -96,65 +98,64 @@ services: source: $DDS_LOG_DIR target: /dds_web/logs - minio: - container_name: dds_minio - image: pgsty/minio:RELEASE.2026-08-04T00-00-00Z - profiles: - - s3 - - full-dev - - cli - command: server /data --console-address ":9001" + # SeaweedFS (weed mini): all SeaweedFS components in one container, serving S3 on port 9000. + # S3 keys come from AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY; data in /data is lost unless a volume is mounted. + # Flags turn off weed mini defaults we don't need: + # -s3.autoCreateBucket=false: uploading to a missing bucket fails instead of creating it + # -master.telemetry=false: no anonymous usage data sent to the SeaweedFS project + # -webdav=false: no WebDAV server (for mounting storage as a network drive) + # -s3.port.iceberg/lance=0: no Iceberg/Lance endpoints (data-catalog tools for analytics/ML) + weedmini: + container_name: dds_weed_mini + image: chrislusf/seaweedfs:4.52 + command: > + mini -dir=/data -s3.port=9000 + -s3.autoCreateBucket=false + -master.telemetry=false + -webdav=false -s3.port.iceberg=0 -s3.port.lance=0 ports: - 127.0.0.1:9000:9000 - - 127.0.0.1:9001:9001 environment: - MINIO_ROOT_USER: minio # access key - MINIO_ROOT_PASSWORD: minioPassword # secret key - # NOTE: Uncomment if you want to keep your data. - # Mounts a folder into the container to make uploaded data persistent. - # volumes: - # - type: bind - # source: ./minio-data - # target: /data + AWS_ACCESS_KEY_ID: weedMini + AWS_SECRET_ACCESS_KEY: weedMiniPassword + # NOTE: Uncomment if you want to keep your data. + # Mounts a folder into the container to make uploaded data persistent. + # volumes: + # - type: bind + # source: ./weedmini-data + # target: /data - minio2: # Added in order to be able to test the new sto4 move - container_name: dds_minio_2 - image: pgsty/minio:RELEASE.2026-08-04T00-00-00Z - profiles: - - s3 - - full-dev - - cli - command: server /data --console-address ":9003" + # Second S3 storage, only for testing a switch between storages (--profile s3-switch) + weedmini2: + container_name: dds_weed_mini_2 + image: chrislusf/seaweedfs:4.52 + profiles: [s3-switch] + command: > + mini -dir=/data -s3.port=9000 + -s3.autoCreateBucket=false + -master.telemetry=false + -webdav=false -s3.port.iceberg=0 -s3.port.lance=0 ports: - 127.0.0.1:9002:9000 - - 127.0.0.1:9003:9003 environment: - MINIO_ROOT_USER: minio2 # access key - MINIO_ROOT_PASSWORD: minioPassword2 # secret key - # NOTE: Uncomment if you want to keep your data. - # Mounts a folder into the container to make uploaded data persistent. - # volumes: - # - type: bind - # source: ./minio-data - # target: /data + AWS_ACCESS_KEY_ID: weedMini2 + AWS_SECRET_ACCESS_KEY: weedMiniPassword2 + # NOTE: Uncomment if you want to keep your data. + # Mounts a folder into the container to make uploaded data persistent. + # volumes: + # - type: bind + # source: ./weedmini2-data + # target: /data mailcatcher: container_name: dds_mailcatcher image: sj26/mailcatcher:latest - profiles: - - dev - - mail - - full-dev - - cli ports: - 127.0.0.1:1080:1080 redis: container_name: dds_redis image: redis:latest - profiles: - - full-dev - - redis cli: container_name: dds_cli @@ -163,9 +164,6 @@ services: dockerfile: Dockerfiles/cli.Dockerfile context: ./ target: base - profiles: - - cli - - full-dev environment: - DDS_CLI_ENV=docker-dev volumes: diff --git a/migrations/README.md b/migrations/README.md index 3e5770302..947fe6cca 100644 --- a/migrations/README.md +++ b/migrations/README.md @@ -11,7 +11,7 @@ This document explains how to generate new database migration. Before making any changes to the database models, ensure the containers are running locally. ```bash -docker compose up # See root README for information regarding the different profiles +docker compose up # See the root README for details on the development environment ``` ### 2. Modify the Database Models