Skip to content

Commit

Permalink
Initial commit with basic Flask project structure
Browse files Browse the repository at this point in the history
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
CFIALeronB committed Nov 6, 2023
1 parent 152d477 commit 026c987
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .gitignore
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/
16 changes: 16 additions & 0 deletions Dockerfile
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
6 changes: 6 additions & 0 deletions devcontainer/devcontainer.json
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"
}

2 changes: 2 additions & 0 deletions requirements-production.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flask
gunicorn
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flask
gunicorn
# additional dependencies
Empty file added src/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions src/app.py
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 added tests/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions tests/test_main.py
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)

0 comments on commit 026c987

Please sign in to comment.