-
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.
- Loading branch information
Showing
21 changed files
with
294 additions
and
135 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
FROM python:3.11-slim AS server | ||
# https://hub.docker.com/_/python | ||
COPY hello-grpc-python grpc-server | ||
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ | ||
WORKDIR /grpc-server | ||
RUN pip install --upgrade pip | ||
RUN pip install -r requirements.txt --no-cache-dir | ||
RUN sh proto2py.sh | ||
COPY tls/server_certs /var/hello_grpc/server_certs | ||
COPY tls/client_certs /var/hello_grpc/client_certs | ||
ENTRYPOINT ["sh","server_start.sh"] | ||
|
||
FROM python:3.11-slim AS client | ||
COPY hello-grpc-python grpc-client | ||
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ | ||
WORKDIR /grpc-client | ||
RUN pip install --upgrade pip | ||
RUN pip install -r requirements.txt --no-cache-dir | ||
RUN sh proto2py.sh | ||
COPY tls/client_certs /var/hello_grpc/client_certs | ||
CMD ["sh","client_start.sh"] |
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,3 @@ | ||
#!/bin/bash | ||
docker push feuyeux/grpc_server_python:1.0.0 | ||
docker push feuyeux/grpc_client_python:1.0.0 |
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 @@ | ||
#!/bin/bash | ||
cd "$( | ||
cd "$(dirname "$0")" >/dev/null 2>&1 | ||
pwd -P | ||
)/" || exit | ||
export CLIENT_NAME=grpc_client_python | ||
export CLIENT_IMG=feuyeux/$CLIENT_NAME:1.0.0 | ||
# if there's first argument, it's secure, otherwise insecure | ||
if [ "$1" = "secure" ]; then | ||
sh run_tls_client.sh | ||
else | ||
sh run_insecure_client.sh | ||
fi |
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 @@ | ||
#!/bin/bash | ||
cd "$( | ||
cd "$(dirname "$0")" >/dev/null 2>&1 | ||
pwd -P | ||
)/" || exit | ||
export SERVER_NAME=grpc_server_python | ||
export SERVER_IMG=feuyeux/$SERVER_NAME:1.0.0 | ||
# if there's first argument, it's secure, otherwise insecure | ||
if [ "$1" = "secure" ]; then | ||
sh run_tls_server.sh | ||
else | ||
sh run_insecure_server.sh | ||
fi |
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 |
---|---|---|
@@ -1,77 +1,50 @@ | ||
## grpc python demo | ||
# grpc python demo | ||
|
||
### 1 Setup | ||
## 1 Setup | ||
|
||
```bash | ||
```sh | ||
# 1. Aliyun's mirror of the Python Package Index (PyPI) | ||
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple | ||
# 2. Tsinghua University's mirror of PyPI | ||
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple | ||
# 3. University of Science and Technology of China's mirror of PyPI | ||
pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple | ||
``` | ||
|
||
#### python2 | ||
|
||
```bash | ||
python -m pip install --upgrade pip | ||
pip install virtualenv | ||
|
||
which virtualenv | ||
/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv | ||
``` | ||
|
||
#### python3 | ||
|
||
```bash | ||
python3 -m pip install --upgrade pip | ||
export PATH="/Users/han/Library/Python/3.8/bin:$PATH" | ||
pip3 install virtualenv | ||
|
||
which virtualenv | ||
/Users/han/Library/Python/3.8/bin/virtualenv | ||
```sh | ||
sh init.sh | ||
``` | ||
|
||
```bash | ||
virtualenv venv | ||
/Users/han/Library/Python/3.8/bin/virtualenv venv | ||
|
||
source venv/bin/activate | ||
python -m pip install --upgrade pip | ||
|
||
```sh | ||
( | ||
#generate requirements.txt with dependencies | ||
pip install pipreqs | ||
pipreqs --encoding utf-8 . --force | ||
) | ||
|
||
# https://pypi.org/project/grpcio-tools/ | ||
# https://pypi.org/project/protobuf/ | ||
# https://pypi.org/project/futures/ | ||
# enum34-1.1.10 futures-3.3.0 grpcio-1.41.1 grpcio-tools-1.41.1 protobuf-3.18.0 six-1.16.0 | ||
#pip install grpcio-tools | ||
pip install -r requirements.txt | ||
|
||
(python -m pip install grpcio) | ||
``` | ||
|
||
### 2 Generate | ||
## 2 Generate | ||
|
||
```bash | ||
conda activate grpc_env | ||
sh proto2py.sh | ||
``` | ||
|
||
### 3 Run | ||
## 3 Run | ||
|
||
```bash | ||
conda activate grpc_env | ||
sh server_start.sh | ||
``` | ||
|
||
```bash | ||
source venv/bin/activate | ||
|
||
conda activate grpc_env | ||
sh client_start.sh | ||
``` | ||
|
||
#### UT | ||
### UT | ||
|
||
```sh | ||
python3 -m unittest tests/test_utils.py | ||
conda activate grpc_env | ||
python -m unittest tests/test_utils.py | ||
``` |
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
#!/bin/bash | ||
# shellcheck disable=SC2155 | ||
|
||
cd "$( | ||
cd "$(dirname "$0")" >/dev/null 2>&1 | ||
pwd -P | ||
)/" || exit | ||
|
||
export PYTHONPATH=$(pwd) | ||
export PYTHONPATH=$PYTHONPATH:$(pwd)/landing_pb2 | ||
alias python=python3 | ||
python -V | ||
|
||
export PYTHONPATH=$(pwd) | ||
export PYTHONPATH=$PYTHONPATH:$(pwd)/landing | ||
echo "PYTHONPATH=${PYTHONPATH}" | ||
echo "starting client..." | ||
python3 client/protoClient.py |
21 changes: 16 additions & 5 deletions
21
hello-grpc-python/landing/landing_pb2.py → hello-grpc-python/conn/landing_pb2.py
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,47 @@ | ||
from google.protobuf.internal import containers as _containers | ||
from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper | ||
from google.protobuf import descriptor as _descriptor | ||
from google.protobuf import message as _message | ||
from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Mapping, Optional as _Optional, Union as _Union | ||
|
||
DESCRIPTOR: _descriptor.FileDescriptor | ||
|
||
class ResultType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper): | ||
__slots__ = () | ||
OK: _ClassVar[ResultType] | ||
FAIL: _ClassVar[ResultType] | ||
OK: ResultType | ||
FAIL: ResultType | ||
|
||
class TalkRequest(_message.Message): | ||
__slots__ = ("data", "meta") | ||
DATA_FIELD_NUMBER: _ClassVar[int] | ||
META_FIELD_NUMBER: _ClassVar[int] | ||
data: str | ||
meta: str | ||
def __init__(self, data: _Optional[str] = ..., meta: _Optional[str] = ...) -> None: ... | ||
|
||
class TalkResponse(_message.Message): | ||
__slots__ = ("status", "results") | ||
STATUS_FIELD_NUMBER: _ClassVar[int] | ||
RESULTS_FIELD_NUMBER: _ClassVar[int] | ||
status: int | ||
results: _containers.RepeatedCompositeFieldContainer[TalkResult] | ||
def __init__(self, status: _Optional[int] = ..., results: _Optional[_Iterable[_Union[TalkResult, _Mapping]]] = ...) -> None: ... | ||
|
||
class TalkResult(_message.Message): | ||
__slots__ = ("id", "type", "kv") | ||
class KvEntry(_message.Message): | ||
__slots__ = ("key", "value") | ||
KEY_FIELD_NUMBER: _ClassVar[int] | ||
VALUE_FIELD_NUMBER: _ClassVar[int] | ||
key: str | ||
value: str | ||
def __init__(self, key: _Optional[str] = ..., value: _Optional[str] = ...) -> None: ... | ||
ID_FIELD_NUMBER: _ClassVar[int] | ||
TYPE_FIELD_NUMBER: _ClassVar[int] | ||
KV_FIELD_NUMBER: _ClassVar[int] | ||
id: int | ||
type: ResultType | ||
kv: _containers.ScalarMap[str, str] | ||
def __init__(self, id: _Optional[int] = ..., type: _Optional[_Union[ResultType, str]] = ..., kv: _Optional[_Mapping[str, str]] = ...) -> None: ... |
Oops, something went wrong.