Skip to content
This repository was archived by the owner on Oct 23, 2021. It is now read-only.

Commit a93c9e8

Browse files
gillesmagGilles Magalhaestimstokman
authored
Add support for Apple M1 as development platform. (#431)
* Update backend base container images and frontend dependencies to support development on Apple M1 * Update remaining dependencies (except Stripe API) * Upgrade backend * Remove useless comment in Dockerfile * Update test job to latest docker as well * Upgrade mailchimp (no longer suited for DI) * Specify build node version for Netlify Co-authored-by: Gilles Magalhaes <gilles.magalhaes@riskquest.com> Co-authored-by: Tim Stokman <timstokman@gmail.com>
1 parent 6b874ad commit a93c9e8

117 files changed

Lines changed: 6095 additions & 5310 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test_backend.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
test_backend:
1111
runs-on: ubuntu-latest
12-
container: mcr.microsoft.com/dotnet/core/sdk:3.1-buster
12+
container: mcr.microsoft.com/dotnet/sdk:5.0
1313

1414
env:
1515
Db: CollActionDb

CollAction.Tests/CollAction.Tests.csproj

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp3.1</TargetFramework>
3+
<TargetFramework>net5.0</TargetFramework>
44
<UserSecretsId>aspnet-CollAction-29a5d7b8-3530-4482-9ed6-572bd6c178fa</UserSecretsId>
5-
<LangVersion>8.0</LangVersion>
5+
<LangVersion>9.0</LangVersion>
66
<PreserveCompilationReferences>true</PreserveCompilationReferences>
77
<PreserveCompilationContext>true</PreserveCompilationContext>
8+
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
9+
<ApplicationIcon />
10+
<OutputType>Library</OutputType>
11+
<StartupObject />
812
</PropertyGroup>
913

1014
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.4" />
12-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.9">
15+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.8" />
16+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
1317
<PrivateAssets>all</PrivateAssets>
1418
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1519
</PackageReference>
16-
<PackageReference Include="Moq" Version="4.14.1" />
17-
<PackageReference Include="Verify.Xunit" Version="5.1.0" />
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
21+
<PackageReference Include="Moq" Version="4.16.1" />
22+
<PackageReference Include="Verify.Xunit" Version="11.20.3" />
1823
<PackageReference Include="xunit" Version="2.4.1" />
1924
<PackageReference Include="xunit.runner.console" Version="2.4.1">
2025
<PrivateAssets>all</PrivateAssets>
2126
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2227
</PackageReference>
23-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
28+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
2429
<PrivateAssets>all</PrivateAssets>
2530
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2631
</PackageReference>

CollAction.Tests/GlobalSuppressions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
// Crowdaction-level suppressions either have no target or are given
44
// a specific target and scoped to a namespace, type, member, etc.
55

6+
using System;
67
using System.Diagnostics.CodeAnalysis;
78

9+
[assembly:CLSCompliant(false)]
810
[assembly: SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "Test project")]
911
[assembly: SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "Test project")]
1012
[assembly: SuppressMessage("Usage", "CA1816:Dispose methods should call SuppressFinalize", Justification = "Test project")]
1113
[assembly: SuppressMessage("Design", "CA1063:Implement IDisposable Correctly", Justification = "Test project")]
1214
[assembly: SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Not needed in test project")]
15+
[assembly: SuppressMessage("Security", "CA5394: Do not use insecure randomness", Justification = "We're not using randomness for security")]

CollAction/CollAction.csproj

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp3.1</TargetFramework>
3+
<TargetFramework>net5.0</TargetFramework>
44
<UserSecretsId>aspnet-CollAction-29a5d7b8-3530-4482-9ed6-572bd6c178fa</UserSecretsId>
5-
<LangVersion>8.0</LangVersion>
5+
<LangVersion>9.0</LangVersion>
66
<Nullable>enable</Nullable>
77
<PreserveCompilationReferences>true</PreserveCompilationReferences>
88
<PreserveCompilationContext>true</PreserveCompilationContext>
9+
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
910
</PropertyGroup>
1011
<ItemGroup>
1112
<Content Remove="Views\Emails\CrowdactionAddedAdmin.cshtml" />
@@ -34,43 +35,43 @@
3435

3536
<ItemGroup>
3637
<PackageReference Include="AspNetCore.IServiceCollection.AddIUrlHelper" Version="1.1.0" />
37-
<PackageReference Include="AWSSDK.S3" Version="3.3.111.2" />
38-
<PackageReference Include="AWSSDK.SimpleEmail" Version="3.3.101.152" />
39-
<PackageReference Include="Faker.Net" Version="1.3.77" />
38+
<PackageReference Include="AWSSDK.S3" Version="3.7.1.16" />
39+
<PackageReference Include="AWSSDK.SimpleEmail" Version="3.7.0.44" />
40+
<PackageReference Include="Faker.Net" Version="1.5.138" />
4041
<PackageReference Include="GraphiQL" Version="2.0.0" />
4142
<PackageReference Include="GraphQL" Version="2.4.0" />
4243
<PackageReference Include="GraphQL.Authorization" Version="2.1.29" />
4344
<PackageReference Include="GraphQL.EntityFramework" Version="9.4.0" />
44-
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.11" />
45-
<PackageReference Include="Hangfire.PostgreSql" Version="1.6.4.2" />
46-
<PackageReference Include="HtmlAgilityPack" Version="1.11.23" />
47-
<PackageReference Include="HtmlSanitizer" Version="5.0.372" />
48-
<PackageReference Include="MailChimp.Net.V3" Version="4.2.1" />
49-
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.14.0" />
50-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="3.1.4" />
51-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="3.1.4" />
52-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="3.1.4" />
53-
<PackageReference Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="3.1.4" />
54-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.4" />
55-
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
56-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.9">
45+
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.24" />
46+
<PackageReference Include="Hangfire.PostgreSql" Version="1.8.5.4" />
47+
<PackageReference Include="HtmlAgilityPack" Version="1.11.34" />
48+
<PackageReference Include="HtmlSanitizer" Version="5.0.404" />
49+
<PackageReference Include="MailChimp.Net.V3" Version="5.2.0" />
50+
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.17.0" />
51+
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="5.0.8" />
52+
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="5.0.8" />
53+
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="5.0.8" />
54+
<PackageReference Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="5.0.8" />
55+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.8" />
56+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.8" />
57+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
5758
<PrivateAssets>all</PrivateAssets>
5859
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
5960
</PackageReference>
60-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" />
61-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4" PrivateAssets="all">
61+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.8" />
62+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.8" PrivateAssets="all">
6263
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
6364
</PackageReference>
64-
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="3.1.4" />
65-
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" PrivateAssets="All" />
66-
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.3" />
65+
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="5.0.8" />
66+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" PrivateAssets="All" />
67+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.7" />
6768
<PackageReference Include="RazorLight" Version="2.0.0-beta9" />
68-
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
69+
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
6970
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
7071
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="3.1.0" />
71-
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
72-
<PackageReference Include="Serilog.Sinks.Slack" Version="1.2.63" />
73-
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0007" />
72+
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
73+
<PackageReference Include="Serilog.Sinks.Slack" Version="2.0.3" />
74+
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3" />
7475
<PackageReference Include="Stripe.net" Version="26.0.0" />
7576
</ItemGroup>
7677
</Project>

CollAction/Controllers/GraphQlController.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.AspNetCore.Mvc.ModelBinding;
1111
using Microsoft.Extensions.Caching.Memory;
1212
using Microsoft.Extensions.Logging;
13+
using Newtonsoft.Json;
1314
using Newtonsoft.Json.Linq;
1415
using System;
1516
using System.Collections.Generic;
@@ -47,13 +48,14 @@ public CacheKey(string query, JObject? variables)
4748
public bool Equals([AllowNull] CacheKey? other)
4849
=> other != null &&
4950
Query == other.Query &&
50-
jtokenComparer.Equals(Variables, other.Variables);
51+
((Variables == null && other.Variables == null) ||
52+
(Variables != null && other.Variables != null && jtokenComparer.Equals(Variables, other.Variables)));
5153

5254
public override bool Equals(object? obj)
5355
=> Equals(obj as CacheKey);
5456

5557
public override int GetHashCode()
56-
=> HashCode.Combine(Query, jtokenComparer.GetHashCode(Variables));
58+
=> Variables == null ? -1 : HashCode.Combine(Query, jtokenComparer.GetHashCode(Variables));
5759
}
5860

