Skip to content

Commit

Permalink
[REFACTOR] Restructure project into client and api_service directorie…
Browse files Browse the repository at this point in the history
…s, improved docker build speed and weight (#50)

 🚀 Improved

- Restructured the project into `client` and `api_service` directories for better organization and modularity.
- Improved Docker build speed and reduced image size.
- Added support for ARM64 architecture.

🐛 Fixed
- Fixed a bug that prevented users from manually entering the URL for Jellyfin, Overseer, and Jellyseer.
  • Loading branch information
giuseppe99barchetta authored Oct 25, 2024
1 parent a565be7 commit 7d1977b
Show file tree
Hide file tree
Showing 83 changed files with 175 additions and 428 deletions.
56 changes: 48 additions & 8 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,62 @@
.env
# Ignore Git files and folders
.git
.gitattributes
.gitignore
.github

# Ignore Docker-specific files and folders
.docker
docker-compose.yml
docker-compose.override.yml
docker-compose-debug.yml
dockerfile
.docker
.dockerignore

# Ignore environment and config files
.env
.env.local
.env.development
.env.production
.env.example
*.config
*.yaml

# Ignore Python cache and environment folders
**/__pycache__/
**/*.py[cod]
.Python
*.manifest
*.spec
.venv/
venv/
.vscode/
*.md

# Ignore Node modules
node_modules/

# Ignore IDE and editor configurations and temporary files
.vscode/
.idea/
*.sublime-project
*.sublime-workspace
*.iml

# Ignore temporary and backup files
*.swp
*.swo
*.bak
*.tmp
*.temp
*.DS_Store

# Ignore log files
*.log
app.log
*.yaml

# Ignore build and distribution folders
build/
dist/
out/

# Ignore documentation and markdown files
*.md

# Ignore config and config files folders
/config_files
/config/config_files
24 changes: 11 additions & 13 deletions .github/workflows/docker_hub_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -13,20 +14,17 @@ jobs:
- name: Checkout code
uses: actions/[email protected]

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Docker Hub
run: echo ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | docker login -u ciuse99 --password-stdin

- name: Build Docker Image
run: |
docker build . -t ciuse99/suggestarr:latest
- name: Push Docker Image
run: |
docker push ciuse99/suggestarr:latest
# temporary keeping two images
- name: Build Docker Image
run: |
docker build . -t ciuse99/jellyseer_request_automation:latest
- name: Push Docker Image
- name: Build and Push Docker Image (SuggestArr)
run: |
docker push ciuse99/jellyseer_request_automation:latest
docker buildx build \
--platform linux/amd64,linux/arm64 \
--cache-from type=registry,ref=ciuse99/suggestarr:cache \
--cache-to type=registry,ref=ciuse99/suggestarr:cache,mode=max \
-t ciuse99/suggestarr:latest \
-f docker/Dockerfile . --push
16 changes: 9 additions & 7 deletions .github/workflows/docker_hub_build_nightly.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@

name: Build and Publish Docker Image to Docker Hub

on:
push:
branches:
- nightly

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/[email protected].1
uses: actions/[email protected].2

- name: Set up Docker Buildx
run: |
docker run --privileged --rm tonistiigi/binfmt --install all
docker buildx create --use
docker buildx inspect --bootstrap
uses: docker/[email protected]

- name: Log in to Docker Hub
run: echo ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | docker login -u ciuse99 --password-stdin

- name: Build and Push Docker Image
run: |
docker buildx build --platform linux/amd64,linux/arm64 -t ciuse99/suggestarr:nightly --push .
docker buildx build \
--platform linux/amd64,linux/arm64 \
--cache-from type=registry,ref=ciuse99/suggestarr:cache \
--cache-to type=registry,ref=ciuse99/suggestarr:cache,mode=max \
-t ciuse99/suggestarr:nightly \
-f docker/Dockerfile . --push
52 changes: 0 additions & 52 deletions Dockerfile

This file was deleted.

File renamed without changes.
21 changes: 11 additions & 10 deletions app.py → api_service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
from flask_cors import CORS
from asgiref.wsgi import WsgiToAsgi

from utils.utils import AppUtils
from config.logger_manager import LoggerManager

from blueprints.jellyfin.routes import jellyfin_bp
from blueprints.seer.routes import seer_bp
from blueprints.plex.routes import plex_bp
from blueprints.automation.routes import automation_bp
from blueprints.logs.routes import logs_bp
from blueprints.config.routes import config_bp
from api_service.utils.utils import AppUtils
from api_service.config.logger_manager import LoggerManager

from api_service.blueprints.jellyfin.routes import jellyfin_bp
from api_service.blueprints.seer.routes import seer_bp
from api_service.blueprints.plex.routes import plex_bp
from api_service.blueprints.automation.routes import automation_bp
from api_service.blueprints.logs.routes import logs_bp
from api_service.blueprints.config.routes import config_bp

executor = ThreadPoolExecutor(max_workers=3)
logger = LoggerManager().get_logger(__name__)
Expand All @@ -29,7 +30,7 @@ def create_app():
if AppUtils.is_last_worker():
AppUtils.print_welcome_message() # Print only for last worker

application = Flask(__name__, static_folder='static', static_url_path='/')
application = Flask(__name__, static_folder='../static', static_url_path='/')
CORS(application)

application.register_blueprint(jellyfin_bp, url_prefix='/api/jellyfin')
Expand Down Expand Up @@ -58,7 +59,7 @@ def serve_frontend(path):
"""
Serve the built frontend's index.html or any other static file.
"""
app.static_folder = './suggestarr-frontend/dist'
app.static_folder = '../static'
if path == "" or not os.path.exists(os.path.join(app.static_folder, path)):
return send_from_directory(app.static_folder, 'index.html')
else:
Expand Down
16 changes: 8 additions & 8 deletions automate_process.py → api_service/automate_process.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import asyncio

from config.config import load_env_vars
from config.logger_manager import LoggerManager
from handler.jellyfin_handler import JellyfinHandler
from handler.plex_handler import PlexHandler
from jellyfin.jellyfin_client import JellyfinClient
from jellyseer.seer_client import SeerClient
from plex.plex_client import PlexClient
from tmdb.tmdb_client import TMDbClient
from api_service.config.config import load_env_vars
from api_service.config.logger_manager import LoggerManager
from api_service.handler.jellyfin_handler import JellyfinHandler
from api_service.handler.plex_handler import PlexHandler
from api_service.services.jellyfin.jellyfin_client import JellyfinClient
from api_service.services.jellyseer.seer_client import SeerClient
from api_service.services.plex.plex_client import PlexClient
from api_service.services.tmdb.tmdb_client import TMDbClient


class ContentAutomation:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import Blueprint, jsonify
from tasks.tasks import run_content_automation_task
from config.logger_manager import LoggerManager
from api_service.tasks.tasks import run_content_automation_task
from api_service.config.logger_manager import LoggerManager

logger = LoggerManager().get_logger(__name__)
automation_bp = Blueprint('automation', __name__)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import Blueprint, request, jsonify
from config.config import load_env_vars, save_env_vars, clear_env_vars
from config.logger_manager import LoggerManager
from api_service.config.config import load_env_vars, save_env_vars, clear_env_vars
from api_service.config.logger_manager import LoggerManager

logger = LoggerManager().get_logger(__name__)
config_bp = Blueprint('config', __name__)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import Blueprint, request, jsonify
from jellyfin.jellyfin_client import JellyfinClient
from config.logger_manager import LoggerManager
from api_service.services.jellyfin.jellyfin_client import JellyfinClient
from api_service.config.logger_manager import LoggerManager

logger = LoggerManager().get_logger(__name__)
jellyfin_bp = Blueprint('jellyfin', __name__)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import Blueprint, jsonify
from config.logger_manager import LoggerManager
from api_service.config.logger_manager import LoggerManager

logger = LoggerManager().get_logger(__name__)
logs_bp = Blueprint('logs', __name__)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import uuid
from flask import Blueprint, request, jsonify
from plex.plex_auth import PlexAuth
from plex.plex_client import PlexClient
from config.logger_manager import LoggerManager
from api_service.services.plex.plex_auth import PlexAuth
from api_service.services.plex.plex_client import PlexClient
from api_service.config.logger_manager import LoggerManager

logger = LoggerManager().get_logger(__name__)
plex_bp = Blueprint('plex', __name__)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import Blueprint, request, jsonify
from jellyseer.seer_client import SeerClient
from config.logger_manager import LoggerManager
from api_service.services.jellyseer.seer_client import SeerClient
from api_service.config.logger_manager import LoggerManager

logger = LoggerManager().get_logger(__name__)
seer_bp = Blueprint('seer', __name__)
Expand Down
File renamed without changes.
15 changes: 10 additions & 5 deletions config/config.py → api_service/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import platform
import yaml
from croniter import croniter
from config.logger_manager import LoggerManager
from api_service.config.logger_manager import LoggerManager

logger = LoggerManager().get_logger(__name__)

# Constants for environment variables
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
CONFIG_PATH = os.path.join(BASE_DIR, 'config_files', 'config.yaml')
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
CONFIG_PATH = os.path.join(BASE_DIR, 'config', 'config_files', 'config.yaml')

ENV_VARS = {
'TMDB_API_KEY': 'TMDB_API_KEY',
Expand Down Expand Up @@ -79,7 +79,12 @@ def save_env_vars(config_data):

# Prepare environment variables to be saved
env_vars = {key: config_data.get(key, default_value()) for key, default_value in get_default_values().items()}


# Create config.yaml file if it does not exist
if not os.path.exists(CONFIG_PATH):
logger.info(f'Creating new file for config at {CONFIG_PATH}')
open(CONFIG_PATH, 'w').close() # Create an empty file

# Write environment variables to the config.yaml file
with open(CONFIG_PATH, 'w', encoding='utf-8') as f:
yaml.safe_dump(env_vars, f)
Expand All @@ -102,7 +107,7 @@ def clear_env_vars():
os.remove(CONFIG_PATH)
logger.info("Configuration cleared successfully.")
except OSError as e:
print(f"Error deleting {CONFIG_PATH}: {e}")
logger.error(f"Error deleting {CONFIG_PATH}: {e}")


def update_cron_job(cron_time):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio

from jellyfin.jellyfin_client import JellyfinClient
from jellyseer.seer_client import SeerClient
from tmdb.tmdb_client import TMDbClient
from api_service.services.jellyfin.jellyfin_client import JellyfinClient
from api_service.services.jellyseer.seer_client import SeerClient
from api_service.services.tmdb.tmdb_client import TMDbClient

class JellyfinHandler:
def __init__(self, jellyfin_client:JellyfinClient, jellyseer_client:SeerClient, tmdb_client:TMDbClient, logger, max_similar_movie, max_similar_tv):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio

from jellyseer.seer_client import SeerClient
from plex.plex_client import PlexClient
from tmdb.tmdb_client import TMDbClient
from api_service.services.jellyseer.seer_client import SeerClient
from api_service.services.plex.plex_client import PlexClient
from api_service.services.tmdb.tmdb_client import TMDbClient

class PlexHandler:
def __init__(self, plex_client:PlexClient, jellyseer_client:SeerClient, tmdb_client:TMDbClient, logger, max_similar_movie, max_similar_tv):
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
import re
import aiohttp
from config.logger_manager import LoggerManager
from api_service.config.logger_manager import LoggerManager

# Constants
REQUEST_TIMEOUT = 10 # Timeout in seconds for HTTP requests
Expand Down
File renamed without changes.
Loading

0 comments on commit 7d1977b

Please sign in to comment.