diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f9f0e93 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.11 + +WORKDIR /app + +# apt install +RUN apt-get update && \ + DEBAIN_FRONTEND=noninteractive apt-get install -qy libmagic1 libmagic-dev +# other packages if needed +# git openssh-server vim net-tools iputils-ping btop tmux wget + +# pip3 install +COPY ./requirements.txt /app/requirements.txt +RUN pip3 install -r /app/requirements.txt + +EXPOSE 5000 diff --git a/README.md b/README.md index 94adc09..7a5e02f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,14 @@ # Niming Backend +## build +### with docker-compose +See ``docker-compose.yml`` (It is a template) + +### Manual Prepare: ``` apt update apt install libmagic1 libmagic-dev -y - pip3 install -r requirements.txt ``` @@ -13,4 +17,4 @@ Run: python3 app.py ``` -Shirakami Fubuki is the cutest fox!!! \ No newline at end of file +Shirakami Fubuki is the cutest fox!!! diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e55f21c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: '3' + +# template: docker-compose.yml + +services: + niming-backend-appserver: + build: . + container_name: niming-backend-appserver + volumes: + - "appserver_data/:/app" + ports: + - "5000:5000" + environment: + - PG_HOST=postgresql+psycopg2://root:password@ip:port/niming_db + - S3_ENDPOINT=ip:port + - S3_ACCESS_KEY= + - S3_SECRET_KEY= + - S3_BUCKET=nmfs + - IGRPC_HOST=ip:port + - PLATFORM_ROOT_PASSWORD= + - JWT_KEY= + - TIMEZONE=Asia/Taipei + restart: unless-stopped + working_dir: /app + command: python3 /app/app.py + #networks: + # - networkName diff --git a/utils/ighelper.py b/utils/ighelper.py index 6cb197e..d855a9b 100644 --- a/utils/ighelper.py +++ b/utils/ighelper.py @@ -6,38 +6,38 @@ import grpc from protobuf_files import igapi_pb2_grpc from protobuf_files.igapi_pb2 import Request, Reply -IGAPI_HOST = os.getenv("IGAPI_HOST", None) +IGRPC_HOST = os.getenv("IGRPC_HOST", None) def request_account_info() -> Tuple[dict, int]: - with grpc.insecure_channel(IGAPI_HOST) as channel: + with grpc.insecure_channel(IGRPC_HOST) as channel: stub = igapi_pb2_grpc.IGAPIStub(channel) res = stub.account_info(Request()) return dict(res.result.items()), res.err def request_login() -> Tuple[dict, int]: - with grpc.insecure_channel(IGAPI_HOST) as channel: + with grpc.insecure_channel(IGRPC_HOST) as channel: stub = igapi_pb2_grpc.IGAPIStub(channel) res = stub.login(Request()) return dict(res.result.items()), res.err def request_queue() -> dict: - with grpc.insecure_channel(IGAPI_HOST) as channel: + with grpc.insecure_channel(IGRPC_HOST) as channel: stub = igapi_pb2_grpc.IGAPIStub(channel) res = stub.queue(Request()) return dict(res.result.items()) def request_upload(aid:int) -> Tuple[dict, int]: - with grpc.insecure_channel(IGAPI_HOST) as channel: + with grpc.insecure_channel(IGRPC_HOST) as channel: stub = igapi_pb2_grpc.IGAPIStub(channel) res = stub.upload(Request(code=aid)) return dict(res.result.items()), res.err def request_delete(aid:int, code:str) -> Tuple[dict, int]: - with grpc.insecure_channel(IGAPI_HOST) as channel: + with grpc.insecure_channel(IGRPC_HOST) as channel: stub = igapi_pb2_grpc.IGAPIStub(channel) res = stub.delete(Request(code=aid, args=[code])) return dict(res.result.items()), res.err