Skip to content

Add a database and test users for advanced testing #7

Open

Description

@nhoening
No description provided.

Activity

  1. victorgarcia98 commented on May 17, 2023

    @victorgarcia98
    Contributor

    Taking some bites from the FM core docker-compose.yaml, I suggest we add this file to the plugin template:

    version: "3.4"
    
    services:
      server:
        build:
          context: .
          dockerfile: Dockerfile
        ports:
          - 5000:5000
        depends_on:
          - test-db  # use -e SQLALCHEMY_TEST_DATABASE_URI=... to exec pytest
        restart: on-failure
        healthcheck:
          test: ["CMD", "curl", "-f", "http://localhost:5000/api/v3_0/health/ready"]
          start_period: 10s
          interval: 20s
          timeout: 10s
          retries: 6
        environment:
          SQLALCHEMY_DATABASE_URI: "postgresql://fm-test-db-user:fm-test-db-pass@test-db:5432/fm-test-db"
          SECRET_KEY: notsecret
          FLASK_ENV: development
          LOGGING_LEVEL: INFO 
          FLEXMEASURES_PLUGINS: /app/{{cookiecutter.plugin_name}}
        entrypoint: ["/bin/sh", "-c"]
        command:
        - |
          pip install -r instance/requirements.txt
          flexmeasures db upgrade
          flexmeasures add toy-account --name 'Docker Toy Account'
          gunicorn --bind 0.0.0.0:5000 --worker-tmp-dir /dev/shm --workers 1 --threads 4 wsgi:application
      test-db: #  sudo docker compose down --volumes
        image: postgres
        expose:
          - 5432
        restart: always
        environment:
          POSTGRES_DB: fm-test-db
          POSTGRES_USER: fm-test-db-user
          POSTGRES_PASSWORD: fm-test-db-pass
        volumes:
          - ./ci/load-psql-extensions.sql:/docker-entrypoint-initdb.d/load-psql-extensions.sql
    

    For this to work, we would need to add the file load-psql-extensions.sql with the instructions to install the extensions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions