Commit 45423962 authored by Dmytro Bogatov's avatar Dmytro Bogatov 💕
Browse files

Resolve "Upgrade to ASP Core 2.0"

parent fb3be3de
......@@ -56,3 +56,7 @@ debug
# Debian build artifacts
debian/build
test/appsettings.*
*lock.json
......@@ -9,7 +9,7 @@ before_script:
## BUILD
build-docs:
image: dbogatov/docker-containers:mkdocs-latest
image: dbogatov/docker-images:mk-docs-latest
stage: build
script:
- ./build.sh -f build-docs
......@@ -35,7 +35,7 @@ build-ping:
- docker
build-app:
image: dbogatov/docker-containers:dotnet-core-latest
image: dbogatov/docker-images:net-core-latest
stage: build
script:
- export ASPNETCORE_ENVIRONMENT="Production"
......@@ -53,24 +53,25 @@ build-app:
unit-test-app:
stage: test
image: microsoft/dotnet:1.1.1-sdk
image: microsoft/dotnet:2.0.3-sdk
script:
- printf "{\"Version\":{\"GitHash\":\"%s\"}}" $CI_BUILD_REF > src/version.json
- cd test
- dotnet restore
- dotnet build
- ./test.sh | tee tests.out
- "cat tests.out | grep 'Failed: 0.'"
- "cat tests.out | grep 'Test Run Successful.'"
tags:
- docker
tidy-app:
stage: test
image: dbogatov/docker-containers:dotnet-core-latest
image: dbogatov/docker-images:net-core-latest
dependencies:
- build-app
before_script:
- export ASPNETCORE_ENVIRONMENT="Staging"
- cd src/web/bin/release/netcoreapp1.1/publish/
- cd src/web/bin/release/netcoreapp2.0/publish/
- dotnet web.dll > /dev/null &
- sleep 15
script:
......@@ -81,12 +82,12 @@ tidy-app:
blc-app:
stage: test
image: dbogatov/docker-containers:dotnet-core-latest
image: dbogatov/docker-images:net-core-latest
dependencies:
- build-app
before_script:
- export ASPNETCORE_ENVIRONMENT="Staging"
- cd src/web/bin/release/netcoreapp1.1/publish/
- cd src/web/bin/release/netcoreapp2.0/publish/
- dotnet web.dll > /dev/null &
- sleep 15
script:
......@@ -96,7 +97,7 @@ blc-app:
blc-docs:
stage: test
image: dbogatov/docker-containers:jekyll-latest
image: dbogatov/docker-images:blc-latest
dependencies:
- build-docs
before_script:
......@@ -130,7 +131,7 @@ release-app-docs:
release-debian:
stage: release
image: dbogatov/docker-containers:debian-latest
image: dbogatov/docker-images:debian-latest
script:
- ./build.sh -f build-debian-package
artifacts:
......
......@@ -14,7 +14,7 @@
"request": "launch",
"preLaunchTask": "build-web",
"justMyCode": false,
"program": "${workspaceRoot}/src/web/bin/Debug/netcoreapp1.1/web.dll",
"program": "${workspaceRoot}/src/web/bin/Debug/netcoreapp2.0/web.dll",
"args": [],
"cwd": "${workspaceRoot}/src/web",
"externalConsole": false,
......@@ -27,7 +27,7 @@
"request": "launch",
"preLaunchTask": "build-daemons",
"justMyCode": false,
"program": "${workspaceRoot}/src/daemons/bin/Debug/netcoreapp1.1/daemons.dll",
"program": "${workspaceRoot}/src/daemons/bin/Debug/netcoreapp2.0/daemons.dll",
"args": [],
"cwd": "${workspaceRoot}/src/daemons",
"externalConsole": false,
......@@ -40,7 +40,7 @@
"request": "launch",
"preLaunchTask": "build-test",
"justMyCode": false,
"program": "${workspaceRoot}/test/bin/Debug/netcoreapp1.1/test.dll",
"program": "${workspaceRoot}/test/bin/Debug/netcoreapp2.0/test.dll",
"args": [],
"cwd": "${workspaceRoot}/test",
"externalConsole": false,
......
......@@ -9,7 +9,9 @@ strict: true
copyright: Copyright © 2017 Dmytro Bogatov
# Documentation and theme
theme_dir: material
theme:
name: 'material'
custom_dir: 'material'
# Options
extra:
......
......@@ -15,11 +15,7 @@ install-node-tools () {
echo "Installing node modules... Requires Yarn or MPM"
if hash yarn 2>/dev/null; then
yarn --ignore-engines > /dev/null
else
npm install > /dev/null
fi
yarn --ignore-engines > /dev/null
}
clean-doc-folder () {
......
FROM dbogatov/docker-containers:nginx-latest
FROM dbogatov/docker-images:nginx-latest
MAINTAINER Dmytro Bogatov dmytro@dbogatov.org
......
FROM microsoft/dotnet:1.1.1-runtime
FROM microsoft/dotnet:2.0.3-runtime
# Create directory for the app source code
WORKDIR /srv
# Copy the binary
COPY bin/release/netcoreapp1.1/publish/ /srv
COPY bin/release/netcoreapp2.0/publish/ /srv
ENTRYPOINT /bin/bash -c "dotnet daemons.dll"
......@@ -54,6 +54,8 @@ namespace StatusMonitor.Daemons.Services
public async Task<DataPoint> GenerateDemoDataAsync(Metrics type, string source, DateTime? timestamp = null)
{
var metric = await _metricService.GetOrCreateMetricAsync(type, source);
_context.Attach(metric);
// Using plain new Random() will result in the same number if called multiple times in short time period
var random = new Random(
......
......@@ -287,6 +287,12 @@ namespace StatusMonitor.Daemons.Services
.GetRequiredService<IHealthService>()
.ProduceHealthReportAsync();
// May happen in test environment
if (report.Metric != null)
{
context.Attach(report.Metric);
}
await context.HealthReports.AddAsync(report);
await context.SaveChangesAsync();
}
......@@ -353,6 +359,18 @@ namespace StatusMonitor.Daemons.Services
// Wait completion of all tasks
var pingDataPoints = await Task.WhenAll(tasks.ToArray());
pingDataPoints
.ToList()
.ForEach(
ping => {
// May happen in test environment
if (ping.Metric != null)
{
context.Attach(ping.Metric);
}
}
);
await context.PingDataPoints.AddRangeAsync(pingDataPoints);
await context.SaveChangesAsync();
......
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../shared/shared.csproj">
<Name>shared</Name>
</ProjectReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
<PackageReference Include="Npgsql" Version="3.1.9" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
<ProjectReference Include="../shared/shared.csproj" Name="shared" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Npgsql" Version="3.2.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0-*" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="2.0.0-*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
<PackageReference Include="CommonMark.NET" Version="0.14.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Tools" Version="1.1.0-preview4-final" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.6.38-alpha" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="1.1.0" />
<PackageReference Include="MailKit" Version="1.16.0" />
<PackageReference Include="NetEscapades.Configuration.Yaml" Version="1.2.0" />
<PackageReference Include="System.ComponentModel.TypeConverter" Version="*" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="*" />
</ItemGroup>
<ItemGroup>
<AppSettings Include="../appsettings*.*"/>
......
......@@ -38,22 +38,14 @@ namespace StatusMonitor.Shared.Extensions
services
.AddEntityFrameworkSqlite()
.AddDbContext<DataContext>(
b => b.UseSqlite("Data Source=../../../../../development.db")
b => b.UseSqlite("Data Source=../development.db")
);
}
else // Testing and Staging
{
services
.AddEntityFrameworkInMemoryDatabase()
.AddDbContext<DataContext>(
b => b
.UseInMemoryDatabase()
.UseInternalServiceProvider(
new ServiceCollection()
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider()
)
);
.AddDbContext<DataContext>(b => b.UseInMemoryDatabase("main-db"));
}
services.AddTransient<IDataContext, DataContext>();
......
......@@ -37,6 +37,7 @@ namespace StatusMonitor.Shared.Models
void RemoveRange(params object[] entities);
EntityEntry Remove(object entity);
EntityEntry Entry(object entity);
EntityEntry Attach(object entity);
}
/// <summary>
......
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
<OutputType>Library</OutputType>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
<PackageReference Include="Npgsql" Version="3.1.9" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Npgsql" Version="3.2.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0-*" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="2.0.0-*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
<PackageReference Include="CommonMark.NET" Version="0.14.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Tools" Version="1.1.0-preview4-final" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.6.38-alpha" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="1.1.0" />
<PackageReference Include="MailKit" Version="1.16.0" />
<PackageReference Include="NetEscapades.Configuration.Yaml" Version="1.2.0" />
<PackageReference Include="System.ComponentModel.TypeConverter" Version="*" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="*" />
</ItemGroup>
</Project>
......@@ -18,7 +18,9 @@ namespace StatusMonitor.Web.Controllers.Api
{
// Retrieve requested metric
var metric = await _metricService.GetOrCreateMetricAsync(Metrics.Compilation, model.Source);
_context.Attach(metric);
// Retrieve requested user action
var compilationStage =
await _context
......
......@@ -15,7 +15,9 @@ namespace StatusMonitor.Web.Controllers.Api
{
// Retrieve requested metric
var metric = await _metricService.GetOrCreateMetricAsync(Metrics.CpuLoad, model.Source);
_context.Attach(metric);
// Record data
await _context
.NumericDataPoints
......
......@@ -18,6 +18,8 @@ namespace StatusMonitor.Web.Controllers.Api
// Retrieve requested metric
var metric = await _metricService.GetOrCreateMetricAsync(Metrics.Log, model.Source);
_context.Attach(metric);
// Retrieve requested user action
var logSeverity =
await _context
......
......@@ -18,6 +18,8 @@ namespace StatusMonitor.Web.Controllers.Api
// Retrieve requested metric
var metric = await _metricService.GetOrCreateMetricAsync(Metrics.UserAction, model.Source);
_context.Attach(metric);
// Record data
await _context
.UserActionDataPoints
......
FROM microsoft/dotnet:1.1.1-runtime
FROM microsoft/dotnet:2.0.3-runtime
# Create directory for the app source code
WORKDIR /srv
# Copy the binary
COPY bin/release/netcoreapp1.1/publish/ /srv
COPY bin/release/netcoreapp2.0/publish/ /srv
# Expose the port and start the app
EXPOSE 5555
......
using System;
using System.IO;
using System.Threading;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using StatusMonitor.Shared.Extensions;
namespace StatusMonitor.Web
......@@ -10,7 +13,7 @@ namespace StatusMonitor.Web
/// This class contains the entry point for the application.
/// </summary>
public class Program
{
{
/// <summary>
/// The entry point.
/// This function is responsible for starting up the server object.
......@@ -22,7 +25,7 @@ namespace StatusMonitor.Web
public static int Main(string[] args)
{
int port = 5555;
if (args.Length != 0 && (!Int32.TryParse(args[0], out port) || port < 1024 || port > 65534))
if (args.Length != 0 && (!Int32.TryParse(args[0], out port) || port < 1024 || port > 65534))
{
ColoredConsole.WriteLine("Usage: dotnet web.dll [port | number 1024-65534]", ConsoleColor.Red);
return 1;
......@@ -42,14 +45,18 @@ namespace StatusMonitor.Web
{
try
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
var host = WebHost
.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging(
logging => {
logging.ClearProviders();
logging.AddFilter("Microsoft", LogLevel.None);
}
)
.UseUrls($"http://*:{port}")
.Build(); // Connection to the database happens in .Build()
.Build();
host.Run();
return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment