-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit with basic Flask project structure
This commit sets up a minimal Flask project with the following: - app.py: Contains a simple read_root route. - requirements.txt: Lists Flask as a dependency. - .env file: Defines FLASK_APP environment variable for flask run. - venv/: A virtual environment for project-specific dependencies.
- Loading branch information
1 parent
152d477
commit 026c987
Showing
9 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "Python 3", | ||
"image": "mcr.microsoft.com/devcontainers/python:3.11", | ||
"postCreateCommand": "pip3 install --user -r requirements.txt" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
flask | ||
gunicorn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
flask | ||
gunicorn | ||
# additional dependencies |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |