Skip to content

Commit

Permalink
Merge pull request #101 from bcgov/2.3.6
Browse files Browse the repository at this point in the history
Version 2.3.6
  • Loading branch information
BcGovNeal authored Aug 19, 2020
2 parents 9391c54 + d7021f0 commit 1c7c6db
Show file tree
Hide file tree
Showing 24 changed files with 232 additions and 67 deletions.
33 changes: 32 additions & 1 deletion .pipeline/lib/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
const options = require("@bcgov/pipeline-cli").Util.parseArguments();
const changeId = options.pr; //aka pull-request
const changeId = options.pr; // aka pull-request
const version = "2.3.6";
const name = "transaction";

Expand All @@ -14,6 +14,7 @@ const phases = {
instance: `${name}-build-${changeId}`,
version: `${version}-${changeId}`,
tag: `build-${version}-${changeId}`,
transient: true,
},
dev: {
namespace: "vlpweg-dev",
Expand All @@ -27,6 +28,16 @@ const phases = {
host: `transaction-${changeId}-vlpweg-dev.pathfinder.gov.bc.ca`,
dotnet_env: "Development",
transient: true,
resources: {
api: {
cpu: { request: "150m", limit: "200m" },
memory: { request: "250M", limit: "500M" },
},
client: {
cpu: { request: "50m", limit: "100m" },
memory: { request: "50M", limit: "100M" },
},
},
},
test: {
namespace: "vlpweg-test",
Expand All @@ -39,6 +50,16 @@ const phases = {
tag: `test-${version}`,
host: `transaction-vlpweg-test.pathfinder.gov.bc.ca`,
dotnet_env: "Test",
resources: {
api: {
cpu: { request: "150m", limit: "200m" },
memory: { request: "250M", limit: "500M" },
},
client: {
cpu: { request: "50m", limit: "100m" },
memory: { request: "50M", limit: "100M" },
},
},
},
prod: {
namespace: "vlpweg-prod",
Expand All @@ -51,6 +72,16 @@ const phases = {
tag: `prod-${version}`,
host: "transaction-vlpweg-prod.pathfinder.gov.bc.ca",
dotnet_env: "Production",
resources: {
api: {
cpu: { request: "150m", limit: "200m" },
memory: { request: "250M", limit: "500M" },
},
client: {
cpu: { request: "50m", limit: "100m" },
memory: { request: "50M", limit: "100M" },
},
},
},
};

Expand Down
10 changes: 9 additions & 1 deletion .pipeline/lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = (settings) => {
const kc = new KeyCloakClient(settings, oc);
kc.addUris();

// The deployment of your cool app goes here ▼▼▼
// The deployment of your cool app goes here ▼▼▼
objects.push(
...oc.processDeploymentTemplate(
`${templatesLocalBaseUrl}/client-deploy-config.yaml`,
Expand All @@ -32,6 +32,10 @@ module.exports = (settings) => {
VERSION: phases[phase].tag,
ENV: phases[phase].phase,
HOST: phases[phase].host,
CPU_REQUEST: phases[phase].resources.client.cpu.request,
CPU_LIMIT: phases[phase].resources.client.cpu.limit,
MEMORY_REQUEST: phases[phase].resources.client.memory.request,
MEMORY_LIMIT: phases[phase].resources.client.memory.limit,
},
}
)
Expand All @@ -47,6 +51,10 @@ module.exports = (settings) => {
VERSION: phases[phase].tag,
HOST: phases[phase].host,
ASPNETCORE_ENVIRONMENT: phases[phase].dotnet_env,
CPU_REQUEST: phases[phase].resources.api.cpu.request,
CPU_LIMIT: phases[phase].resources.api.cpu.limit,
MEMORY_REQUEST: phases[phase].resources.api.memory.request,
MEMORY_LIMIT: phases[phase].resources.api.memory.limit,
},
}
)
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pipeline {
agent { label 'deploy' }
steps {
echo "Deploying ..."
sh "cd .pipeline && ./npmw ci && ./npmw run deploy -- --pr=${CHANGE_ID} --env=dev"
sh "DEBUG=* && cd .pipeline && ./npmw ci && ./npmw run deploy -- --pr=${CHANGE_ID} --env=dev"
}
}
stage('Deploy (TEST)') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -32,7 +33,7 @@ public static AuthenticationBuilder AddKeycloakAuth(this AuthenticationBuilder b
{
OnAuthenticationFailed = context =>
{
IHostingEnvironment env = context.HttpContext.RequestServices.GetRequiredService<IHostingEnvironment>();
var env = context.HttpContext.RequestServices.GetRequiredService<IWebHostEnvironment>();
context.NoResult();
context.Response.StatusCode = 500;
Expand Down
4 changes: 3 additions & 1 deletion api/TransAction.API/Controllers/VersionController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System.Reflection;
using System.Runtime.Versioning;
Expand All @@ -19,6 +20,7 @@ public VersionController(IConfiguration config)
_config = config;
}

[AllowAnonymous]
[HttpGet]
public ActionResult<VersionInfo> GetVersionInfo()
{
Expand Down
4 changes: 0 additions & 4 deletions api/TransAction.API/Helpers/DateFormatConverter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace TransAction.API.Helpers
{
Expand Down
9 changes: 1 addition & 8 deletions api/TransAction.API/Helpers/UserHelper.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TransAction.Data.Services;

namespace TransAction.API.Helpers
{
public class UserHelper
{



public static string GetUserGuid(IHttpContextAccessor httpContextAccessor)
{
String userGuid = httpContextAccessor.HttpContext.User.FindFirst("idir_guid").Value;
string userGuid = httpContextAccessor.HttpContext.User.FindFirst("idir_guid").Value;

return userGuid;
}
Expand Down
1 change: 0 additions & 1 deletion api/TransAction.API/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/events",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
62 changes: 45 additions & 17 deletions api/TransAction.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using System.Linq;
using System.Net.Mime;
using TransAction.API.Authentication;
using TransAction.API.Extensions;
using TransAction.API.Helpers;
Expand All @@ -32,8 +38,6 @@ public Startup(IConfiguration configuration, ILogger<Startup> logger)

public IConfiguration Configuration { get; }

private const string CORS_ALLOW_ALL = "CORS_ALLOW_ALL";

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
Expand All @@ -57,25 +61,22 @@ public void ConfigureServices(IServiceCollection services)
})
.AddKeycloakAuth(new KeycloakAuthenticationOptions() { Authority = Configuration["JWT_AUTHORITY"], Audience = Configuration["JWT_AUDIENCE"] });

services.AddCors(options =>
{
options.AddPolicy(CORS_ALLOW_ALL,
builder =>
{
builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
});
});

services.AddMvc(options =>
services.AddControllers(options =>
{
options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddJsonOptions(a => a.SerializerSettings.Converters.Add(new TrimmingConverter()));
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.Converters.Add(new TrimmingConverter());
});

services.AddHealthChecks()
.AddSqlServer(ConnectionString, name: "DB-Check", failureStatus: HealthStatus.Degraded, tags: new string[] { "sql", "db" });
}

// 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 @@ -89,9 +90,36 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseSerilogRequestLogging();
app.ConfigureExceptionHandler(_logger);

app.UseCors(CORS_ALLOW_ALL);
var healthCheckOptions = new HealthCheckOptions
{
ResponseWriter = async (c, r) =>
{
c.Response.ContentType = MediaTypeNames.Application.Json;
var result = System.Text.Json.JsonSerializer.Serialize(
new
{
checks = r.Entries.Select(e =>
new
{
description = e.Key,
status = e.Value.Status.ToString(),
tags = e.Value.Tags,
responseTime = e.Value.Duration.TotalMilliseconds
}),
totalResponseTime = r.TotalDuration.TotalMilliseconds
});
await c.Response.WriteAsync(result);
}
};

app.UseHealthChecks("/healthz", healthCheckOptions);

app.UseRouting();
app.UseAuthentication();
app.UseMvc();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
24 changes: 14 additions & 10 deletions api/TransAction.API/TransAction.API.csproj
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<RepositoryUrl>https://github.com/bcgov/TransAction.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>2.3.6</Version>
<Description>The API server for the TransAction System</Description>
<Copyright>Copyright© 2019, Province of British Columbia.</Copyright>
<AssemblyVersion>2.3.6.0</AssemblyVersion>
<FileVersion>2.3.4.0</FileVersion>
<FileVersion>2.3.6.0</FileVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="8.1.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.1.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4">
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="3.1.1" />
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.0.0-dev-00059" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="3.1.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.Debug" Version="1.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0006" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion api/TransAction.API/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Default": "Warning",
"Override": {
"Microsoft": "Warning"
}
Expand Down
3 changes: 1 addition & 2 deletions api/TransAction.Data/Models/ImageDto.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace TransAction.Data.Models
{
Expand Down
6 changes: 6 additions & 0 deletions api/TransAction.Data/Repositories/UserActivityRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public IEnumerable<UserScoreDto> CurrentUserScore(int id)
.Where(p => p.UserId == id)
.Include(x => x.Activity)//.Where(x => x.Event.IsActive == true)
.Include(x => x.Event).Where(x => x.Event.IsActive == true)
.ToList()
.GroupBy(x => new { x.TeamId, x.EventId })
.Select(x => new UserScoreDto()
{
Expand Down Expand Up @@ -78,6 +79,7 @@ public IEnumerable<RegionScoreDto> RegionalScore(int eventId)
.ThenInclude(user => user.Team)
.Include(userActivity => userActivity.Activity)
.Where(userActivity => userActivity.EventId == eventId && userActivity.User.Team != null)
.ToList()
.GroupBy(userActivity => userActivity.User.Team.RegionId)
.Select(g => new RegionScoreDto
{
Expand Down Expand Up @@ -112,6 +114,7 @@ public int TeamEventSpecificScore(IEnumerable<TraUser> users, int teamId, int ev
var userList = users.Select(x => x.UserId).ToList();
var userAct = Find(p => p.EventId == eventId && userList.Contains(p.UserId))
.Include(x => x.Activity)
.ToList()
.GroupBy(x => new { x.TeamId, x.EventId })
.Select(x => new
{
Expand All @@ -128,6 +131,7 @@ public IEnumerable<TeamSpecificScoreDto> TeamSpecificScore(IEnumerable<TraUser>
var teamAct = Find(p => userList.Contains(p.UserId))
.Include(x => x.Activity)
.Include(x => x.Event).Where(x => x.Event.IsActive == true)
.ToList()
.GroupBy(x => new { x.TeamId, x.EventId })
.Select(x => new TeamSpecificScoreDto()
{
Expand All @@ -146,6 +150,7 @@ public IEnumerable<TeamSpecificScoreDto> TopTeams(int number, int eventId)
var teams = Find(p => p.EventId == eventId)
.Include(x => x.Activity)
.Include(x => x.Event)
.ToList()
.GroupBy(x => new { x.TeamId, x.EventId })
.Select(x => new TeamSpecificScoreDto()
{
Expand All @@ -163,6 +168,7 @@ public int UserSpecificScore(int userId, int eventId)
var userAct = Find(p => p.EventId == eventId && p.UserId == userId)
.Include(x => x.Activity)
.Include(x => x.Event)
.ToList()
.GroupBy(x => new { x.UserId, x.EventId })
.Select(x => new
{
Expand Down
Loading

0 comments on commit 1c7c6db

Please sign in to comment.