Skip to content

Commit

Permalink
Merge pull request #335 from Soluto/dotnetcore3
Browse files Browse the repository at this point in the history
upgrade everything to dotnet core 3
  • Loading branch information
shaikatz authored Oct 22, 2019
2 parents 28212a7 + 687d469 commit 2bf7c84
Show file tree
Hide file tree
Showing 23 changed files with 136 additions and 314 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
command: docker build . -t kamus-encryptor --build-arg PROJECT_NAME=encrypt-api
- run:
name: Build CRD controller docker image
command: docker build . -t crd-controller --build-arg PROJECT_NAME=crd-controller -f Dockerfile-aspnet3
command: docker build . -t crd-controller --build-arg PROJECT_NAME=crd-controller
- run:
name: Save docker image
command: |
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:

run_tests:
docker:
- image: microsoft/dotnet:2.2-sdk
- image: mcr.microsoft.com/dotnet/core/sdk:3.0

steps:
- checkout
Expand Down
70 changes: 35 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env

ARG PROJECT_NAME=decrypt-api

WORKDIR /app

# Copy csproj and restore as distinct layers
COPY ./src/$PROJECT_NAME/$PROJECT_NAME.csproj ./$PROJECT_NAME/$PROJECT_NAME.csproj
COPY ./src/key-managment/key-managment.csproj ./key-managment/key-managment.csproj
RUN dotnet restore $PROJECT_NAME/$PROJECT_NAME.csproj

# Copy everything else and build
COPY ./src/$PROJECT_NAME ./$PROJECT_NAME
COPY ./src/key-managment ./key-managment
RUN dotnet publish $PROJECT_NAME/$PROJECT_NAME.csproj -c Release -o ./obj/Docker/publish

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2.7-alpine AS release
ARG PROJECT_NAME=decrypt-api
ENV PROJECT_NAME_ENV=$PROJECT_NAME
RUN addgroup dotnet && \
adduser -D -G dotnet -h /home/dotnet dotnet && \
apk --no-cache add ca-certificates wget && \
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
wget -q https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.30-r0/glibc-2.30-r0.apk && \
apk add glibc-2.30-r0.apk && \
apk del wget


USER dotnet
WORKDIR /home/dotnet/app
ENV ASPNETCORE_URLS=http://+:9999
COPY --from=build-env /app/$PROJECT_NAME/obj/Docker/publish .

ENTRYPOINT dotnet $PROJECT_NAME_ENV.dll
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build-env

ARG PROJECT_NAME=decrypt-api

WORKDIR /app

# Copy csproj and restore as distinct layers
COPY ./src/$PROJECT_NAME/$PROJECT_NAME.csproj ./$PROJECT_NAME/$PROJECT_NAME.csproj
COPY ./src/key-managment/key-managment.csproj ./key-managment/key-managment.csproj
RUN dotnet restore $PROJECT_NAME/$PROJECT_NAME.csproj

# Copy everything else and build
COPY ./src/$PROJECT_NAME ./$PROJECT_NAME
COPY ./src/key-managment ./key-managment
RUN dotnet publish $PROJECT_NAME/$PROJECT_NAME.csproj -c Release -o ./obj/Docker/publish

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine AS release
ARG PROJECT_NAME=decrypt-api
ENV PROJECT_NAME_ENV=$PROJECT_NAME
RUN addgroup dotnet && \
adduser -D -G dotnet -h /home/dotnet dotnet && \
apk --no-cache add ca-certificates wget && \
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
wget -q https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.30-r0/glibc-2.30-r0.apk && \
apk add glibc-2.30-r0.apk && \
apk del wget

USER dotnet

WORKDIR /home/dotnet/app
ENV ASPNETCORE_URLS=http://+:9999
COPY --from=build-env /app/obj/Docker/publish .

ENTRYPOINT dotnet $PROJECT_NAME_ENV.dll
35 changes: 0 additions & 35 deletions Dockerfile-aspnet3

This file was deleted.

