Skip to content

Commit db00159

Browse files
author
Ramón Tomás
committed
Added envoy + config grpc json transcoder
1 parent 7c0e2a1 commit db00159

10 files changed

Lines changed: 142 additions & 22 deletions

File tree

docker-compose.override.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ services:
7777
catalog.api:
7878
environment:
7979
- ASPNETCORE_ENVIRONMENT=Development
80-
- ASPNETCORE_URLS=http://0.0.0.0:80;https://0.0.0.0:443;
8180
- ConnectionString=${ESHOP_AZURE_CATALOG_DB:-Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word}
8281
- PicBaseUrl=${ESHOP_AZURE_STORAGE_CATALOG_URL:-http://localhost:5202/api/v1/c/catalog/items/[0]/pic/} #Local: You need to open your local dev-machine firewall at range 5100-5110.
8382
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
@@ -92,7 +91,7 @@ services:
9291
- OrchestratorType=${ORCHESTRATOR_TYPE}
9392
ports:
9493
- "5101:80"
95-
- "9101:443"
94+
- "9101:81"
9695

9796
ordering.api:
9897
environment:
@@ -415,4 +414,10 @@ services:
415414
- WebhooksUrl=http://webhooks.api
416415
- SelfUrl=http://webhooks.client/
417416
ports:
418-
- "5114:80"
417+
- "5114:80"
418+
419+
envoy:
420+
volumes:
421+
- ./src/ApiGateways/Envoy/config:/etc/envoy
422+
ports:
423+
- "51051:51051"

docker-compose.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,10 @@ services:
237237
context: .
238238
dockerfile: src/Web/WebhookClient/Dockerfile
239239
depends_on:
240-
- webhooks.api
240+
- webhooks.api
241+
242+
envoy:
243+
image: envoy:v1
244+
build:
245+
context: src/ApiGateways/Envoy
246+
dockerfile: Dockerfile

eShopOnContainers-ServicesAndWebApps.sln

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27130.2027
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29020.237
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{FEA0C318-FFED-4D39-8781-265718CA43DD}"
77
EndProject
@@ -148,7 +148,20 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebhookClient", "src\Web\We
148148
EndProject
149149
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Devspace.Support", "Devspace.Support", "{68F5041D-51F2-4630-94B6-B49789F5E51A}"
150150
EndProject
151-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Devspaces.Support", "src\BuildingBlocks\Devspaces.Support\Devspaces.Support.csproj", "{56C2EF0B-6BF2-41D9-BE07-6E6D08D06B35}"
151+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Devspaces.Support", "src\BuildingBlocks\Devspaces.Support\Devspaces.Support.csproj", "{56C2EF0B-6BF2-41D9-BE07-6E6D08D06B35}"
152+
EndProject
153+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Envoy", "Envoy", "{882A8F3A-C61F-4C44-86DD-A5A258714BF2}"
154+
ProjectSection(SolutionItems) = preProject
155+
src\ApiGateways\Envoy\Dockerfile = src\ApiGateways\Envoy\Dockerfile
156+
EndProjectSection
157+
EndProject
158+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config", "config", "{3ABEEE8C-35E0-4185-9825-C44326151F5B}"
159+
ProjectSection(SolutionItems) = preProject
160+
src\ApiGateways\Envoy\config\catalog.proto = src\ApiGateways\Envoy\config\catalog.proto
161+
src\ApiGateways\Envoy\config\catalog.proto-descriptor.pb = src\ApiGateways\Envoy\config\catalog.proto-descriptor.pb
162+
src\ApiGateways\Envoy\Dockerfile = src\ApiGateways\Envoy\Dockerfile
163+
src\ApiGateways\Envoy\config\envoy.yaml = src\ApiGateways\Envoy\config\envoy.yaml
164+
EndProjectSection
152165
EndProject
153166
Global
154167
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -1862,6 +1875,8 @@ Global
18621875
{766D7E92-6AF0-476C-ADD5-282BF4D8C576} = {E279BF0F-7F66-4F3A-A3AB-2CDA66C1CD04}
18631876
{68F5041D-51F2-4630-94B6-B49789F5E51A} = {DB0EFB20-B024-4E5E-A75C-52143C131D25}
18641877
{56C2EF0B-6BF2-41D9-BE07-6E6D08D06B35} = {68F5041D-51F2-4630-94B6-B49789F5E51A}
1878+
{882A8F3A-C61F-4C44-86DD-A5A258714BF2} = {77849D35-37D4-4802-81DC-9477B2775A40}
1879+
{3ABEEE8C-35E0-4185-9825-C44326151F5B} = {882A8F3A-C61F-4C44-86DD-A5A258714BF2}
18651880
EndGlobalSection
18661881
GlobalSection(ExtensibilityGlobals) = postSolution
18671882
SolutionGuid = {25728519-5F0F-4973-8A64-0A81EB4EA8D9}

src/ApiGateways/Envoy/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM envoyproxy/envoy
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
syntax = "proto3";
2+
3+
package CatalogApi;
4+
5+
import "google/api/annotations.proto";
6+
7+
message CatalogItemRequest {
8+
int32 id = 1;
9+
}
10+
11+
message CatalogItemResponse {
12+
int32 id = 1;
13+
string name = 2;
14+
string description=3;
15+
double price=4;
16+
string picture_file_name=5;
17+
string picture_uri=6;
18+
CatalogType catalog_type=8;
19+
CatalogBrand catalog_brand=10;
20+
int32 available_stock=11;
21+
int32 restock_threshold=12;
22+
int32 max_stock_threshold=13;
23+
bool on_reorder=14;
24+
}
25+
26+
message CatalogBrand {
27+
int32 id = 1;
28+
string name = 2;
29+
}
30+
31+
message CatalogType {
32+
int32 id = 1;
33+
string type = 2;
34+
}
35+
36+
service Catalog {
37+
rpc GetItemById (CatalogItemRequest) returns (CatalogItemResponse) {
38+
option (google.api.http) = {
39+
get: "/api/v1/catalog/items/{id}"
40+
};
41+
}
42+
}
9.13 KB
Binary file not shown.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
admin:
2+
access_log_path: /tmp/admin_access.log
3+
address:
4+
socket_address: { address: 0.0.0.0, port_value: 9901 }
5+
6+
static_resources:
7+
listeners:
8+
- name: listener1
9+
address:
10+
socket_address: { address: 0.0.0.0, port_value: 51051 }
11+
filter_chains:
12+
- filters:
13+
- name: envoy.http_connection_manager
14+
typed_config:
15+
"@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
16+
stat_prefix: grpc_json
17+
codec_type: AUTO
18+
route_config:
19+
name: local_route
20+
virtual_hosts:
21+
- name: local_service
22+
domains: ["*"]
23+
routes:
24+
- match: { prefix: "/" }
25+
route: { cluster: grpc, timeout: { seconds: 60 } }
26+
http_filters:
27+
- name: envoy.grpc_json_transcoder
28+
config:
29+
proto_descriptor: "/etc/envoy/catalog.proto-descriptor.pb"
30+
services: ["CatalogApi.Catalog"]
31+
print_options:
32+
add_whitespace: true
33+
always_print_primitive_fields: true
34+
always_print_enums_as_ints: false
35+
preserve_proto_field_names: false
36+
- name: envoy.router
37+
38+
clusters:
39+
- name: grpc
40+
connect_timeout: 1.25s
41+
type: logical_dns
42+
lb_policy: round_robin
43+
dns_lookup_family: V4_ONLY
44+
http2_protocol_options: {}
45+
load_assignment:
46+
cluster_name: grpc
47+
endpoints:
48+
- lb_endpoints:
49+
- endpoint:
50+
address:
51+
socket_address:
52+
# WARNING: "docker.for.mac.localhost" has been deprecated from Docker v18.03.0.
53+
# If you're running an older version of Docker, please use "docker.for.mac.localhost" instead.
54+
# Reference: https://docs.docker.com/docker-for-mac/release-notes/#docker-community-edition-18030-ce-mac59-2018-03-26
55+
address: catalog.api
56+
port_value: 81

src/ApiGateways/Web.Bff.Shopping/apigw/configuration.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"DownstreamScheme": "http",
66
"DownstreamHostAndPorts": [
77
{
8-
"Host": "catalog.api",
9-
"Port": 80
8+
"Host": "envoy",
9+
"Port": 51051
1010
}
1111
],
1212
"UpstreamPathTemplate": "/api/{version}/c/{everything}",

src/Services/Catalog/Catalog.API/Catalog.API.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
<None Remove="@(Protobuf)" />
3939
</ItemGroup>
4040

41-
4241
<ItemGroup>
4342
<PackageReference Include="Grpc.AspNetCore.Server" Version="0.1.21-pre1" />
4443
<PackageReference Include="Google.Protobuf" Version="3.8.0" />

src/Services/Catalog/Catalog.API/Program.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,15 @@ private static IHostBuilder CreateHostBuilder(IConfiguration configuration, stri
7575
.UseConfiguration(configuration)
7676
.ConfigureKestrel(options =>
7777
{
78-
var ports = GetDefinedPorts(configuration);
79-
foreach (var port in ports.Distinct())
78+
options.Listen(IPAddress.Any, 80, listenOptions =>
8079
{
81-
options.ListenAnyIP(port.portNumber, listenOptions =>
82-
{
83-
Console.WriteLine($"Binding to port {port.portNumber} (https is {port.https})");
84-
if (port.https)
85-
{
86-
listenOptions.UseHttps("eshop.pfx");
87-
listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
88-
}
89-
});
90-
}
80+
listenOptions.Protocols = HttpProtocols.Http1;
81+
});
82+
options.Listen(IPAddress.Any, 81, listenOptions =>
83+
{
84+
listenOptions.Protocols = HttpProtocols.Http2;
85+
});
86+
9187
})
9288
.UseStartup<Startup>()
9389
.UseApplicationInsights()

0 commit comments

Comments
 (0)