From 313ae1625224f3e7c7147a98614bface0f2e1c28 Mon Sep 17 00:00:00 2001 From: Martin Hoyer Date: Thu, 15 Aug 2024 15:17:57 +0200 Subject: [PATCH] Refactoring github workflow --- .github/workflows/test.yml | 80 +++++++++++++++++++++++++++++-------- Dockerfile => Containerfile | 3 +- src/requirements.txt | 5 +-- 3 files changed, 67 insertions(+), 21 deletions(-) rename Dockerfile => Containerfile (77%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8b06715..adedbe1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,30 +6,78 @@ on: pull_request: branches: [ "main" ] -permissions: - contents: read - jobs: - build: + test: runs-on: ubuntu-latest + strategy: matrix: - python-version: [ "3.10", "3.11", "3.12" ] + python-version: [ "3.10", "3.12" ] + steps: - - uses: actions/checkout@v4 + + - 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@v3 + uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies + python-version: '${{ matrix.python-version }}' + + - name: Install pytest run: | - sudo apt-get update -y - sudo apt-get install podman -y - python -m pip install -U pip podman-compose + python -m pip install pytest python -m pip install -r src/requirements.txt - - name: Start services + + + - 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-compose up -d - - name: Test + podman pod create --name tmt-web-pod -p 8000:8000 -p 6379:6379 || true + # I don't even know, now it threw "docker://k8s.gcr.io/pause:3.5: Requesting bear token: invalid status code from registry 404" + # 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=src.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 src.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: | - pytest + podman pod stop tmt-web-pod + podman pod rm tmt-web-pod diff --git a/Dockerfile b/Containerfile similarity index 77% rename from Dockerfile rename to Containerfile index 97d4e5b..dfc37c1 100644 --- a/Dockerfile +++ b/Containerfile @@ -1,4 +1,5 @@ -FROM python:3.10 +ARG PYTHON_VERSION=3.12 +FROM python:${PYTHON_VERSION} RUN mkdir /app WORKDIR /app diff --git a/src/requirements.txt b/src/requirements.txt index 212e33a..e3dc82a 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -1,8 +1,5 @@ -fmf~=1.4 -pytest~=8.3 tmt~=1.35 fastapi~=0.112 httpx~=0.27 -redis~=5.0 uvicorn~=0.30 -celery~=5.4 +celery[redis]~=5.4