diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index a5abd0e..a80fc87 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -5,35 +5,64 @@ name: Python application on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] permissions: contents: read jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.11 - uses: actions/setup-python@v3 - with: - python-version: "3.11" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: | - pytest test/models.py + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install lint dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 + + - name: Lint with flake8 + run: | + # stop if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + + - name: Build Docker image + run: docker compose build + + - name: Run service stability test + env: + TEST_TELEGRAM_TOKEN: ${{ secrets.TEST_TELEGRAM_TOKEN }} + FEEDBACK_CHANNEL_ID: ${{ secrets.FEEDBACK_CHANNEL_ID }} + MONGO_URL: ${{ secrets.MONGO_URL }} + GITHUB_URL: ${{ secrets.GITHUB_URL }} + run: | + # Start service + docker compose up -d + + # Monitor for 1 minute + START_TIME=$(date +%s) + END_TIME=$((START_TIME + 60)) + + while [ $(date +%s) -lt $END_TIME ]; do + # Check if container is still running + if ! docker ps | grep -q terrier-alert; then + echo "Service crashed!" + docker compose logs + exit 1 + fi + sleep 5 + done + + # If we get here, service ran for 1 minute successfully + echo "Service ran stable for 1 minute" + docker compose down diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eb44a2b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.11-slim + +WORKDIR /app + +COPY requirements.txt . + +RUN pip install --no-cache-dir -r requirements.txt + +# Copy all files from build context to /app +COPY . . + +CMD ["python3", "test/bot.py"] + +# docker compose build +# docker compose up diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..cc47923 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + bot: + build: . + environment: + - TELEGRAM_TOKEN=${TELEGRAM_TOKEN} + - TEST_TELEGRAM_TOKEN=${TEST_TELEGRAM_TOKEN} + - FEEDBACK_CHANNEL_ID=${FEEDBACK_CHANNEL_ID} + - MONGO_URL=${MONGO_URL} + - GITHUB_URL=${GITHUB_URL} diff --git a/requirements.txt b/requirements.txt index e970f35..6c6504e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ certifi curl_cffi pendulum +pydantic pymongo python-dotenv python-telegram-bot[ext]