This commit is contained in:
p23 2024-12-18 05:00:33 +00:00
parent 9a60c514c5
commit 3eb5d6aa25
4 changed files with 54 additions and 8 deletions

15
Dockerfile Normal file
View File

@ -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

View File

@ -1,10 +1,14 @@
# Niming Backend # Niming Backend
## build
### with docker-compose
See ``docker-compose.yml`` (It is a template)
### Manual
Prepare: Prepare:
``` ```
apt update apt update
apt install libmagic1 libmagic-dev -y apt install libmagic1 libmagic-dev -y
pip3 install -r requirements.txt pip3 install -r requirements.txt
``` ```
@ -13,4 +17,4 @@ Run:
python3 app.py python3 app.py
``` ```
Shirakami Fubuki is the cutest fox!!! Shirakami Fubuki is the cutest fox!!!

27
docker-compose.yml Normal file
View File

@ -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

View File

@ -6,38 +6,38 @@ import grpc
from protobuf_files import igapi_pb2_grpc from protobuf_files import igapi_pb2_grpc
from protobuf_files.igapi_pb2 import Request, Reply 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]: 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) stub = igapi_pb2_grpc.IGAPIStub(channel)
res = stub.account_info(Request()) res = stub.account_info(Request())
return dict(res.result.items()), res.err return dict(res.result.items()), res.err
def request_login() -> Tuple[dict, int]: 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) stub = igapi_pb2_grpc.IGAPIStub(channel)
res = stub.login(Request()) res = stub.login(Request())
return dict(res.result.items()), res.err return dict(res.result.items()), res.err
def request_queue() -> dict: 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) stub = igapi_pb2_grpc.IGAPIStub(channel)
res = stub.queue(Request()) res = stub.queue(Request())
return dict(res.result.items()) return dict(res.result.items())
def request_upload(aid:int) -> Tuple[dict, int]: 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) stub = igapi_pb2_grpc.IGAPIStub(channel)
res = stub.upload(Request(code=aid)) res = stub.upload(Request(code=aid))
return dict(res.result.items()), res.err return dict(res.result.items()), res.err
def request_delete(aid:int, code:str) -> Tuple[dict, int]: 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) stub = igapi_pb2_grpc.IGAPIStub(channel)
res = stub.delete(Request(code=aid, args=[code])) res = stub.delete(Request(code=aid, args=[code]))
return dict(res.result.items()), res.err return dict(res.result.items()), res.err