Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: setup a devcontainer for python and initialize the flask backend #1

Merged
merged 8 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM python:3.12

# Install python requirements
COPY backend/requirements-combined.txt requirements-combined.txt
RUN pip install -r requirements-combined.txt
33 changes: 33 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "retro_olympics_webapp",
"dockerComposeFile": "docker-compose.yml",
"workspaceFolder": "/workspace",
"service": "webapp",
"customizations": {
"vscode": {
"settings": {
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "always"
}
},
"isort.args": ["--profile", "black"],
"ruff.nativeServer": true
},
"extensions": [
"eamodio.gitlens",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.black-formatter",
"ms-python.isort",
"charliermarsh.ruff"
]
}
},
"remoteUser": "root",
"remoteEnv": {
"PYTHONPATH": "/workspace/backend/src"
}
}
13 changes: 13 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3.8"
services:
webapp:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
entrypoint: ["tail", "-f", "/dev/null"]
volumes:
- ..:/workspace
postgres:
image: "postgres:16"
environment:
POSTGRES_HOST_AUTH_METHOD: trust
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ build
# typescript
*.tsbuildinfo
next-env.d.ts

# Python
*.pyc
Empty file removed backend/.gitkeep
Empty file.
57 changes: 57 additions & 0 deletions backend/requirements-combined.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --output-file=backend/requirements-combined.txt backend/requirements-dev.in backend/requirements.in
#
black==24.4.2
# via -r backend/requirements-dev.in
blinker==1.8.2
# via flask
build==1.2.1
# via pip-tools
click==8.1.7
# via
# black
# flask
# pip-tools
flask==3.0.3
# via -r backend/requirements.in
invoke==2.2.0
# via -r backend/requirements-dev.in
isort==5.13.2
# via -r backend/requirements-dev.in
itsdangerous==2.2.0
# via flask
jinja2==3.1.4
# via flask
markupsafe==2.1.5
# via
# jinja2
# werkzeug
mypy-extensions==1.0.0
# via black
packaging==24.1
# via
# black
# build
pathspec==0.12.1
# via black
pip-tools==7.4.1
# via -r backend/requirements-dev.in
platformdirs==4.2.2
# via black
pyproject-hooks==1.1.0
# via
# build
# pip-tools
ruff==0.4.9
# via -r backend/requirements-dev.in
werkzeug==3.0.3
# via flask
wheel==0.43.0
# via pip-tools

# The following packages are considered to be unsafe in a requirements file:
# pip
# setuptools
5 changes: 5 additions & 0 deletions backend/requirements-dev.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
black==24.4.2
invoke==2.2.0
pip-tools==7.4.1
isort==5.13.2
ruff==0.4.9
1 change: 1 addition & 0 deletions backend/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flask==3.0.3
22 changes: 22 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile backend/requirements.in
#
blinker==1.8.2
# via flask
click==8.1.7
# via flask
flask==3.0.3
# via -r backend/requirements.in
itsdangerous==2.2.0
# via flask
jinja2==3.1.4
# via flask
markupsafe==2.1.5
# via
# jinja2
# werkzeug
werkzeug==3.0.3
# via flask
3 changes: 3 additions & 0 deletions backend/src/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .main import get_api

__all__ = ["get_api"]
3 changes: 3 additions & 0 deletions backend/src/api/components/hello/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .controller import hello_api

__all__ = ["hello_api"]
10 changes: 10 additions & 0 deletions backend/src/api/components/hello/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from flask import Blueprint, jsonify

from api.consts import COMMON_API_PREFIX

hello_api = Blueprint("hello_api", __name__, url_prefix=COMMON_API_PREFIX + "/hello")


@hello_api.route("/", methods=["GET"])
def get_collections():
return jsonify({"message": "Hello World ! From the retro olympics backend !"}), 200
1 change: 1 addition & 0 deletions backend/src/api/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMMON_API_PREFIX = "/api/v1"
15 changes: 15 additions & 0 deletions backend/src/api/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from flask import Flask

from api.components.hello import hello_api

api: Flask | None = None


def get_api() -> Flask:
global api
if api is None:
api = Flask(__name__)

api.register_blueprint(hello_api)

return api
22 changes: 22 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from invoke import task

from api import get_api


# Python reqs
@task
def update_app_reqs(c):
c.run("pip-compile backend/requirements.in")


@task
def update_combined_reqs(c):
c.run(
"pip-compile backend/requirements.in backend/requirements-dev.in -o backend/requirements-combined.txt"
)


# Run
@task
def run_back(c):
get_api().run()
Loading