5961
public GraphQlController(ISchema schema, IDocumentExecuter executer, IEnumerable<IValidationRule> validationRules, ApplicationDbContext context, ILogger<GraphQlController> logger, IServiceProvider serviceProvider, IMemoryCache cache)
@@ -70,7 +72,7 @@ public GraphQlController(ISchema schema, IDocumentExecuter executer, IEnumerable
7072
[HttpPost]
7173
public Task<ExecutionResult> Post([BindRequired, FromBody] GraphQlPostBody body, CancellationToken cancellation)
7274
{
73-
if (!User.Identity.IsAuthenticated && body.Query.StartsWith("query", StringComparison.OrdinalIgnoreCase))
75+
if (!(User.Identity?.IsAuthenticated ?? false) && body.Query.StartsWith("query", StringComparison.OrdinalIgnoreCase))
7476
{
7577
logger.LogInformation("Executing graphql query with caching");
7678
return cache.GetOrCreateAsync(
@@ -93,7 +95,7 @@ public Task<ExecutionResult> Post([BindRequired, FromBody] GraphQlPostBody body,
9395
public Task<ExecutionResult> Get([FromQuery] GraphQlGetQuery getQuery, CancellationToken cancellation)
9496
{
9597
JObject? jsonVariables = ParseVariables(getQuery.Variables);
96-
if (!User.Identity.IsAuthenticated && getQuery.Query.StartsWith("query", StringComparison.OrdinalIgnoreCase))
98+
if (!(User.Identity?.IsAuthenticated ?? false) && getQuery.Query.StartsWith("query", StringComparison.OrdinalIgnoreCase))
9799
{
98100
logger.LogInformation("Executing graphql query with caching");
99101
return cache.GetOrCreateAsync(
@@ -123,9 +125,9 @@ public Task<ExecutionResult> Get([FromQuery] GraphQlGetQuery getQuery, Cancellat
123125
{
124126
return JObject.Parse(variables);
125127
}
126-
catch (Exception exception)
128+
catch (JsonReaderException exception)
127129
{
128-
throw new Exception("Could not parse variables.", exception);
130+
throw new InvalidOperationException("Could not parse variables.", exception);
129131
}
130132
}
131133

CollAction/Controllers/HomeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public async Task<IActionResult> Sitemap(CancellationToken token)
2626
XDocument sitemap = await sitemapService.GetSitemap(token).ConfigureAwait(false);
2727
return new ContentResult()
2828
{
29-
Content = sitemap.Declaration.ToString() + sitemap.ToString(SaveOptions.DisableFormatting),
29+
Content = $"{sitemap.Declaration}{sitemap.ToString(SaveOptions.DisableFormatting)}",
3030
ContentType = "text/xml",
3131
StatusCode = 200
3232
};

CollAction/Data/ApplicationDbContext.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected override void OnModelCreating(ModelBuilder builder)
4545
.HasAlternateKey(t => t.Name);
4646
builder.Entity<Crowdaction>()
4747
.HasIndex(c => c.Name)
48-
.HasName("IX_Crowdactions_Name").IsUnique();
48+
.HasDatabaseName("IX_Crowdactions_Name").IsUnique();
4949
builder.Entity<Crowdaction>()
5050
.HasMany(c => c.Comments)
5151
.WithOne(c => c.Crowdaction!)
@@ -87,8 +87,7 @@ protected override void OnModelCreating(ModelBuilder builder)
8787

8888
// All stored dates are UTC
8989
ValueConverter<DateTime, DateTime> dateTimeConverter =
90-
new ValueConverter<DateTime, DateTime>(
91-
v => v, v => DateTime.SpecifyKind(v, DateTimeKind.Utc));
90+
new(v => v, v => DateTime.SpecifyKind(v, DateTimeKind.Utc));
9291

9392
foreach (IMutableEntityType entityType in builder.Model.GetEntityTypes())
9493
{

CollAction/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
1+
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
22
ARG BUILD_CONFIG=Release
33
ARG DOTNET_CLI_TELEMETRY_OPTOUT=1
44
WORKDIR /src
@@ -10,7 +10,7 @@ RUN dotnet build CollAction.csproj -c $BUILD_CONFIG -o /app/build
1010
RUN dotnet publish CollAction.csproj -c $BUILD_CONFIG -o /app/publish
1111
RUN if [ "$BUILD_CONFIG" = "Debug" ] ; then dotnet dev-certs https -ep /app/publish/collaction.pfx -p test ; else echo skipping ssl ; fi
1212

13-
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim
13+
FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine
1414
WORKDIR /app
1515
COPY --from=build /app/publish .
1616
ENTRYPOINT ["dotnet", "CollAction.dll"]

CollAction/GlobalSuppressions.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
// Project-level suppressions either have no target or are given
44
// a specific target and scoped to a namespace, type, member, etc.
55

6-
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Too many exceptions to this rule, also seems a little buggy")]
7-
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "We're not internationalized currently")]
8-
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "We're mostly not normalizing strings when we're doing ToLower")]
9-
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Property setters needed for EF core and for options objects")]
10-
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "We're not a library")]
6+
using System.Diagnostics.CodeAnalysis;
7+
8+
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Too many exceptions to this rule, also seems a little buggy")]
9+
[assembly: SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "We're not internationalized currently")]
10+
[assembly: SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "We're mostly not normalizing strings when we're doing ToLower")]
11+
[assembly: SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Property setters needed for EF core and for options objects")]
12+
[assembly: SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "We're not a library")]
13+
[assembly: SuppressMessage("Security", "CA5394: Do not use insecure randomness", Justification = "We're not using randomness for security")]

CollAction/Helpers/ValidationHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ namespace CollAction.Helpers
99
{
1010
public static class ValidationHelper
1111
{
12-
public static IEnumerable<ValidationResult> Validate<TItem>(TItem item, IServiceProvider serviceProvider)
12+
public static IEnumerable<ValidationResult> Validate<TItem>(TItem item, IServiceProvider serviceProvider) where TItem: class
1313
{
1414
var validationContext = new ValidationContext(item, serviceProvider: serviceProvider, items: null);
1515
var validationResults = new List<ValidationResult>();
1616
Validator.TryValidateObject(item, validationContext, validationResults, true);
1717
return validationResults;
1818
}
1919

20-
public static IEnumerable<IdentityError> ValidateAsIdentity<TItem>(TItem item, IServiceProvider serviceProvider)
20+
public static IEnumerable<IdentityError> ValidateAsIdentity<TItem>(TItem item, IServiceProvider serviceProvider) where TItem: class
2121
=> Validate(item, serviceProvider).Select(ValidationResultToIdentityError);
2222

2323
public static string GetValidationString(this ModelStateDictionary modelState)
2424
=> string.Join(", ", modelState.Values.SelectMany(state => state.Errors).Select(error => error.ErrorMessage));
2525

2626
private static IdentityError ValidationResultToIdentityError(ValidationResult result)
27-
=> new IdentityError()
27+
=> new()
2828
{
2929
Code = string.Join("_", result.MemberNames),
3030
Description = result.ErrorMessage

0 commit comments

Comments
 (0)