This commit is contained in:
Tom Delaney 2020-08-19 08:03:50 -04:00 коммит произвёл GitHub
Родитель e3f872e0b1
Коммит e5e86c30be
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
10 изменённых файлов: 179 добавлений и 11 удалений

Просмотреть файл

@ -0,0 +1,9 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as builder
WORKDIR /src
COPY . /src
RUN dotnet publish -f netcoreapp3.1
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 as runtime
WORKDIR /app
COPY --from=builder /src/bin/Debug/netcoreapp3.1/* /app/
ENTRYPOINT [ "dotnet","Fortune-Teller-Service.dll" ]

Просмотреть файл

@ -24,5 +24,6 @@
<PackageReference Include="Steeltoe.Discovery.Eureka" Version="$(SteeltoeVersion)" />
<PackageReference Include="Steeltoe.Extensions.Configuration.CloudFoundryCore" Version="$(SteeltoeVersion)" />
<PackageReference Include="Steeltoe.Extensions.Configuration.PlaceholderCore" Version="$(SteeltoeVersion)" />
<PackageReference Include="Steeltoe.Management.EndpointCore" Version="$(SteeltoeVersion)" />
</ItemGroup>
</Project>

Просмотреть файл

@ -4,6 +4,7 @@ using Steeltoe.Common.Hosting;
using Steeltoe.Discovery.Client;
using Steeltoe.Extensions.Configuration.CloudFoundry;
using Steeltoe.Extensions.Configuration.Placeholder;
using Steeltoe.Management.Endpoint;
namespace FortuneTellerService
{
@ -22,6 +23,7 @@ namespace FortuneTellerService
})
.AddCloudFoundryConfiguration()
.AddDiscoveryClient()
.AddHealthActuator()
.AddPlaceholderResolver()
.UseCloudHosting(5000)
.Build();

Просмотреть файл

@ -5,6 +5,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Steeltoe.Discovery.Client;
using Steeltoe.Management.Endpoint.Health;
namespace FortuneTellerService
{
@ -20,6 +21,7 @@ namespace FortuneTellerService
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddHealthActuator(Configuration);
services.AddEntityFrameworkInMemoryDatabase().AddDbContext<FortuneContext>(
options => options.UseInMemoryDatabase("Fortunes"), ServiceLifetime.Singleton);

Просмотреть файл

@ -0,0 +1,9 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as builder
WORKDIR /src
COPY . /src
RUN dotnet publish -f netcoreapp3.1
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 as runtime
WORKDIR /app
COPY --from=builder /src/bin/Debug/netcoreapp3.1/* /app/
ENTRYPOINT [ "dotnet","Fortune-Teller-UI.dll" ]

Просмотреть файл

@ -12,5 +12,7 @@
<PackageReference Include="Steeltoe.Discovery.ClientCore" Version="$(SteeltoeVersion)" />
<PackageReference Include="Steeltoe.Discovery.Consul" Version="$(SteeltoeVersion)" />
<PackageReference Include="Steeltoe.Discovery.Eureka" Version="$(SteeltoeVersion)" />
<PackageReference Include="Steeltoe.Discovery.Kubernetes" Version="$(SteeltoeVersion)" />
<PackageReference Include="Steeltoe.Management.EndpointCore" Version="$(SteeltoeVersion)" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,8 +1,9 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Steeltoe.Common.Hosting;
using Steeltoe.Discovery.Client;
using Steeltoe.Extensions.Configuration.CloudFoundry;
using Steeltoe.Management.Endpoint;
namespace Fortune_Teller_UI
{
@ -10,15 +11,19 @@ namespace Fortune_Teller_UI
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
BuildHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.AddCloudFoundryConfiguration()
.AddDiscoveryClient()
.UseStartup<Startup>()
.UseCloudHosting(5555)
.Build();
public static IHost BuildHost(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(host =>
{
host.UseStartup<Startup>();
})
.AddCloudFoundryConfiguration()
.AddHealthActuator()
.AddDiscoveryClient()
.UseCloudHosting(5555)
.Build();
}
}

Просмотреть файл

@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Steeltoe.Common.Http.Discovery;
using System;
using Steeltoe.Management.Endpoint.Health;
namespace Fortune_Teller_UI
{
@ -21,6 +22,7 @@ namespace Fortune_Teller_UI
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddHealthActuator(Configuration);
services.AddHttpClient("fortunes", c =>
{
c.BaseAddress = new Uri("http://fortuneService/api/fortunes/");
@ -45,7 +47,6 @@ namespace Fortune_Teller_UI
}
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
}

Просмотреть файл

@ -0,0 +1,14 @@
version: '3.4'
services:
fortune-teller-service:
image: ${DOCKER_REGISTRY}fortunetellerservicek8s
build:
context: Fortune-Teller-Service
dockerfile: Dockerfile
fortune-teller-ui:
image: ${DOCKER_REGISTRY}fortunetelleruik8s
build:
context: Fortune-Teller-UI
dockerfile: Dockerfile

Просмотреть файл

@ -0,0 +1,123 @@
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: default
name: namespace-reader
rules:
- apiGroups: ["", "extensions", "apps"]
resources: ["configmaps", "pods", "services", "endpoints", "secrets"]
verbs: ["get", "list", "watch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: namespace-reader-binding
namespace: default
subjects:
- kind: ServiceAccount
name: default
apiGroup: ""
roleRef:
kind: Role
name: namespace-reader
apiGroup: ""
---
apiVersion: v1
kind: Service
metadata:
labels:
app: fortuneservice
name: fortuneservice
namespace: default
spec:
ports:
- name: http
port: 80
selector:
app: fortune-teller-service
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: fortune-teller-service
name: fortune-teller-service
spec:
replicas: 1
selector:
matchLabels:
app: fortune-teller-service
template:
metadata:
labels:
app: fortune-teller-service
spec:
containers:
- image: tscrypter/fortunetellerservicek8s:latest # TODO: update image repository
name: fortune-teller-service
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: 80
initialDelaySeconds: 15
failureThreshold: 3
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: 80
initialDelaySeconds: 15
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
labels:
app: fortuneui
name: fortuneui
namespace: default
spec:
ports:
- name: http
port: 80
type: LoadBalancer
selector:
app: fortune-teller-ui
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: fortune-teller-ui
name: fortune-teller-ui
spec:
replicas: 1
selector:
matchLabels:
app: fortune-teller-ui
template:
metadata:
labels:
app: fortune-teller-ui
spec:
containers:
- image: tscrypter/fortunetelleruik8s:latest # TODO: update image repository
name: fortune-teller-ui
env:
- name: "spring__cloud__kubernetes__discovery__enabled"
value: "true"
- name: "spring__cloud__kubernetes__discovery__serviceName"
value: "fortune-teller-ui"
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: 80
initialDelaySeconds: 15
failureThreshold: 3
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: 80
initialDelaySeconds: 15
ports:
- containerPort: 80