Add the web service implementation #104
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run tests | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.12"] # Can be extended with future Python versions | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Set up Podman and Buildah | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y podman buildah | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '${{ matrix.python-version }}' | |
cache: 'pip' | |
- name: Install pytest | |
run: | | |
python -m pip install pytest hatch | |
python -m pip install . | |
- name: Build the web image | |
run: | | |
buildah bud -t tmt-web:latest --build-arg PYTHON_VERSION=${{ matrix.python-version }} . | |
- name: Create Podman pod | |
run: | | |
podman pod create --name tmt-web-pod --infra-image=registry.k8s.io/pause:3.9 -p 8000:8000 -p 6379:6379 | |
# Exposing redis port as well for test_api.py::TestCelery::test_basic_test_request | |
- name: Start Redis container | |
run: | | |
podman run -d --pod tmt-web-pod --name redis redis:latest | |
- name: Start Celery container | |
run: | | |
podman run -d --pod tmt-web-pod --name celery \ | |
-e REDIS_URL=redis://localhost:6379 \ | |
-e API_HOSTNAME=http://localhost:8000 \ | |
tmt-web:latest celery --app=tmt_web.api.service worker --loglevel=INFO | |
- name: Start Web container | |
run: | | |
podman run -d --pod tmt-web-pod --name web \ | |
-e REDIS_URL=redis://localhost:6379 \ | |
-e API_HOSTNAME=http://localhost:8000 \ | |
tmt-web:latest uvicorn tmt_web.api:app --reload --host 0.0.0.0 --port 8000 | |
- name: Wait for services to be ready | |
run: | | |
for i in {1..30}; do | |
if curl -s http://localhost:8000/health; then | |
break | |
fi | |
sleep 4 | |
done | |
- name: Run tests | |
run: | | |
python -m pytest | |
- name: Cleanup | |
if: always() | |
run: | | |
podman pod stop tmt-web-pod | |
podman pod rm tmt-web-pod |