-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
df67166
commit 7fb575a
Showing
38 changed files
with
724 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
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,27 @@ | ||
load("@rules_python//python:defs.bzl", "py_library", "py_test") | ||
|
||
py_library( | ||
name = "models_py", | ||
srcs = ["models.py"], | ||
visibility = ["//ark_nova_stats:__subpackages__"], | ||
deps = [ | ||
":config_py", | ||
"@py_deps//requests", | ||
"@py_deps//sqlalchemy", | ||
], | ||
) | ||
|
||
py_library( | ||
name = "config_py", | ||
srcs = ["config.py"], | ||
visibility = ["//ark_nova_stats:__subpackages__"], | ||
deps = [ | ||
"//base:flask_app_py", | ||
], | ||
) | ||
|
||
py_test( | ||
name = "models_test", | ||
srcs = ["models_test.py"], | ||
deps = [":models_py"], | ||
) |
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,23 @@ | ||
load("@rules_python//python:defs.bzl", "py_library") | ||
load("//tools/build_rules:api_image.bzl", "api_image") | ||
|
||
py_library( | ||
name = "app", | ||
srcs = ["app.py"], | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
"//ark_nova_stats:config_py", | ||
"//ark_nova_stats:models_py", | ||
"//ark_nova_stats/api/gql:schema", | ||
"@py_deps//flask", | ||
"@py_deps//graphql_server", | ||
], | ||
) | ||
|
||
api_image( | ||
name = "api_image", | ||
app_package = "ark_nova_stats.api.app", | ||
docker_hub_repository = "docker.io/shaldengeki/ark-nova-stats-api", | ||
repo_tags = ["shaldengeki/ark-nova-stats-api:latest"], | ||
deps = [":app"], | ||
) |
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,15 @@ | ||
import datetime | ||
from datetime import timezone | ||
from typing import Optional | ||
|
||
from flask import abort, redirect, request, session | ||
from graphql_server.flask import GraphQLView # type: ignore | ||
|
||
from ark_nova_stats import models | ||
from ark_nova_stats.api.gql import schema | ||
from ark_nova_stats.config import app, db | ||
|
||
app.add_url_rule( | ||
"/graphql", | ||
view_func=GraphQLView.as_view("graphql", schema=schema.Schema(app), graphiql=True), | ||
) |
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,12 @@ | ||
load("@rules_python//python:defs.bzl", "py_library") | ||
|
||
py_library( | ||
name = "schema", | ||
srcs = ["schema.py"], | ||
visibility = ["//ark_nova_stats/api:__subpackages__"], | ||
deps = [ | ||
"//ark_nova_stats:models_py", | ||
"//ark_nova_stats/api/gql/types:example_model", | ||
"@py_deps//graphql_core", | ||
], | ||
) |
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,15 @@ | ||
from graphql import GraphQLObjectType, GraphQLSchema | ||
|
||
from ark_nova_stats.api.gql.types.example_model import example_model_field | ||
from ark_nova_stats.models import ExampleModel | ||
|
||
|
||
def Schema(app): | ||
return GraphQLSchema( | ||
query=GraphQLObjectType( | ||
name="Query", | ||
fields={ | ||
"testModel": example_model_field(ExampleModel), | ||
}, | ||
), | ||
) |
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,13 @@ | ||
load("@rules_python//python:defs.bzl", "py_library") | ||
|
||
py_library( | ||
name = "example_model", | ||
srcs = ["example_model.py"], | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
"//ark_nova_stats:config_py", | ||
"//ark_nova_stats:models_py", | ||
"@py_deps//flask", | ||
"@py_deps//graphql_core", | ||
], | ||
) |
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,54 @@ | ||
from typing import Any, Optional, Type | ||
|
||
from flask import Flask | ||
from graphql import ( | ||
GraphQLArgument, | ||
GraphQLBoolean, | ||
GraphQLField, | ||
GraphQLFloat, | ||
GraphQLInt, | ||
GraphQLList, | ||
GraphQLNonNull, | ||
GraphQLObjectType, | ||
) | ||
|
||
from ark_nova_stats.config import app, db | ||
from ark_nova_stats.models import ExampleModel | ||
|
||
|
||
def example_model_fields() -> dict[str, GraphQLField]: | ||
return { | ||
"id": GraphQLField( | ||
GraphQLNonNull(GraphQLInt), | ||
description="The id of the example model.", | ||
), | ||
} | ||
|
||
|
||
example_model_type = GraphQLObjectType( | ||
"ExampleModel", | ||
description="A example model.", | ||
fields=example_model_fields, | ||
) | ||
|
||
|
||
def fetch_example_model( | ||
example_model: Type[ExampleModel], params: dict[str, Any] | ||
) -> Optional[ExampleModel]: | ||
return (example_model.query.filter(example_model.id == params["id"])).first() | ||
|
||
|
||
example_model_filters: dict[str, GraphQLArgument] = { | ||
"id": GraphQLArgument( | ||
GraphQLNonNull(GraphQLInt), | ||
description="ID of the example model.", | ||
), | ||
} | ||
|
||
|
||
def example_model_field(example_model: type[ExampleModel]) -> GraphQLField: | ||
return GraphQLField( | ||
example_model_type, | ||
args=example_model_filters, | ||
resolve=lambda root, info, **args: fetch_example_model(example_model, args), | ||
) |
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,76 @@ | ||
load("@py_deps//:requirements.bzl", "requirement") | ||
load("@rules_python//python:defs.bzl", "py_binary", "py_library") | ||
load("//tools/build_rules:cross_platform_image.bzl", "cross_platform_image") | ||
load("//tools/build_rules:py_layer.bzl", "py_oci_image") | ||
|
||
py_library( | ||
name = "migrate_lib", | ||
srcs = glob(["**/*.py"]), # keep | ||
imports = [".."], | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
requirement("alembic"), | ||
requirement("Flask"), | ||
], | ||
) | ||
|
||
py_binary( | ||
name = "binary", | ||
srcs = glob(["**/*.py"]), # keep | ||
data = ["alembic.ini"], | ||
imports = [".."], | ||
main = "__main__.py", | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
"//ark_nova_stats:config_py", | ||
"//scripts:wait_for_postgres", # keep | ||
"@py_deps//flask_migrate", | ||
"@rules_python//python/runfiles", | ||
], | ||
) | ||
|
||
py_oci_image( | ||
name = "base_image", | ||
base = "@python3_image", | ||
binary = ":binary", | ||
cmd = [ | ||
"/ark_nova_stats/api/migrations/binary.runfiles/_main/scripts/wait_for_postgres", | ||
"/ark_nova_stats/api/migrations/binary", | ||
], | ||
env = { | ||
"FLASK_APP": "app.py", | ||
"FLASK_DEBUG": "True", | ||
"API_PORT": "5000", | ||
"FRONTEND_PROTOCOL": "http", | ||
"FRONTEND_HOST": "frontend", | ||
"FRONTEND_PORT": "5001", | ||
"DB_HOST": "pg", | ||
"DB_USERNAME": "admin", | ||
"DB_PASSWORD": "development", | ||
"DATABASE_NAME": "api_development", | ||
"FITBIT_CLIENT_ID": "testing", | ||
"FITBIT_CLIENT_SECRET": "testing", | ||
"FITBIT_VERIFICATION_CODE": "testing", | ||
"FLASK_SECRET_KEY": "testing", | ||
}, | ||
) | ||
|
||
# $ bazel run //ark_nova_stats/api/migrations:image_tarball | ||
# $ docker run --rm shaldengeki/ark-nova-stats-api-migrations:latest | ||
cross_platform_image( | ||
name = "image", | ||
image = ":base_image", | ||
repo_tags = ["shaldengeki/ark-nova-stats-api-migrations:latest"], | ||
repository = "docker.io/shaldengeki/ark-nova-stats-api-migrations", | ||
visibility = ["//ark_nova_stats/api/migrations:__subpackages__"], | ||
) | ||
|
||
py_library( | ||
name = "env", | ||
srcs = ["env.py"], | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
"@py_deps//alembic", | ||
"@py_deps//flask", | ||
], | ||
) |
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 @@ | ||
Single-database configuration for Flask. |
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,15 @@ | ||
import shutil | ||
|
||
from flask_migrate import upgrade | ||
from python.runfiles import Runfiles | ||
|
||
from ark_nova_stats.config import app | ||
|
||
if __name__ == "__main__": | ||
# Copy the alembic.ini. | ||
r = Runfiles.Create() | ||
alembic_ini_src = r.Rlocation("_main/ark_nova_stats/api/migrations/alembic.ini") | ||
shutil.copyfile(alembic_ini_src, "/ark_nova_stats/api/migrations/alembic.ini") | ||
|
||
with app.app_context(): | ||
upgrade(directory="/ark_nova_stats/api/migrations") |
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,51 @@ | ||
# A generic, single database configuration. | ||
|
||
[alembic] | ||
# template used to generate migration files | ||
# file_template = %%(rev)s_%%(slug)s | ||
|
||
# set to 'true' to run the environment during | ||
# the 'revision' command, regardless of autogenerate | ||
# revision_environment = false | ||
|
||
script_location = . | ||
|
||
# Logging configuration | ||
[loggers] | ||
keys = root,sqlalchemy,alembic,flask_migrate | ||
|
||
[handlers] | ||
keys = console | ||
|
||
[formatters] | ||
keys = generic | ||
|
||
[logger_root] | ||
level = WARN | ||
handlers = console | ||
qualname = | ||
|
||
[logger_sqlalchemy] | ||
level = WARN | ||
handlers = | ||
qualname = sqlalchemy.engine | ||
|
||
[logger_alembic] | ||
level = INFO | ||
handlers = | ||
qualname = alembic | ||
|
||
[logger_flask_migrate] | ||
level = INFO | ||
handlers = | ||
qualname = flask_migrate | ||
|
||
[handler_console] | ||
class = StreamHandler | ||
args = (sys.stderr,) | ||
level = NOTSET | ||
formatter = generic | ||
|
||
[formatter_generic] | ||
format = %(levelname)-5.5s [%(name)s] %(message)s | ||
datefmt = %H:%M:%S |
Oops, something went wrong.