Skip to content

Commit

Permalink
[SDESK-7284] Launch superdesk test instance on Github Actions (#2684)
Browse files Browse the repository at this point in the history
* Implement new async_cli module

This module includes a custom Blueprint, AppGroup and a helper to easily create a command blueprint ready to register commands based on async function. The registered async commands will be run sync using `asgiref.sync.async_to_sync`

SDESK-7284

* Rework `app:initialize_data` command

The command was converted from the old class based commands into a function one using `Click` and our new `cli.register_async_command` decorator in order to use our new async services in the synchronous context of Quart's command line interface

SDESK-7284

* Update docker-compose.yml

* Fix type and docstrings

* Rework `users:create` command

Command converted from the old class based commands into a function one using `Click` and our new `cli.register_async_command` decorator.

SDESK-7284

* Rework `schema:migrate` command

SDESK-7284

* Update app_initialize.py

* Rework `data:upgrade` and `data:downgrade` commands

SDESK-7284

* Remove not needed false return

* Fix async commands to use proper app context

Async commands fail when using app context as they are executed in different threads or outside of the normal request context lifecycle. In order to fix that, we set the current app instance into the AsyncAppGroup so later it can be passed optionally to the command at the moment of its execution.

SDESK-7284

* Fix `schema:migrate` command

SDESK-7284

* Small improvement to use of app context in async commands

SDESK-7284

* Implement basic Github Actions test instance

SDESK-7284

* Removing not needed settings

SDESK-7284
  • Loading branch information
eos87 authored Sep 4, 2024
1 parent c90f21b commit d3de447
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/test-instance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "Spawn Test Instance"

on: [push, pull_request]

jobs:
pytest:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ['3.10']

services:
mongodb:
image: mongo:6
ports:
- 27017:27017
redis:
image: redis:alpine
ports:
- 6379:6379
elastic:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.22
ports:
- 9200:9200
env:
discovery.type: single-node

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: ./scripts/tests_setup

- name: Install dependencies
working-directory: ./tests/test_instance/server
run: |
pip install -U pip wheel setuptools
pip install -r requirements.txt
- name: Prepare instance
working-directory: ./tests/test_instance/server
run: |
python manage.py app:initialize_data
python manage.py users:create -u admin -p admin -e [email protected] --admin
# python manage.py data:upgrade # until we decide what to do
python manage.py schema:migrate
3 changes: 3 additions & 0 deletions tests/test_instance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Superdesk Test Instance

This is intended to be run from Github Actions. It contains a basic superdesk server setup in order to launch a test instance from there.
10 changes: 10 additions & 0 deletions tests/test_instance/server/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8; -*-
#
# This file is part of Superdesk.
#
# Copyright 2013 to present Sourcefabric z.u. and contributors.
#
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code

from superdesk.factory import get_app as create_app # noqa
15 changes: 15 additions & 0 deletions tests/test_instance/server/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8; -*-
#
# This file is part of Superdesk.
#
# Copyright 2013 to present Sourcefabric z.u. and contributors.
#
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code

"""Superdesk Manager"""

from quart.cli import main

if __name__ == "__main__":
main()
4 changes: 4 additions & 0 deletions tests/test_instance/server/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-e ../../../.

-e git+https://github.com/superdesk/superdesk-planning.git@async#egg=superdesk_planning
-e git+https://github.com/superdesk/sams.git@develop#egg=sams_client&subdirectory=src/clients/python/

0 comments on commit d3de447

Please sign in to comment.