11 changes: 4 additions & 7 deletions src/crd-controller/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
using App.Metrics.AspNetCore;
using App.Metrics.Formatters.Prometheus;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
Expand All @@ -20,12 +19,10 @@ public static void Main(string[] args)

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseMetrics(options =>
{
options.EndpointOptions = endpointsOptions =>
{
endpointsOptions.MetricsEndpointOutputFormatter = new MetricsPrometheusTextOutputFormatter();
};
.UseMetricsEndpoints(options => {
options.MetricsEndpointOutputFormatter = new MetricsPrometheusTextOutputFormatter();
options.MetricsTextEndpointEnabled = false;
options.EnvironmentInfoEndpointEnabled = false;
})
.UseStartup<Startup>()
.UseSerilog()
Expand Down
1 change: 0 additions & 1 deletion src/crd-controller/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public void ConfigureServices (IServiceCollection services) {

services.AddSingleton(Configuration);
services.AddControllers().AddNewtonsoftJson();
services.AddMetrics();

services.AddKeyManagement(Configuration, Log.Logger);

Expand Down
5 changes: 3 additions & 2 deletions src/crd-controller/crd-controller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<PropertyGroup>
<Version>0.5.2.0</Version>
<Version>0.6.0.0</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -23,7 +23,8 @@
<PackageReference Include="KubernetesClient" Version="1.6.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="App.Metrics.AspNetCore.Mvc" Version="3.1.0" />
<PackageReference Include="App.Metrics.AspNetCore.Endpoints" Version="3.1.0" />
<PackageReference Include="App.Metrics.AspNetCore.Tracking" Version="3.1.0" />
<PackageReference Include="App.Metrics.Formatters.Prometheus" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
Expand Down
22 changes: 11 additions & 11 deletions src/decrypt-api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using App.Metrics.AspNetCore;
using App.Metrics.Formatters.Prometheus;
using App.Metrics.Formatters.Prometheus;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Serilog;
Expand All @@ -15,14 +14,15 @@ public static void Main(string[] args)

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseMetrics(options => {
options.EndpointOptions = endpointsOptions => {
endpointsOptions.MetricsEndpointOutputFormatter = new MetricsPrometheusTextOutputFormatter();
};
})

.UseStartup<Startup>()
.UseSerilog()
.Build();
.UseMetricsEndpoints(options => {
options.MetricsEndpointOutputFormatter = new MetricsPrometheusTextOutputFormatter();
options.MetricsTextEndpointEnabled = false;
options.EnvironmentInfoEndpointEnabled = false;
})
.UseStartup<Startup>()
.UseSerilog()
//see https://github.com/AppMetrics/AppMetrics/issues/396#issue-425344649
.UseKestrel(o => o.AllowSynchronousIO = true)
.Build();
}
}
45 changes: 27 additions & 18 deletions src/decrypt-api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
using Kamus.KeyManagement;
using Microsoft.AspNetCore.Http;
using System.Reflection;

using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;

namespace Kamus
{
public class Startup {

public Startup(IHostingEnvironment env)
public Startup(IWebHostEnvironment env)
{
string appsettingsPath = "appsettings.json";

Expand All @@ -41,18 +43,18 @@ public Startup(IHostingEnvironment env)
public IConfiguration Configuration;

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices (IServiceCollection services) {

services.AddMvc().AddMetrics();
public void ConfigureServices (IServiceCollection services) {

services.AddControllers().AddNewtonsoftJson();

services.AddSwaggerGen (swagger => {
swagger.SwaggerDoc ("v1", new Swashbuckle.AspNetCore.Swagger.Info { Title = "Kamus Swagger" });
services.AddSwaggerGen(swagger => {
swagger.SwaggerDoc("v1", new OpenApiInfo { Title = "Kamus Encryptor API", Version = "v1" });
});

services.AddSingleton<IKubernetes>(s => {
var config = string.IsNullOrEmpty(Configuration["Kubernetes:ProxyUrl"])
? KubernetesClientConfiguration.BuildDefaultConfig()
: new KubernetesClientConfiguration { Host = Configuration["Kubernetes:ProxyUrl"] };
services.AddSingleton<IKubernetes>(s => {
var config = string.IsNullOrEmpty(Configuration["Kubernetes:ProxyUrl"])
? KubernetesClientConfiguration.BuildDefaultConfig()
: new KubernetesClientConfiguration { Host = Configuration["Kubernetes:ProxyUrl"] };
return new Kubernetes(config);
});

Expand All @@ -72,7 +74,7 @@ public void ConfigureServices (IServiceCollection services) {
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure (IApplicationBuilder app, IHostingEnvironment env) {
public void Configure (IApplicationBuilder app, IWebHostEnvironment env) {

if (env.IsDevelopment())
{
Expand All @@ -85,17 +87,24 @@ public void Configure (IApplicationBuilder app, IHostingEnvironment env) {

Log.Logger = new LoggerConfiguration ()
.ReadFrom.Configuration (Configuration)
.CreateLogger ();

.CreateLogger ();

app.UseRouting();
app.UseSwagger();

app.UseSwagger ();
app.UseSwaggerUI (c => {
c.SwaggerEndpoint ("/swagger/v1/swagger.json", "Kamus Swagger");
app.UseSwaggerUI(c => {
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Kamus Decryptor API");
});

app.UseMetricsErrorTrackingMiddleware();

app.UseAuthentication();
app.UseAuthorization();

app.UseMvc ();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
12 changes: 7 additions & 5 deletions src/decrypt-api/decrypt-api.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<Version>0.5.2.0</Version>
<Version>0.6.0.0</Version>
</PropertyGroup>
<ItemGroup>
<Folder Include="Models\" />
Expand All @@ -14,15 +14,17 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Net.Security" Version="4.3.2" />
<PackageReference Include="App.Metrics.AspNetCore.Mvc" Version="3.1.0" />
<PackageReference Include="App.Metrics.AspNetCore.Endpoints" Version="3.1.0" />
<PackageReference Include="App.Metrics.AspNetCore.Tracking" Version="3.1.0" />
<PackageReference Include="App.Metrics.Formatters.Prometheus" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
<PackageReference Include="KubernetesClient" Version="1.6.1" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />
<PackageReference Include="jose-jwt" Version="2.4.0" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
Expand Down
Loading

0 comments on commit 2bf7c84

Please sign in to comment.