Skip to content

Commit

Permalink
feat: create Dockerfile for local host testing
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-ang committed Jan 9, 2025
1 parent 9cb892d commit f10e131
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 22 deletions.
73 changes: 51 additions & 22 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
certifi
curl_cffi
pendulum
pydantic
pymongo
python-dotenv
python-telegram-bot[ext]
Expand Down

0 comments on commit f10e131

Please sign in to comment.