-
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
17 changed files
with
882 additions
and
3 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 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,6 @@ | ||
**/*.sh | ||
**/*.bat | ||
**/bin/ | ||
**/obj/ | ||
**/out/ | ||
Dockerfile* |
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,41 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# https://mcr.microsoft.com/product/dotnet/sdk | ||
FROM mcr.microsoft.com/dotnet/sdk:8.0.101@sha256:7ef41132b2ebe6166bde36b7ba2f0d302e10307c3e0523a4539643a77233f56d as builder | ||
WORKDIR /app | ||
COPY cartservice.csproj . | ||
RUN dotnet restore cartservice.csproj \ | ||
-r linux-musl-x64 | ||
COPY . . | ||
RUN dotnet publish cartservice.csproj \ | ||
-p:PublishSingleFile=true \ | ||
-r linux-musl-x64 \ | ||
--self-contained true \ | ||
-p:PublishTrimmed=True \ | ||
-p:TrimMode=Full \ | ||
-c release \ | ||
-o /cartservice \ | ||
--no-restore | ||
|
||
# https://mcr.microsoft.com/product/dotnet/runtime-deps | ||
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0.1-alpine3.18-amd64@sha256:0b9be3c3937cd5ce83c6d05fc01698a904537be71b93dd485ea779592d5c8c10 | ||
|
||
WORKDIR /app | ||
COPY --from=builder /cartservice . | ||
EXPOSE 7070 | ||
ENV DOTNET_EnableDiagnostics=0 \ | ||
ASPNETCORE_HTTP_PORTS=7070 | ||
USER 1000 | ||
ENTRYPOINT ["/app/cartservice"] |
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,33 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM mcr.microsoft.com/dotnet/sdk:8.0@sha256:7ef41132b2ebe6166bde36b7ba2f0d302e10307c3e0523a4539643a77233f56d AS build | ||
WORKDIR /app | ||
COPY . . | ||
RUN dotnet restore cartservice.csproj | ||
RUN dotnet build "./cartservice.csproj" -c Debug -o /out | ||
|
||
FROM build AS publish | ||
RUN dotnet publish cartservice.csproj -c Debug -o /out | ||
|
||
# Building final image used in running container | ||
FROM mcr.microsoft.com/dotnet/aspnet:8.0@sha256:3ff67792728179308c4bf06799d8b45d155c60fddc347acf69465a496d9a20b8 AS final | ||
# Installing procps on the container to enable debugging of .NET Core | ||
RUN apt-get update \ | ||
&& apt-get install -y unzip procps wget | ||
WORKDIR /app | ||
COPY --from=publish /out . | ||
ENV ASPNETCORE_HTTP_PORTS=7070 | ||
|
||
ENTRYPOINT ["dotnet", "cartservice.dll"] |
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,26 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
using cartservice; | ||
|
||
CreateHostBuilder(args).Build().Run(); | ||
|
||
static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); |
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,84 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Diagnostics.HealthChecks; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Microsoft.Extensions.Hosting; | ||
using cartservice.cartstore; | ||
using cartservice.services; | ||
using Microsoft.Extensions.Caching.StackExchangeRedis; | ||
|
||
namespace cartservice | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container. | ||
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
string redisAddress = Configuration["REDIS_ADDR"]; | ||
string spannerProjectId = Configuration["SPANNER_PROJECT"]; | ||
string spannerConnectionString = Configuration["SPANNER_CONNECTION_STRING"]; | ||
string alloyDBConnectionString = Configuration["ALLOYDB_PRIMARY_IP"]; | ||
|
||
if (!string.IsNullOrEmpty(redisAddress)) | ||
{ | ||
services.AddStackExchangeRedisCache(options => | ||
{ | ||
options.Configuration = redisAddress; | ||
}); | ||
services.AddSingleton<ICartStore, RedisCartStore>(); | ||
} | ||
else if (!string.IsNullOrEmpty(spannerProjectId) || !string.IsNullOrEmpty(spannerConnectionString)) | ||
{ | ||
services.AddSingleton<ICartStore, SpannerCartStore>(); | ||
} | ||
else if (!string.IsNullOrEmpty(alloyDBConnectionString)) | ||
{ | ||
Console.WriteLine("Creating AlloyDB cart store"); | ||
services.AddSingleton<ICartStore, AlloyDBCartStore>(); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Redis cache host(hostname+port) was not specified. Starting a cart service using in memory store"); | ||
services.AddDistributedMemoryCache(); | ||
services.AddSingleton<ICartStore, RedisCartStore>(); | ||
} | ||
|
||
|
||
services.AddGrpc(); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseRouting(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapGrpcService<CartService>(); | ||
endpoints.MapGrpcService<cartservice.services.HealthCheckService>(); | ||
endpoints.MapGet("/", async context => | ||
{ | ||
await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909"); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
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,15 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"Kestrel": { | ||
"EndpointDefaults": { | ||
"Protocols": "Http2" | ||
} | ||
} | ||
} |
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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Grpc.AspNetCore" Version="2.60.0" /> | ||
<PackageReference Include="Grpc.HealthCheck" Version="2.60.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.0" /> | ||
<PackageReference Include="Google.Cloud.Spanner.Data" Version="4.6.0" /> | ||
<PackageReference Include="Npgsql" Version="8.0.1" /> | ||
<PackageReference Include="Google.Cloud.SecretManager.V1" Version="2.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Protobuf Include="protos\Cart.proto" GrpcServices="Both" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.