From 84cfc87682dfdff2cabfdf8fe32a805f2295621c Mon Sep 17 00:00:00 2001 From: AG Date: Thu, 23 Sep 2021 14:44:05 -0700 Subject: [PATCH] cleanup remove debugging print out databse connection point to the correct container repostiory don't fully declar ghcr.io for container. update on k8s update move to entrypoint change to shell forego the entrypoint script --- .github/workflows/server-ci-cd-mainnet.yml | 2 +- .k8s/mainnet/server.yaml | 2 +- server/Dockerfile | 5 ++-- .../api/analysis/calculate_divergent_block.py | 1 - server/api/config.py | 6 +++++ server/api/dispute/w3.py | 1 - server/api/main.py | 3 +-- server/api/models/disputes.py | 1 - server/api/models/indexer.py | 7 +++--- server/api/transport/upload.py | 7 ++++-- server/api/views/disputes.py | 1 - server/api/views/divergent_blocks.py | 3 --- server/api/views/indexers.py | 25 +++++++++++++------ server/docker-entrypoint.sh | 2 +- 14 files changed, 38 insertions(+), 28 deletions(-) diff --git a/.github/workflows/server-ci-cd-mainnet.yml b/.github/workflows/server-ci-cd-mainnet.yml index 5813c30..697a47d 100644 --- a/.github/workflows/server-ci-cd-mainnet.yml +++ b/.github/workflows/server-ci-cd-mainnet.yml @@ -3,7 +3,7 @@ on: push: paths: - 'server/**' - - 'k8s/**' + - '.k8s/**' - '.github/**' env: BASE_IMAGE: ghcr.io/edgeandnode/graph-disputes-server diff --git a/.k8s/mainnet/server.yaml b/.k8s/mainnet/server.yaml index ba75861..8afb4a9 100644 --- a/.k8s/mainnet/server.yaml +++ b/.k8s/mainnet/server.yaml @@ -17,7 +17,7 @@ spec: - name: docker-registry containers: - name: app - image: ghcr.io/graph-disputes-server + image: graph-disputes-server env: - name: DB_HOST valueFrom: diff --git a/server/Dockerfile b/server/Dockerfile index 177216f..f699b6f 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -40,8 +40,9 @@ FROM python-base as final COPY --from=builder /venv /venv COPY docker-entrypoint.sh ./ -RUN ["chmod", "+x", "docker-entrypoint.sh"] +RUN chmod +x ./docker-entrypoint.sh EXPOSE 5432 EXPOSE 8000 -CMD ["./docker-entrypoint.sh"] +CMD . /venv/bin/activate && uvicorn api.asgi:app --host 0.0.0.0 --port 8000 +# ENTRYPOINT ["./docker-entrypoint.sh"] diff --git a/server/api/analysis/calculate_divergent_block.py b/server/api/analysis/calculate_divergent_block.py index fe203b8..6fe52ae 100644 --- a/server/api/analysis/calculate_divergent_block.py +++ b/server/api/analysis/calculate_divergent_block.py @@ -6,7 +6,6 @@ from psycopg2.extras import NumericRange from tensorflow.python.lib.io import file_io -import ipdb def read_csv_file(filename): """ diff --git a/server/api/config.py b/server/api/config.py index 275ffa7..adf856c 100644 --- a/server/api/config.py +++ b/server/api/config.py @@ -7,6 +7,7 @@ FASTAPI_DEPLOYMENT = os.getenv("FASTAPI_DEPLOYMENT") +### NOT USED ON if FASTAPI_DEPLOYMENT == "production": environment_path = Path.joinpath(Path(__file__).parent, ".env.prod") elif FASTAPI_DEPLOYMENT == "dev": @@ -16,6 +17,11 @@ config = Config(environment_path) +print("HOST") +print(config("DB_HOST")) +print("PORT") +print(config("DB_PORT")) + DB_DRIVER = config("DB_DRIVER", default="postgresql") DB_HOST = config("DB_HOST", default="127.0.0.1") diff --git a/server/api/dispute/w3.py b/server/api/dispute/w3.py index da62747..0f8491b 100644 --- a/server/api/dispute/w3.py +++ b/server/api/dispute/w3.py @@ -11,7 +11,6 @@ from eth_typing import URI from web3 import Web3 -from web3.types import RPCEndpoint, RPCResponse # Inline this. can't shade versions of sqlalchemy diff --git a/server/api/main.py b/server/api/main.py index 7f8e44f..5b55402 100644 --- a/server/api/main.py +++ b/server/api/main.py @@ -9,7 +9,7 @@ from starlette.requests import Request -from starlette_context import context, plugins +from starlette_context import plugins from starlette_context.middleware import ContextMiddleware from fastapi.middleware.cors import CORSMiddleware @@ -68,7 +68,6 @@ async def log_requests(request: Request, call_next): ) start_time = time.time() - # ipdb.set_trace() response = await call_next(request) process_time = (time.time() - start_time) * 1000 diff --git a/server/api/models/disputes.py b/server/api/models/disputes.py index 6cc1787..e680299 100644 --- a/server/api/models/disputes.py +++ b/server/api/models/disputes.py @@ -1,6 +1,5 @@ import enum import datetime -from fastapi import HTTPException from sqlalchemy import * from sqlalchemy.dialects.postgresql import ARRAY, JSONB, insert diff --git a/server/api/models/indexer.py b/server/api/models/indexer.py index 2f90499..708f014 100644 --- a/server/api/models/indexer.py +++ b/server/api/models/indexer.py @@ -1,15 +1,14 @@ from datetime import datetime -from sqlalchemy.dialects.postgresql import JSONB, insert +from sqlalchemy.dialects.postgresql import insert from . import db class Indexer(db.Model): __tablename__ = "indexer" - id = db.Column(db.BigInteger(),nullable=True) + id = db.Column(db.BigInteger(), nullable=True) indexer_id = db.Column( - db.String(), - primary_key=True + db.String(), primary_key=True ) # Won't make primary key so can keep updated records name = db.Column(db.Unicode(), default="unnamed") updated_at = db.Column(db.DateTime, default=datetime.utcnow) diff --git a/server/api/transport/upload.py b/server/api/transport/upload.py index 03f4773..6f91e6c 100644 --- a/server/api/transport/upload.py +++ b/server/api/transport/upload.py @@ -1,12 +1,12 @@ import logging from typing import Optional -import ipdb from pydantic import BaseModel from starlette.requests import Request from fastapi import APIRouter, File, UploadFile, HTTPException from ..dispute.fsm import create_resolver from ..models.disputes import DisputeStage + router = APIRouter() logger = logging.getLogger(__name__) @@ -33,7 +33,9 @@ async def upload_poi_to_gcloud(request: Request, file: UploadFile = File(...)): if stage != DisputeStage.waiting_for_poi: logger.info("Not waiting for poi") - raise HTTPException(status_code=404, detail="This dispute is no longer accepting POI") + raise HTTPException( + status_code=404, detail="This dispute is no longer accepting POI" + ) logger.info( "Uploading file {} for indexer {} for dispute {}".format( @@ -99,5 +101,6 @@ async def upload_metadata_to_gcloud(request: Request, file: UploadFile = File(.. return IndexerUploadResponse(upload_path=result) + def init_app(app): app.include_router(router) diff --git a/server/api/views/disputes.py b/server/api/views/disputes.py index 8707e0a..f043c4d 100644 --- a/server/api/views/disputes.py +++ b/server/api/views/disputes.py @@ -12,7 +12,6 @@ from ..models.indexer_uploads import DataKindEnum, IndexerUploads -from ..dispute.fsm import DisputeResolver from ..graphql import * diff --git a/server/api/views/divergent_blocks.py b/server/api/views/divergent_blocks.py index 7d04843..b162837 100644 --- a/server/api/views/divergent_blocks.py +++ b/server/api/views/divergent_blocks.py @@ -1,5 +1,3 @@ -from numpy.lib.function_base import disp -from api.models.disputes import Dispute import logging from typing import List, Dict, Optional, Any from fastapi import APIRouter @@ -11,7 +9,6 @@ from ..models.divergent_blocks import DivergentBlocks from ..dispute.fsm import DisputeResolver, create_resolver -from api.models import divergent_blocks logger = logging.getLogger(__name__) diff --git a/server/api/views/indexers.py b/server/api/views/indexers.py index 7482126..3cf1e40 100644 --- a/server/api/views/indexers.py +++ b/server/api/views/indexers.py @@ -7,7 +7,6 @@ from ..models.indexer import Indexer from ..models.indexer_uploads import DataKindEnum, IndexerUploads from ..models.divergent_blocks import DivergentBlocks -from api.models import indexer router = APIRouter() @@ -30,6 +29,7 @@ class IndexerUpload(BaseModel): data_path: str data_kind_enum: DataKindEnum + class IndexerResponse(BaseModel): indexer_id: str name: str @@ -37,7 +37,6 @@ class IndexerResponse(BaseModel): indexer_uploads: Optional[List[IndexerUpload]] = [] - @router.post("/indexers") async def create_indexer(indexer: IndexerModel): indexer = await Indexer.create( @@ -54,26 +53,36 @@ async def get_indexer(uid: str): indexer = await Indexer.query.where(Indexer.indexer_id == uid).gino.first() return indexer.to_dict() + class IndexerUploadResponse(BaseModel): - path:str - kind:str + path: str + kind: str + class IndexerUploadsResponse(BaseModel): indexer_uploads: List[IndexerUploadResponse] -@router.get("/indexers/uploads/{indexer_id}/{dispute_id}", response_model=IndexerUploadsResponse) + +@router.get( + "/indexers/uploads/{indexer_id}/{dispute_id}", response_model=IndexerUploadsResponse +) async def get_indexer_uploads(indexer_id: str, dispute_id: str): indexer_uploads = await IndexerUploads.query.where( - and_(IndexerUploads.indexer_id == indexer_id, - IndexerUploads.dispute_id == dispute_id + and_( + IndexerUploads.indexer_id == indexer_id, + IndexerUploads.dispute_id == dispute_id, ) ).gino.all() - mapped_uploads = [IndexerUploadResponse(path=d.data_path, kind=d.data_kind_enum.name) for d in indexer_uploads] + mapped_uploads = [ + IndexerUploadResponse(path=d.data_path, kind=d.data_kind_enum.name) + for d in indexer_uploads + ] uploads_response = IndexerUploadsResponse(indexer_uploads=mapped_uploads) return uploads_response + @router.get("/indexers/divergent/{uid}") async def get_divergent_blocks(uid: str): divergent_blocks = await DivergentBlocks.get_or_404(uid) diff --git a/server/docker-entrypoint.sh b/server/docker-entrypoint.sh index fe40c71..dbe1684 100644 --- a/server/docker-entrypoint.sh +++ b/server/docker-entrypoint.sh @@ -1,4 +1,4 @@ -#!/bin/sh +/bin/sh set -e