Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docker): add Dockerfile and .dockerignore for containerized setup #14

Merged
merged 4 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git
__pycache__
.venv
tests
*.pyc
30 changes: 17 additions & 13 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v3
with:
python-version: "3.10"
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

- name: Install Poetry
uses: snok/install-poetry@v1
- name: Build Docker image
run: docker build -t focusfeed .

- name: Install dependencies
run: |
poetry install
poetry add ruff --group dev
#- name: Run tests in Docker
# run: docker run focusfeed poetry run pytest tests/

- name: Run ruff format
run: poetry run ruff format . --check
- name: Format with Ruff
run: docker run focusfeed poetry run ruff format . --check

- name: Run ruff lint
run: poetry run ruff check .
- name: Lint with Ruff
run: docker run focusfeed poetry run ruff check .
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use the official Python 3.10 image
FROM python:3.10-slim

# Set environment variables
ENV POETRY_VERSION=1.1.13
ENV POETRY_HOME="/opt/poetry"
ENV POETRY_VIRTUALENVS_CREATE=false

# Install Poetry
RUN apt-get update && apt-get install -y curl && \
curl -sSL https://install.python-poetry.org | python3 - && \
ln -s $POETRY_HOME/bin/poetry /usr/local/bin/poetry


# Set the working directory
WORKDIR /app

# Copy the project files
COPY . .

# Install dependencies
RUN poetry install --no-root

# Expose the port the app runs on
EXPOSE 8000

# Set the entry point
CMD ["poetry", "run", "focusfeed"]
4 changes: 1 addition & 3 deletions focusfeed/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import sys

from src.auth import Authenticator


class InstagramBot:
def __init__(self):
self.auth = Authenticator()
self.auth = "Hello"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Replacing self.auth with a string breaks authentication flow.

Currently, self.auth is assigned the value "Hello" instead of an Authenticator-like object. As a result, calls to self.auth.login(), self.auth.logout(), and self.auth.perform_operations() (lines 22, 24, 26) will fail, causing runtime errors. If your goal is to remove or mock the authenticator for testing, consider using a dummy or mock object that still provides the required methods instead of a raw string.

Below is an example of a minimal mock object you could substitute:

-class InstagramBot:
-    def __init__(self):
-        self.auth = "Hello"
+class MockAuthenticator:
+    def login(self):
+        print("Mock login.")
+
+    def logout(self):
+        print("Mock logout.")
+
+    def perform_operations(self):
+        print("Mock perform_operations.")

 class InstagramBot:
     def __init__(self):
-        self.auth = "Hello"
+        self.auth = MockAuthenticator()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.auth = "Hello"
class MockAuthenticator:
def login(self):
print("Mock login.")
def logout(self):
print("Mock logout.")
def perform_operations(self):
print("Mock perform_operations.")
class InstagramBot:
def __init__(self):
self.auth = MockAuthenticator()
# ... rest of the code ...

self.loader = None

def display_menu(self):
Expand Down