Skip to content

Commit

Permalink
neat csharp
Browse files Browse the repository at this point in the history
  • Loading branch information
feuyeux committed Sep 28, 2024
1 parent cb1d1f0 commit 2944ab4
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 57 deletions.
41 changes: 0 additions & 41 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,3 @@ sh tools/clean_world.sh
| 10 | [Swift](hello-grpc-swift) | feuyeux/grpc_server_swift:1.0.0 | feuyeux/grpc_client_swift:1.0.0 |
| 11 | [PHP](hello-grpc-php) | feuyeux/grpc_server_php:1.0.0 | feuyeux/grpc_client_php:1.0.0 |
| 12 | [TypeScript](hello-grpc-ts) | feuyeux/grpc_server_ts:1.0.0 | feuyeux/grpc_client_ts:1.0.0 |

### INSECURE

```sh
langs=(cpp rust java go csharp python nodejs dart kotlin swift php ts)
lang=$langs[2]
lang=php
SERVER_NAME=grpc_server_$lang
SERVER_IMG=feuyeux/$SERVER_NAME:1.0.0
CLIENT_NAME=grpc_client_$lang
CLIENT_IMG=feuyeux/$CLIENT_NAME:1.0.0
echo "SERVER_IMG=$SERVER_IMG,CLIENT_IMG=$CLIENT_IMG"
```

```sh
docker run --rm --name $SERVER_NAME -p 9996:9996 $SERVER_IMG
```

```sh
docker run --rm --name $CLIENT_NAME -e GRPC_SERVER=$(ipconfig getifaddr en0) $CLIENT_IMG

docker run --rm --name $CLIENT_NAME -e GRPC_SERVER=host.docker.internal $CLIENT_IMG
```

### TLS

```sh
docker run --rm --name $SERVER_NAME -p 9996:9996 -e GRPC_HELLO_SECURE=Y $SERVER_IMG
```

```sh
docker run --rm --name $CLIENT_NAME \
-e GRPC_SERVER=$(ipconfig getifaddr en0) \
-e GRPC_HELLO_SECURE=Y \
$CLIENT_IMG

docker run --rm --name $CLIENT_NAME \
-e GRPC_SERVER=host.docker.internal \
-e GRPC_HELLO_SECURE=Y \
$CLIENT_IMG
```
2 changes: 1 addition & 1 deletion docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ set -e

langs=(cpp rust java go csharp python nodejs dart kotlin swift php ts)
for lang in "${langs[@]}"; do
sh "build_$lang.sh"
sh "${lang}_build.sh"
done
15 changes: 7 additions & 8 deletions docker/build_csharp.sh → docker/csharp_build.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ cd "$(
)/" || exit

echo "~~~ build grpc csharp ~~~"
cd ..
cp -r hello-grpc-csharp docker/
cd docker

cp -r ../hello-grpc-csharp .

if [[ "${1}" == "c" ]]; then
echo "build client"
docker build -f grpc-csharp.dockerfile --target client -t feuyeux/grpc_client_csharp:1.0.0 .
docker build -f csharp_grpc.dockerfile --target client -t feuyeux/grpc_client_csharp:1.0.0 .
elif [[ "${1}" == "s" ]]; then
echo "build server"
docker build -f grpc-csharp.dockerfile --target server -t feuyeux/grpc_server_csharp:1.0.0 .
docker build -f csharp_grpc.dockerfile --target server -t feuyeux/grpc_server_csharp:1.0.0 .
else
echo "build csharp"
docker build -f grpc-csharp.dockerfile --target build -t feuyeux/grpc_csharp:1.0.0 .
docker build -f grpc-csharp.dockerfile --target server -t feuyeux/grpc_server_csharp:1.0.0 .
docker build -f grpc-csharp.dockerfile --target client -t feuyeux/grpc_client_csharp:1.0.0 .
docker build -f csharp_grpc.dockerfile --target build -t feuyeux/grpc_csharp:1.0.0 .
docker build -f csharp_grpc.dockerfile --target server -t feuyeux/grpc_server_csharp:1.0.0 .
docker build -f csharp_grpc.dockerfile --target client -t feuyeux/grpc_client_csharp:1.0.0 .
fi

rm -rf hello-grpc-csharp
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions docker/csharp_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
docker push feuyeux/grpc_server_csharp:1.0.0
docker push feuyeux/grpc_client_csharp:1.0.0
13 changes: 13 additions & 0 deletions docker/csharp_run_client.sh
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_csharp
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
13 changes: 13 additions & 0 deletions docker/csharp_run_server.sh
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_csharp
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
6 changes: 6 additions & 0 deletions docker/run_insecure_client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# shellcheck disable=SC2046
echo "CLIENT_NAME=$CLIENT_NAME CLIENT_IMG=$CLIENT_IMG"

docker run --rm --name "$CLIENT_NAME" -e GRPC_SERVER=host.docker.internal "$CLIENT_IMG"
# docker run --rm --name "$CLIENT_NAME" -e GRPC_SERVER=$(ipconfig getifaddr en0) "$CLIENT_IMG"
3 changes: 3 additions & 0 deletions docker/run_insecure_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo "SERVER_NAME=$SERVER_NAME SERVER_IMG=$SERVER_IMG"
docker run --rm --name "$SERVER_NAME" -p 9996:9996 "$SERVER_IMG"
13 changes: 13 additions & 0 deletions docker/run_tls_client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
# shellcheck disable=SC2046
echo "CLIENT_NAME=$CLIENT_NAME CLIENT_IMG=$CLIENT_IMG"

docker run --rm --name "$CLIENT_NAME" \
-e GRPC_SERVER=host.docker.internal \
-e GRPC_HELLO_SECURE=Y \
"$CLIENT_IMG"

# docker run --rm --name "$CLIENT_NAME" \
# -e GRPC_SERVER=$(ipconfig getifaddr en0) \
# -e GRPC_HELLO_SECURE=Y \
# "$CLIENT_IMG"
3 changes: 3 additions & 0 deletions docker/run_tls_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo "SERVER_NAME=$SERVER_NAME SERVER_IMG=$SERVER_IMG"
docker run --rm --name "$SERVER_NAME" -p 9996:9996 -e GRPC_HELLO_SECURE=Y "$SERVER_IMG"
9 changes: 9 additions & 0 deletions docker/tools/fix_fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
cd "$(
cd "$(dirname "$0")" >/dev/null 2>&1
pwd -P
)/" || exit
chmod +x ./*.sh
dos2unix ./*.sh
chmod +x ../*.sh
dos2unix ../*.sh
7 changes: 3 additions & 4 deletions hello-grpc-csharp/HelloClient/HelloClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
<AssemblyName>HelloClient</AssemblyName>
<RootNamespace>HelloClient</RootNamespace>
<PackageId>HelloClient</PackageId>
<Authors>
feuyeux</Authors>
<Authors>feuyeux</Authors>
<Company />
<Product>HelloClient</Product>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions hello-grpc-csharp/HelloServer/HelloServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<Authors>feuyeux</Authors>
<Company />
<Product>HelloServer</Product>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion hello-grpc-csharp/HelloServer/ProtoServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal static class ProtoServer
private static void Main()
{
// https://logging.apache.org/log4net/release/manual/configuration.html
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly() ?? throw new InvalidOperationException());
XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
var port = Connection.GetGrcServerPort();
var tls = Environment.GetEnvironmentVariable("GRPC_HELLO_SECURE");
Expand Down

0 comments on commit 2944ab4

Please sign in to comment.