diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a64fefc --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +# Ignore Python Bytecode +__pycache__/ +*.pyc + +# Ignore Python virtual environment +venv/ + +# Ignore IDE and editor-specific files (customize this based on your editor or IDE) +.idea/ + +# Ignore environment-specific files +.env + +# Ignore any local configuration files +config.local.ini + +# Ignore log files +*.log + +# Ignore compiled Python files +*.pyc +*.pyo +*.pyd + +# Ignore database files +*.db + +# Ignore cache directories +__pycache__/ +.cache/ + +# Ignore any sensitive or private information (e.g., API keys, passwords) +secrets.txt +keys/ +*.pem + +# Ignore Flask Sessions +flask_session/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0afba2e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# Dockerfile +# Base image with Python 3.11 on Alpine +FROM python:3.11-alpine + +# Establish /code as working directory in the container +WORKDIR /code + +# Copy production requirements and install dependencies +COPY ./requirements-production.txt requirements.txt +RUN pip3 install --no-cache-dir -r requirements.txt + +# Copy source code into the working directory +COPY ./src . + +# Use Gunicorn as the server, configuring it for the Flask app +ENTRYPOINT gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 --forwarded-allow-ips "*" main:app diff --git a/devcontainer/devcontainer.json b/devcontainer/devcontainer.json new file mode 100644 index 0000000..5d452f0 --- /dev/null +++ b/devcontainer/devcontainer.json @@ -0,0 +1,6 @@ +{ + "name": "Python 3", + "image": "mcr.microsoft.com/devcontainers/python:3.11", + "postCreateCommand": "pip3 install --user -r requirements.txt" +} + diff --git a/requirements-production.txt b/requirements-production.txt new file mode 100644 index 0000000..e4a286c --- /dev/null +++ b/requirements-production.txt @@ -0,0 +1,2 @@ +flask +gunicorn diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3d3769d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +flask +gunicorn +# additional dependencies diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/app.py b/src/app.py new file mode 100644 index 0000000..45ea532 --- /dev/null +++ b/src/app.py @@ -0,0 +1,11 @@ +# src/main.py +from datetime import datetime +from flask import Flask + +app = Flask(__name__) + +@app.route('/') +def read_root(): + current_time = datetime.now() + unix_timestamp = int(current_time.timestamp()) + return {"current_time": unix_timestamp} diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..b58292e --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,16 @@ +# tests/test_main.py +import unittest +from src.app import app + +class TestApp(unittest.TestCase): + + def setUp(self): + self.app = app.test_client() + self.app.testing = True + + def test_read_root(self): + response = self.app.get('/') + data = response.get_json() + self.assertEqual(response.status_code, 200) + self.assertTrue('current_time' in data) + self.assertIsInstance(data['current_time'], int)