update for TZ more
This commit is contained in:
@@ -3,21 +3,30 @@ FROM python:3.9-slim
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Create logs directory
|
||||
# Optional: Set timezone via build argument (can override in docker-compose)
|
||||
ARG TIMEZONE=UTC
|
||||
ENV TZ=$TIMEZONE
|
||||
|
||||
# Install tzdata and optional tools
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends tzdata iputils-ping telnet && \
|
||||
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
|
||||
echo $TZ > /etc/timezone && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create logs directory (used if LOG_TO_FILE=true)
|
||||
RUN mkdir -p /app/logs
|
||||
|
||||
# Install dependencies
|
||||
# Copy dependencies and install
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Optional tools (useful for debugging)
|
||||
RUN apt-get update && apt-get install -y iputils-ping telnet && apt-get clean
|
||||
|
||||
# Copy application code
|
||||
COPY . .
|
||||
|
||||
# Expose port (optional, for documentation)
|
||||
# Expose internal port (Gunicorn default)
|
||||
EXPOSE 8080
|
||||
|
||||
# Default command to run app with Gunicorn
|
||||
# Run the app via Gunicorn
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "wsgi:app"]
|
||||
|
||||
Binary file not shown.
Binary file not shown.
22
app/app.py
22
app/app.py
@@ -4,21 +4,24 @@ from views.user_views import user
|
||||
from views.group_views import group
|
||||
from config import app_config
|
||||
from database import init_app
|
||||
import os, logging
|
||||
|
||||
import logging, os
|
||||
from logging.handlers import RotatingFileHandler
|
||||
|
||||
if app.config['LOG_TO_FILE']:
|
||||
handler = RotatingFileHandler(app.config['LOG_FILE_PATH'], maxBytes=1000000, backupCount=3)
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(app_config)
|
||||
init_app(app)
|
||||
|
||||
if app.config.get('LOG_TO_FILE'):
|
||||
log_file = app.config.get('LOG_FILE_PATH', '/app/logs/app.log')
|
||||
os.makedirs(os.path.dirname(log_file), exist_ok=True)
|
||||
handler = RotatingFileHandler(log_file, maxBytes=1_000_000, backupCount=3)
|
||||
handler.setLevel(logging.INFO)
|
||||
app.logger.addHandler(handler)
|
||||
|
||||
app.logger.setLevel(logging.INFO)
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(app_config)
|
||||
|
||||
init_app(app)
|
||||
|
||||
# Route setup
|
||||
app.register_blueprint(index)
|
||||
app.register_blueprint(user, url_prefix='/user')
|
||||
app.register_blueprint(group, url_prefix='/group')
|
||||
@@ -34,6 +37,3 @@ def legacy_group_list():
|
||||
@app.route('/')
|
||||
def index_redirect():
|
||||
return render_template('index.html')
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0', port=8080)
|
||||
@@ -1,4 +1,4 @@
|
||||
import os
|
||||
import os, pytz
|
||||
|
||||
class Config:
|
||||
DEBUG = False
|
||||
@@ -16,6 +16,10 @@ class Config:
|
||||
OUI_API_LIMIT_PER_SEC = int(os.getenv('OUI_API_LIMIT_PER_SEC', '2'))
|
||||
OUI_API_DAILY_LIMIT = int(os.getenv('OUI_API_DAILY_LIMIT', '10000'))
|
||||
|
||||
# Timezone
|
||||
APP_TIMEZONE = os.getenv('APP_TIMEZONE', 'UTC')
|
||||
TZ = pytz.timezone(APP_TIMEZONE)
|
||||
|
||||
class DevelopmentConfig(Config):
|
||||
"""Development configuration."""
|
||||
DEBUG = True
|
||||
|
||||
@@ -4,3 +4,4 @@ requests
|
||||
BeautifulSoup4
|
||||
lxml
|
||||
gunicorn
|
||||
pytz
|
||||
Binary file not shown.
@@ -1,5 +1,6 @@
|
||||
from flask import Blueprint, render_template, request, jsonify
|
||||
from database import get_db
|
||||
from pytz import timezone
|
||||
from datetime import datetime
|
||||
import requests
|
||||
|
||||
@@ -8,9 +9,15 @@ OUI_API_URL = 'https://api.maclookup.app/v2/macs/{}'
|
||||
|
||||
|
||||
def time_ago(dt):
|
||||
now = datetime.now()
|
||||
diff = now - dt
|
||||
from config import LOCAL_TZ
|
||||
if dt.tzinfo is None:
|
||||
dt = dt.replace(tzinfo=pytz.UTC)
|
||||
local_dt = dt.astimezone(LOCAL_TZ)
|
||||
|
||||
now = datetime.now(LOCAL_TZ)
|
||||
diff = now - local_dt
|
||||
seconds = int(diff.total_seconds())
|
||||
|
||||
if seconds < 60:
|
||||
return f"{seconds}s ago"
|
||||
elif seconds < 3600:
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
version: '3.8'
|
||||
---
|
||||
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
context: ./app
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
TIMEZONE: ${APP_TIMEZONE}
|
||||
volumes:
|
||||
- ./app:/app
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
- FLASK_APP=app.py
|
||||
- FLASK_ENV=development
|
||||
- FLASK_APP=wsgi:app
|
||||
- FLASK_ENV=production
|
||||
- PYTHONPATH=/app
|
||||
restart: no
|
||||
restart: unless-stopped
|
||||
|
||||
nginx:
|
||||
build:
|
||||
@@ -23,4 +25,4 @@ services:
|
||||
- "8080:80"
|
||||
depends_on:
|
||||
- app
|
||||
restart: always
|
||||
restart: unless-stopped
|
||||
Reference in New Issue
Block a user