Skip to content
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
17 changes: 17 additions & 0 deletions docker-fastapi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.8 AS py

RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends \
less vim \
&& rm -rf /var/lib/apt/lists/*

RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
ENV PATH /root/.poetry/bin:$PATH
RUN poetry completions bash > /etc/bash_completion.d/poetry.bash-completion \
&& poetry self update \
&& poetry config virtualenvs.in-project true --local

WORKDIR /home/api
COPY poetry.lock pyproject.toml ./
RUN poetry install

CMD ["poetry", "run", "uvicorn", "src.api:app", "--reload", "--host", "0.0.0.0", "--port", "8000"]
12 changes: 12 additions & 0 deletions docker-fastapi/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "3"
services:
python:
build: .
image: api
container_name: api
ports:
- "9000:8000"
volumes:
- $PWD:/home/api
working_dir: /home/api
tty: true
372 changes: 372 additions & 0 deletions docker-fastapi/poetry.lock

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions docker-fastapi/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "api"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^3.8"
fastapi = "^0.61.0"
uvicorn = "^0.11.8"
pytest = "^6.0.1"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
15 changes: 15 additions & 0 deletions docker-fastapi/src/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Optional

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
return {"item:id": item_id, "q": q}
11 changes: 11 additions & 0 deletions docker-fastapi/src/web1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.8

RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends \
less vim \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /home/api
COPY . .
RUN pip install -r requirements.txt

CMD ["bash"]
4 changes: 4 additions & 0 deletions docker-fastapi/src/web1/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
grpcio==1.31.0
grpcio-tools==1.31.0
protobuf==3.13.0
six==1.15.0
16 changes: 16 additions & 0 deletions docker-fastapi/src/web1/web1.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";

package web1;

service Web1 {
rpc SayHello (HelloRequest) returns (HelloReply) {};
rpc SayHelloAgain (HelloRequest) returns (HelloReply) {};
}

message HelloRequest {
string name = 1;
}

message HelloReply {
string message = 1;
}
23 changes: 23 additions & 0 deletions docker-fastapi/src/web1/web1_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import logging

import grpc

import web1_pb2
import web1_pb2_grpc


def run():
with grpc.insecure_channel('localhost:50051') as channel:
stub = web1_pb2_grpc.Web1Stub(channel)
print('----- SayHello -----')
response = stub.SayHello(web1_pb2.HelloRequest(name='WEB1'))
print(response.message)
print()
print('----- SayHelloAgain -----')
response = stub.SayHelloAgain(web1_pb2.HelloRequest(name='WEB1AGAIN'))
print(response.message)


if __name__ == '__main__':
logging.basicConfig()
run()
146 changes: 146 additions & 0 deletions docker-fastapi/src/web1/web1_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 99 additions & 0 deletions docker-fastapi/src/web1/web1_pb2_grpc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

import web1_pb2 as web1__pb2


class Web1Stub(object):
"""Missing associated documentation comment in .proto file."""

def __init__(self, channel):
"""Constructor.

Args:
channel: A grpc.Channel.
"""
self.SayHello = channel.unary_unary(
'/web1.Web1/SayHello',
request_serializer=web1__pb2.HelloRequest.SerializeToString,
response_deserializer=web1__pb2.HelloReply.FromString,
)
self.SayHelloAgain = channel.unary_unary(
'/web1.Web1/SayHelloAgain',
request_serializer=web1__pb2.HelloRequest.SerializeToString,
response_deserializer=web1__pb2.HelloReply.FromString,
)


class Web1Servicer(object):
"""Missing associated documentation comment in .proto file."""

def SayHello(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def SayHelloAgain(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')


def add_Web1Servicer_to_server(servicer, server):
rpc_method_handlers = {
'SayHello': grpc.unary_unary_rpc_method_handler(
servicer.SayHello,
request_deserializer=web1__pb2.HelloRequest.FromString,
response_serializer=web1__pb2.HelloReply.SerializeToString,
),
'SayHelloAgain': grpc.unary_unary_rpc_method_handler(
servicer.SayHelloAgain,
request_deserializer=web1__pb2.HelloRequest.FromString,
response_serializer=web1__pb2.HelloReply.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'web1.Web1', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))


# This class is part of an EXPERIMENTAL API.
class Web1(object):
"""Missing associated documentation comment in .proto file."""

@staticmethod
def SayHello(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/web1.Web1/SayHello',
web1__pb2.HelloRequest.SerializeToString,
web1__pb2.HelloReply.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

@staticmethod
def SayHelloAgain(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/web1.Web1/SayHelloAgain',
web1__pb2.HelloRequest.SerializeToString,
web1__pb2.HelloReply.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
Loading